X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/3981e5b5f52b39554131132e5e3a428d8508f546..5a0978ce61cc768c55d621d3f17e6f2c035caebc:/lisp/array.el diff --git a/lisp/array.el b/lisp/array.el index f65f14ac55..64c57bc480 100644 --- a/lisp/array.el +++ b/lisp/array.el @@ -1,17 +1,17 @@ ;;; array.el --- array editing commands for GNU Emacs -;; Copyright (C) 1987, 2000 Free Software Foundation, Inc. +;; Copyright (C) 1987, 2000-2012 Free Software Foundation, Inc. -;; Author David M. Brown +;; Author: David M. Brown ;; Maintainer: FSF ;; Keywords: extensions ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,9 +19,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -41,21 +39,19 @@ ;;; Code: -(eval-when-compile - (defvar array-max-column) - (defvar array-columns-per-line) - (defvar array-buffer-column) - (defvar array-line-length) - (defvar array-buffer-line) - (defvar array-lines-per-row) - (defvar array-max-row) - (defvar array-field-width) - (defvar array-row) - (defvar array-column) - (defvar array-rows-numbered) - (defvar array-copy-string) - (defvar array-init-field) - (defvar array-respect-tabs)) +(defvar array-max-column nil "Number of columns in the array.") +(defvar array-columns-per-line nil "Number of array columns per line.") +(defvar array-buffer-column nil "Current column number of point in the buffer.") +(defvar array-line-length nil "Length of a line in the array.") +(defvar array-buffer-line nil "Current line number of point in the buffer.") +(defvar array-lines-per-row nil "Number of lines per array row.") +(defvar array-max-row nil "Number of rows in the array.") +(defvar array-field-width nil "Width of a field in the array.") +(defvar array-row nil "Current array row location of point.") +(defvar array-column nil "Current array column location of point.") +(defvar array-rows-numbered nil "Are rows numbered in the buffer?") +(defvar array-copy-string nil "Current field string being copied.") +(defvar array-respect-tabs nil "Should TAB conversion be prevented?") ;;; Internal information functions. @@ -106,7 +102,7 @@ Set them to the optional arguments A-ROW and A-COLUMN if those are supplied." array-column (or a-column (array-current-column)))) (defun array-update-buffer-position () - "Set array-buffer-line and array-buffer-column to their current values." + "Set `array-buffer-line' and `array-buffer-column' to their current values." (setq array-buffer-line (current-line) array-buffer-column (current-column))) @@ -605,40 +601,41 @@ If optional ARG is given, copy through ARG rows up." (interactive) ;; If there is a conflict between array-field-width and init-string, resolve it. (let ((check t) - (len)) + (len) + init-field) (while check - (setq array-init-field (read-string "Initial field value: ")) - (setq len (length array-init-field)) + (setq init-field (read-string "Initial field value: ")) + (setq len (length init-field)) (if (/= len array-field-width) (if (y-or-n-p (format "Change field width to %d? " len)) (progn (setq array-field-width len) (setq check nil))) - (setq check nil)))) - (goto-char (point-min)) - (message "Working...") - (let ((this-row 1)) - ;; Loop through the rows. - (while (<= this-row array-max-row) - (if array-rows-numbered - (insert (format "%d:\n" this-row))) - (let ((this-column 1)) - ;; Loop through the columns. - (while (<= this-column array-max-column) - (insert array-init-field) - (if (and (zerop (% this-column array-columns-per-line)) - (/= this-column array-max-column)) - (newline)) - (setq this-column (1+ this-column)))) - (setq this-row (1+ this-row)) - (newline))) - (message "Working...done") + (setq check nil))) + (goto-char (point-min)) + (message "Working...") + (let ((this-row 1)) + ;; Loop through the rows. + (while (<= this-row array-max-row) + (if array-rows-numbered + (insert (format "%d:\n" this-row))) + (let ((this-column 1)) + ;; Loop through the columns. + (while (<= this-column array-max-column) + (insert init-field) + (if (and (zerop (% this-column array-columns-per-line)) + (/= this-column array-max-column)) + (newline)) + (setq this-column (1+ this-column)))) + (setq this-row (1+ this-row)) + (newline))) + (message "Working...done")) (array-goto-cell 1 1)) (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered) "Reconfigure the state of `array-rows-numbered' and `array-columns-per-line'. NEW-COLUMNS-PER-LINE is the desired value of `array-columns-per-line' and NEW-ROWS-NUMBERED (a character, either ?y or ?n) is the desired value -of array-rows-numbered." +of `array-rows-numbered'." (interactive "nColumns per line: \ncRows numbered? (y or n) ") ;; Check on new-columns-per-line (let ((check t)) @@ -717,7 +714,7 @@ of array-rows-numbered." (let ((inhibit-quit t)) (set-buffer main-buffer) (erase-buffer) - (insert-buffer temp-buffer) + (insert-buffer-substring temp-buffer) ;; Update local variables. (setq array-columns-per-line new-columns-per-line) (setq array-rows-numbered new-rows-numbered) @@ -750,9 +747,7 @@ of array-rows-numbered." (defun current-line () "Return the current buffer line at point. The first line is 0." - (save-excursion - (beginning-of-line) - (count-lines (point-min) (point)))) + (count-lines (point-min) (line-beginning-position))) (defun move-to-column-untabify (column) "Move to COLUMN on the current line, untabifying if necessary. @@ -767,7 +762,7 @@ Return COLUMN." (move-to-column column))))) (defun untabify-backward () - "Untabify the preceding tab." + "Untabify the preceding TAB." (save-excursion (let ((start (point))) (backward-char 1) @@ -777,32 +772,30 @@ Return COLUMN." ;;; Array mode. -(defvar array-mode-map nil +(defvar array-mode-map + (let ((map (make-keymap))) + (define-key map "\M-ad" 'array-display-local-variables) + (define-key map "\M-am" 'array-make-template) + (define-key map "\M-ae" 'array-expand-rows) + (define-key map "\M-ar" 'array-reconfigure-rows) + (define-key map "\M-a=" 'array-what-position) + (define-key map "\M-ag" 'array-goto-cell) + (define-key map "\M-af" 'array-fill-rectangle) + (define-key map "\C-n" 'array-next-row) + (define-key map "\C-p" 'array-previous-row) + (define-key map "\C-f" 'array-forward-column) + (define-key map "\C-b" 'array-backward-column) + (define-key map "\M-n" 'array-copy-down) + (define-key map "\M-p" 'array-copy-up) + (define-key map "\M-f" 'array-copy-forward) + (define-key map "\M-b" 'array-copy-backward) + (define-key map "\M-\C-n" 'array-copy-row-down) + (define-key map "\M-\C-p" 'array-copy-row-up) + (define-key map "\M-\C-f" 'array-copy-column-forward) + (define-key map "\M-\C-b" 'array-copy-column-backward) + map) "Keymap used in array mode.") -(if array-mode-map - () - (setq array-mode-map (make-keymap)) - ;; Bind keys. - (define-key array-mode-map "\M-ad" 'array-display-local-variables) - (define-key array-mode-map "\M-am" 'array-make-template) - (define-key array-mode-map "\M-ae" 'array-expand-rows) - (define-key array-mode-map "\M-ar" 'array-reconfigure-rows) - (define-key array-mode-map "\M-a=" 'array-what-position) - (define-key array-mode-map "\M-ag" 'array-goto-cell) - (define-key array-mode-map "\M-af" 'array-fill-rectangle) - (define-key array-mode-map "\C-n" 'array-next-row) - (define-key array-mode-map "\C-p" 'array-previous-row) - (define-key array-mode-map "\C-f" 'array-forward-column) - (define-key array-mode-map "\C-b" 'array-backward-column) - (define-key array-mode-map "\M-n" 'array-copy-down) - (define-key array-mode-map "\M-p" 'array-copy-up) - (define-key array-mode-map "\M-f" 'array-copy-forward) - (define-key array-mode-map "\M-b" 'array-copy-backward) - (define-key array-mode-map "\M-\C-n" 'array-copy-row-down) - (define-key array-mode-map "\M-\C-p" 'array-copy-row-up) - (define-key array-mode-map "\M-\C-f" 'array-copy-column-forward) - (define-key array-mode-map "\M-\C-b" 'array-copy-column-backward)) (put 'array-mode 'mode-class 'special) @@ -817,7 +810,7 @@ NOT recognized as integers or real numbers. The array MUST reside at the top of the buffer. TABs are not respected, and may be converted into spaces at any time. -Setting the variable 'array-respect-tabs to non-nil will prevent TAB conversion, +Setting the variable `array-respect-tabs' to non-nil will prevent TAB conversion, but will cause many functions to give errors if they encounter one. Upon entering array mode, you will be prompted for the values of @@ -872,97 +865,39 @@ take a numeric prefix argument): Entering array mode calls the function `array-mode-hook'." (interactive) - ;; Number of rows in the array. - (make-local-variable 'array-max-row) - ;; Number of columns in the array. - (make-local-variable 'array-max-column) - ;; Number of array columns per line. - (make-local-variable 'array-columns-per-line) - ;; Width of a field in the array. - (make-local-variable 'array-field-width) - ;; Are rows numbered in the buffer? - (make-local-variable 'array-rows-numbered) - ;; Length of a line in the array. - (make-local-variable 'array-line-length) - ;; Number of lines per array row. - (make-local-variable 'array-lines-per-row) - ;; Current line number of point in the buffer. + (kill-all-local-variables) (make-local-variable 'array-buffer-line) - ;; Current column number of point in the buffer. (make-local-variable 'array-buffer-column) - ;; Current array row location of point. (make-local-variable 'array-row) - ;; Current array column location of point. (make-local-variable 'array-column) - ;; Current field string being copied. (make-local-variable 'array-copy-string) - ;; Should TAB conversion be prevented? - (make-local-variable 'array-respect-tabs) - (setq array-respect-tabs nil) - (array-init-local-variables) + (set (make-local-variable 'array-respect-tabs) nil) + (set (make-local-variable 'array-max-row) + (read-number "Number of array rows: ")) + (set (make-local-variable 'array-max-column) + (read-number "Number of array columns: ")) + (set (make-local-variable 'array-columns-per-line) + (read-number "Array columns per line: ")) + (set (make-local-variable 'array-field-width) + (read-number "Field width: ")) + (set (make-local-variable 'array-rows-numbered) + (y-or-n-p "Rows numbered? ")) + (set (make-local-variable 'array-line-length) + (* array-field-width array-columns-per-line)) + (set (make-local-variable 'array-lines-per-row) + (+ (floor (1- array-max-column) array-columns-per-line) + (if array-rows-numbered 2 1))) + (message "") (setq major-mode 'array-mode) (setq mode-name "Array") (force-mode-line-update) - (make-local-variable 'truncate-lines) - (setq truncate-lines t) + (set (make-local-variable 'truncate-lines) t) (setq overwrite-mode 'overwrite-mode-textual) (use-local-map array-mode-map) - (run-hooks 'array-mode-hook)) + (run-mode-hooks 'array-mode-hook)) -;;; Initialization functions. These are not interactive. - -(defun array-init-local-variables () - "Initialize the variables associated with the array in this buffer." - (array-init-max-row) - (array-init-max-column) - (array-init-columns-per-line) - (array-init-field-width) - (array-init-rows-numbered) - (array-init-line-length) - (array-init-lines-per-row) - (message "")) - -(defun array-init-max-row (&optional arg) - "Initialize the value of `array-max-row'." - (setq array-max-row - (or arg (string-to-number (read-string "Number of array rows: "))))) - -(defun array-init-max-column (&optional arg) - "Initialize the value of `array-max-column'." - (setq array-max-column - (or arg (string-to-number (read-string "Number of array columns: "))))) - -(defun array-init-columns-per-line (&optional arg) - "Initialize the value of `array-columns-per-line'." - (setq array-columns-per-line - (or arg (string-to-number (read-string "Array columns per line: "))))) - -(defun array-init-field-width (&optional arg) - "Initialize the value of `array-field-width'." - (setq array-field-width - (or arg (string-to-number (read-string "Field width: "))))) - -(defun array-init-rows-numbered (&optional arg) - "Initialize the value of `array-rows-numbered'." - (setq array-rows-numbered - (or arg (y-or-n-p "Rows numbered? ")))) - -(defun array-init-line-length (&optional arg) - "Initialize the value of `array-line-length'." - (setq array-line-length - (or arg - (* array-field-width array-columns-per-line)))) - -(defun array-init-lines-per-row (&optional arg) - "Initialize the value of `array-lines-per-row'." - (setq array-lines-per-row - (or arg - (+ (floor (1- array-max-column) array-columns-per-line) - (if array-rows-numbered 2 1))))) - (provide 'array) -;;; arch-tag: 0086605d-79fe-4a1a-992a-456417261f80 ;;; array.el ends here