comparison lisp/array.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 37645a051842
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; array.el --- array editing commands for GNU Emacs 1 ;;; array.el --- array editing commands for GNU Emacs
2 2
3 ;; Copyright (C) 1987, 2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1987, 2000, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
4 5
5 ;; Author David M. Brown 6 ;; Author David M. Brown
6 ;; Maintainer: FSF 7 ;; Maintainer: FSF
7 ;; Keywords: extensions 8 ;; Keywords: extensions
8 9
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details. 20 ;; GNU General Public License for more details.
20 21
21 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02110-1301, USA.
25 26
26 ;;; Commentary: 27 ;;; Commentary:
27 28
28 ;; Commands for editing a buffer interpreted as a rectangular array 29 ;; Commands for editing a buffer interpreted as a rectangular array
29 ;; or matrix of whitespace-separated strings. You specify the array 30 ;; or matrix of whitespace-separated strings. You specify the array
605 (interactive) 606 (interactive)
606 ;; If there is a conflict between array-field-width and init-string, resolve it. 607 ;; If there is a conflict between array-field-width and init-string, resolve it.
607 (let ((check t) 608 (let ((check t)
608 (len)) 609 (len))
609 (while check 610 (while check
610 (setq array-init-field (read-input "Initial field value: ")) 611 (setq array-init-field (read-string "Initial field value: "))
611 (setq len (length array-init-field)) 612 (setq len (length array-init-field))
612 (if (/= len array-field-width) 613 (if (/= len array-field-width)
613 (if (y-or-n-p (format "Change field width to %d? " len)) 614 (if (y-or-n-p (format "Change field width to %d? " len))
614 (progn (setq array-field-width len) 615 (progn (setq array-field-width len)
615 (setq check nil))) 616 (setq check nil)))
636 637
637 (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered) 638 (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered)
638 "Reconfigure the state of `array-rows-numbered' and `array-columns-per-line'. 639 "Reconfigure the state of `array-rows-numbered' and `array-columns-per-line'.
639 NEW-COLUMNS-PER-LINE is the desired value of `array-columns-per-line' and 640 NEW-COLUMNS-PER-LINE is the desired value of `array-columns-per-line' and
640 NEW-ROWS-NUMBERED (a character, either ?y or ?n) is the desired value 641 NEW-ROWS-NUMBERED (a character, either ?y or ?n) is the desired value
641 of array-rows-numbered." 642 of `array-rows-numbered'."
642 (interactive "nColumns per line: \ncRows numbered? (y or n) ") 643 (interactive "nColumns per line: \ncRows numbered? (y or n) ")
643 ;; Check on new-columns-per-line 644 ;; Check on new-columns-per-line
644 (let ((check t)) 645 (let ((check t))
645 (while check 646 (while check
646 (if (and (>= new-columns-per-line 1) 647 (if (and (>= new-columns-per-line 1)
647 (<= new-columns-per-line array-max-column)) 648 (<= new-columns-per-line array-max-column))
648 (setq check nil) 649 (setq check nil)
649 (setq new-columns-per-line 650 (setq new-columns-per-line
650 (string-to-int 651 (string-to-number
651 (read-input 652 (read-string
652 (format "Columns per line (1 - %d): " array-max-column))))))) 653 (format "Columns per line (1 - %d): " array-max-column)))))))
653 ;; Check on new-rows-numbered. It has to be done this way 654 ;; Check on new-rows-numbered. It has to be done this way
654 ;; because interactive does not have y-or-n-p. 655 ;; because interactive does not have y-or-n-p.
655 (cond 656 (cond
656 ((eq new-rows-numbered ?y) 657 ((eq new-rows-numbered ?y)
715 (forward-line 1)))) 716 (forward-line 1))))
716 (setq this-row (1+ this-row))) 717 (setq this-row (1+ this-row)))
717 (let ((inhibit-quit t)) 718 (let ((inhibit-quit t))
718 (set-buffer main-buffer) 719 (set-buffer main-buffer)
719 (erase-buffer) 720 (erase-buffer)
720 (insert-buffer temp-buffer) 721 (insert-buffer-substring temp-buffer)
721 ;; Update local variables. 722 ;; Update local variables.
722 (setq array-columns-per-line new-columns-per-line) 723 (setq array-columns-per-line new-columns-per-line)
723 (setq array-rows-numbered new-rows-numbered) 724 (setq array-rows-numbered new-rows-numbered)
724 (setq array-line-length (* old-field-width new-columns-per-line)) 725 (setq array-line-length (* old-field-width new-columns-per-line))
725 (setq array-lines-per-row 726 (setq array-lines-per-row
765 (progn 766 (progn
766 (untabify-backward) 767 (untabify-backward)
767 (move-to-column column))))) 768 (move-to-column column)))))
768 769
769 (defun untabify-backward () 770 (defun untabify-backward ()
770 "Untabify the preceding tab." 771 "Untabify the preceding TAB."
771 (save-excursion 772 (save-excursion
772 (let ((start (point))) 773 (let ((start (point)))
773 (backward-char 1) 774 (backward-char 1)
774 (untabify (point) start)))) 775 (untabify (point) start))))
775 776
815 NOT recognized as integers or real numbers. 816 NOT recognized as integers or real numbers.
816 817
817 The array MUST reside at the top of the buffer. 818 The array MUST reside at the top of the buffer.
818 819
819 TABs are not respected, and may be converted into spaces at any time. 820 TABs are not respected, and may be converted into spaces at any time.
820 Setting the variable 'array-respect-tabs to non-nil will prevent TAB conversion, 821 Setting the variable `array-respect-tabs' to non-nil will prevent TAB conversion,
821 but will cause many functions to give errors if they encounter one. 822 but will cause many functions to give errors if they encounter one.
822 823
823 Upon entering array mode, you will be prompted for the values of 824 Upon entering array mode, you will be prompted for the values of
824 several variables. Others will be calculated based on the values you 825 several variables. Others will be calculated based on the values you
825 supply. These variables are all local to the buffer. Other buffer 826 supply. These variables are all local to the buffer. Other buffer
870 \\[array-display-local-variables] Display the current values of local variables. 871 \\[array-display-local-variables] Display the current values of local variables.
871 872
872 Entering array mode calls the function `array-mode-hook'." 873 Entering array mode calls the function `array-mode-hook'."
873 874
874 (interactive) 875 (interactive)
876 (kill-all-local-variables)
875 ;; Number of rows in the array. 877 ;; Number of rows in the array.
876 (make-local-variable 'array-max-row) 878 (make-local-variable 'array-max-row)
877 ;; Number of columns in the array. 879 ;; Number of columns in the array.
878 (make-local-variable 'array-max-column) 880 (make-local-variable 'array-max-column)
879 ;; Number of array columns per line. 881 ;; Number of array columns per line.
905 (force-mode-line-update) 907 (force-mode-line-update)
906 (make-local-variable 'truncate-lines) 908 (make-local-variable 'truncate-lines)
907 (setq truncate-lines t) 909 (setq truncate-lines t)
908 (setq overwrite-mode 'overwrite-mode-textual) 910 (setq overwrite-mode 'overwrite-mode-textual)
909 (use-local-map array-mode-map) 911 (use-local-map array-mode-map)
910 (run-hooks 'array-mode-hook)) 912 (run-mode-hooks 'array-mode-hook))
911 913
912 914
913 915
914 ;;; Initialization functions. These are not interactive. 916 ;;; Initialization functions. These are not interactive.
915 917
925 (message "")) 927 (message ""))
926 928
927 (defun array-init-max-row (&optional arg) 929 (defun array-init-max-row (&optional arg)
928 "Initialize the value of `array-max-row'." 930 "Initialize the value of `array-max-row'."
929 (setq array-max-row 931 (setq array-max-row
930 (or arg (string-to-int (read-input "Number of array rows: "))))) 932 (or arg (string-to-number (read-string "Number of array rows: ")))))
931 933
932 (defun array-init-max-column (&optional arg) 934 (defun array-init-max-column (&optional arg)
933 "Initialize the value of `array-max-column'." 935 "Initialize the value of `array-max-column'."
934 (setq array-max-column 936 (setq array-max-column
935 (or arg (string-to-int (read-input "Number of array columns: "))))) 937 (or arg (string-to-number (read-string "Number of array columns: ")))))
936 938
937 (defun array-init-columns-per-line (&optional arg) 939 (defun array-init-columns-per-line (&optional arg)
938 "Initialize the value of `array-columns-per-line'." 940 "Initialize the value of `array-columns-per-line'."
939 (setq array-columns-per-line 941 (setq array-columns-per-line
940 (or arg (string-to-int (read-input "Array columns per line: "))))) 942 (or arg (string-to-number (read-string "Array columns per line: ")))))
941 943
942 (defun array-init-field-width (&optional arg) 944 (defun array-init-field-width (&optional arg)
943 "Initialize the value of `array-field-width'." 945 "Initialize the value of `array-field-width'."
944 (setq array-field-width 946 (setq array-field-width
945 (or arg (string-to-int (read-input "Field width: "))))) 947 (or arg (string-to-number (read-string "Field width: ")))))
946 948
947 (defun array-init-rows-numbered (&optional arg) 949 (defun array-init-rows-numbered (&optional arg)
948 "Initialize the value of `array-rows-numbered'." 950 "Initialize the value of `array-rows-numbered'."
949 (setq array-rows-numbered 951 (setq array-rows-numbered
950 (or arg (y-or-n-p "Rows numbered? ")))) 952 (or arg (y-or-n-p "Rows numbered? "))))
962 (+ (floor (1- array-max-column) array-columns-per-line) 964 (+ (floor (1- array-max-column) array-columns-per-line)
963 (if array-rows-numbered 2 1))))) 965 (if array-rows-numbered 2 1)))))
964 966
965 (provide 'array) 967 (provide 'array)
966 968
969 ;;; arch-tag: 0086605d-79fe-4a1a-992a-456417261f80
967 ;;; array.el ends here 970 ;;; array.el ends here