diff options
| author | Dave Love | 2000-01-06 23:12:02 +0000 |
|---|---|---|
| committer | Dave Love | 2000-01-06 23:12:02 +0000 |
| commit | 41674a5aa2626979d2ddf1b40ef42ceabdef540b (patch) | |
| tree | 696f560dbd0bc2d02ada0ec950125f5ba92c3b99 | |
| parent | caff32a7cbc91aba9422df5158627eca005543df (diff) | |
| download | emacs-41674a5aa2626979d2ddf1b40ef42ceabdef540b.tar.gz emacs-41674a5aa2626979d2ddf1b40ef42ceabdef540b.zip | |
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
for symbols.
| -rw-r--r-- | lisp/array.el | 453 |
1 files changed, 234 insertions, 219 deletions
diff --git a/lisp/array.el b/lisp/array.el index 2592dc60b2b..b1182c7f16e 100644 --- a/lisp/array.el +++ b/lisp/array.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; array.el --- array editing commands for Gnu Emacs | 1 | ;;; array.el --- array editing commands for Gnu Emacs |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1987 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1987, 2000 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author David M. Brown | 5 | ;; Author David M. Brown |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -41,58 +41,74 @@ | |||
| 41 | 41 | ||
| 42 | ;;; Code: | 42 | ;;; Code: |
| 43 | 43 | ||
| 44 | (eval-when-compile | ||
| 45 | (defvar array-max-column) | ||
| 46 | (defvar array-columns-per-line) | ||
| 47 | (defvar array-buffer-column) | ||
| 48 | (defvar array-line-length) | ||
| 49 | (defvar array-buffer-line) | ||
| 50 | (defvar array-lines-per-row) | ||
| 51 | (defvar array-max-row) | ||
| 52 | (defvar array-field-width) | ||
| 53 | (defvar array-row) | ||
| 54 | (defvar array-column) | ||
| 55 | (defvar array-rows-numbered) | ||
| 56 | (defvar array-copy-string) | ||
| 57 | (defvar array-init-field) | ||
| 58 | (defvar array-respect-tabs)) | ||
| 59 | |||
| 44 | ;;; Internal information functions. | 60 | ;;; Internal information functions. |
| 45 | 61 | ||
| 46 | (defun array-cursor-in-array-range () | 62 | (defun array-cursor-in-array-range () |
| 47 | "Returns t if the cursor is in a valid array cell. | 63 | "Return t if the cursor is in a valid array cell. |
| 48 | Its ok to be on a row number line." | 64 | Its ok to be on a row number line." |
| 49 | (let ((columns-last-line (% max-column columns-per-line))) | 65 | (let ((columns-last-line (% array-max-column array-columns-per-line))) |
| 50 | ;; Requires buffer-line and buffer-column to be current. | 66 | ;; Requires array-buffer-line and array-buffer-column to be current. |
| 51 | (not (or | 67 | (not (or |
| 52 | ;; The cursor is too far to the right. | 68 | ;; The cursor is too far to the right. |
| 53 | (>= buffer-column line-length) | 69 | (>= array-buffer-column array-line-length) |
| 54 | ;; The cursor is below the last row. | 70 | ;; The cursor is below the last row. |
| 55 | (>= buffer-line (* lines-per-row max-row)) | 71 | (>= array-buffer-line (* array-lines-per-row array-max-row)) |
| 56 | ;; The cursor is on the last line of the row, the line is smaller | 72 | ;; The cursor is on the last line of the row, the line is smaller |
| 57 | ;; than the others, and the cursor is after the last array column | 73 | ;; than the others, and the cursor is after the last array column |
| 58 | ;; on the line. | 74 | ;; on the line. |
| 59 | (and (zerop (% (1+ buffer-line) lines-per-row)) | 75 | (and (zerop (% (1+ array-buffer-line) array-lines-per-row)) |
| 60 | (not (zerop columns-last-line)) | 76 | (not (zerop columns-last-line)) |
| 61 | (>= buffer-column (* columns-last-line field-width))))))) | 77 | (>= array-buffer-column (* columns-last-line array-field-width))))))) |
| 62 | 78 | ||
| 63 | (defun array-current-row () | 79 | (defun array-current-row () |
| 64 | "Return the array row of the field in which the cursor is located." | 80 | "Return the array row of the field in which the cursor is located." |
| 65 | ;; Requires buffer-line and buffer-column to be current. | 81 | ;; Requires array-buffer-line and array-buffer-column to be current. |
| 66 | (and (array-cursor-in-array-range) | 82 | (and (array-cursor-in-array-range) |
| 67 | (1+ (floor buffer-line lines-per-row)))) | 83 | (1+ (floor array-buffer-line array-lines-per-row)))) |
| 68 | 84 | ||
| 69 | (defun array-current-column () | 85 | (defun array-current-column () |
| 70 | "Return the array column of the field in which the cursor is located." | 86 | "Return the array column of the field in which the cursor is located." |
| 71 | ;; Requires buffer-line and buffer-column to be current. | 87 | ;; Requires array-buffer-line and array-buffer-column to be current. |
| 72 | (and (array-cursor-in-array-range) | 88 | (and (array-cursor-in-array-range) |
| 73 | ;; It's not okay to be on a row number line. | 89 | ;; It's not okay to be on a row number line. |
| 74 | (not (and rows-numbered | 90 | (not (and array-rows-numbered |
| 75 | (zerop (% buffer-line lines-per-row)))) | 91 | (zerop (% array-buffer-line array-lines-per-row)))) |
| 76 | (+ | 92 | (+ |
| 77 | ;; Array columns due to line differences. | 93 | ;; Array columns due to line differences. |
| 78 | (* columns-per-line | 94 | (* array-columns-per-line |
| 79 | (if rows-numbered | 95 | (if array-rows-numbered |
| 80 | (1- (% buffer-line lines-per-row)) | 96 | (1- (% array-buffer-line array-lines-per-row)) |
| 81 | (% buffer-line lines-per-row))) | 97 | (% array-buffer-line array-lines-per-row))) |
| 82 | ;; Array columns on the current line. | 98 | ;; Array columns on the current line. |
| 83 | (1+ (floor buffer-column field-width))))) | 99 | (1+ (floor array-buffer-column array-field-width))))) |
| 84 | 100 | ||
| 85 | (defun array-update-array-position (&optional a-row a-column) | 101 | (defun array-update-array-position (&optional a-row a-column) |
| 86 | "Set `array-row' and `array-column' to their current values or | 102 | "Set `array-row' and `array-column' to their current values. |
| 87 | to the optional arguments A-ROW and A-COLUMN." | 103 | Set them to the optional arguments A-ROW and A-COLUMN if those are supplied." |
| 88 | ;; Requires that buffer-line and buffer-column be current. | 104 | ;; Requires that array-buffer-line and array-buffer-column be current. |
| 89 | (setq array-row (or a-row (array-current-row)) | 105 | (setq array-row (or a-row (array-current-row)) |
| 90 | array-column (or a-column (array-current-column)))) | 106 | array-column (or a-column (array-current-column)))) |
| 91 | 107 | ||
| 92 | (defun array-update-buffer-position () | 108 | (defun array-update-buffer-position () |
| 93 | "Set buffer-line and buffer-column to their current values." | 109 | "Set array-buffer-line and array-buffer-column to their current values." |
| 94 | (setq buffer-line (current-line) | 110 | (setq array-buffer-line (current-line) |
| 95 | buffer-column (current-column))) | 111 | array-buffer-column (current-column))) |
| 96 | 112 | ||
| 97 | 113 | ||
| 98 | 114 | ||
| @@ -101,9 +117,9 @@ to the optional arguments A-ROW and A-COLUMN." | |||
| 101 | (defun array-what-position () | 117 | (defun array-what-position () |
| 102 | "Display the row and column in which the cursor is positioned." | 118 | "Display the row and column in which the cursor is positioned." |
| 103 | (interactive) | 119 | (interactive) |
| 104 | (let ((buffer-line (current-line)) | 120 | (let ((array-buffer-line (current-line)) |
| 105 | (buffer-column (current-column))) | 121 | (array-buffer-column (current-column))) |
| 106 | (message "Array row: %s Array column: %s" | 122 | (message "Array row: %s Array column: %s" |
| 107 | (prin1-to-string (array-current-row)) | 123 | (prin1-to-string (array-current-row)) |
| 108 | (prin1-to-string (array-current-column))))) | 124 | (prin1-to-string (array-current-column))))) |
| 109 | 125 | ||
| @@ -116,19 +132,19 @@ to the optional arguments A-ROW and A-COLUMN." | |||
| 116 | (terpri) | 132 | (terpri) |
| 117 | (princ (format " Buffer: %s\n\n" buf)) | 133 | (princ (format " Buffer: %s\n\n" buf)) |
| 118 | (princ (format " max-row: %s\n" | 134 | (princ (format " max-row: %s\n" |
| 119 | (prin1-to-string max-row))) | 135 | (prin1-to-string array-max-row))) |
| 120 | (princ (format " max-column: %s\n" | 136 | (princ (format " max-column: %s\n" |
| 121 | (prin1-to-string max-column))) | 137 | (prin1-to-string array-max-column))) |
| 122 | (princ (format " columns-per-line: %s\n" | 138 | (princ (format " columns-per-line: %s\n" |
| 123 | (prin1-to-string columns-per-line))) | 139 | (prin1-to-string array-columns-per-line))) |
| 124 | (princ (format " field-width: %s\n" | 140 | (princ (format " field-width: %s\n" |
| 125 | (prin1-to-string field-width))) | 141 | (prin1-to-string array-field-width))) |
| 126 | (princ (format " rows-numbered: %s\n" | 142 | (princ (format " rows-numbered: %s\n" |
| 127 | (prin1-to-string rows-numbered))) | 143 | (prin1-to-string array-rows-numbered))) |
| 128 | (princ (format " lines-per-row: %s\n" | 144 | (princ (format " lines-per-row: %s\n" |
| 129 | (prin1-to-string lines-per-row))) | 145 | (prin1-to-string array-lines-per-row))) |
| 130 | (princ (format " line-length: %s\n" | 146 | (princ (format " line-length: %s\n" |
| 131 | (prin1-to-string line-length)))))) | 147 | (prin1-to-string array-line-length)))))) |
| 132 | 148 | ||
| 133 | 149 | ||
| 134 | 150 | ||
| @@ -137,8 +153,8 @@ to the optional arguments A-ROW and A-COLUMN." | |||
| 137 | (defun array-beginning-of-field (&optional go-there) | 153 | (defun array-beginning-of-field (&optional go-there) |
| 138 | "Return the column of the beginning of the current field. | 154 | "Return the column of the beginning of the current field. |
| 139 | Optional argument GO-THERE, if non-nil, means go there too." | 155 | Optional argument GO-THERE, if non-nil, means go there too." |
| 140 | ;; Requires that buffer-column be current. | 156 | ;; Requires that array-buffer-column be current. |
| 141 | (let ((goal-column (- buffer-column (% buffer-column field-width)))) | 157 | (let ((goal-column (- array-buffer-column (% array-buffer-column array-field-width)))) |
| 142 | (if go-there | 158 | (if go-there |
| 143 | (move-to-column-untabify goal-column) | 159 | (move-to-column-untabify goal-column) |
| 144 | goal-column))) | 160 | goal-column))) |
| @@ -146,20 +162,20 @@ Optional argument GO-THERE, if non-nil, means go there too." | |||
| 146 | (defun array-end-of-field (&optional go-there) | 162 | (defun array-end-of-field (&optional go-there) |
| 147 | "Return the column of the end of the current array field. | 163 | "Return the column of the end of the current array field. |
| 148 | If optional argument GO-THERE is non-nil, go there too." | 164 | If optional argument GO-THERE is non-nil, go there too." |
| 149 | ;; Requires that buffer-column be current. | 165 | ;; Requires that array-buffer-column be current. |
| 150 | (let ((goal-column (+ (- buffer-column (% buffer-column field-width)) | 166 | (let ((goal-column (+ (- array-buffer-column (% array-buffer-column array-field-width)) |
| 151 | field-width))) | 167 | array-field-width))) |
| 152 | (if go-there | 168 | (if go-there |
| 153 | (move-to-column-untabify goal-column) | 169 | (move-to-column-untabify goal-column) |
| 154 | goal-column))) | 170 | goal-column))) |
| 155 | 171 | ||
| 156 | (defun array-move-to-cell (a-row a-column) | 172 | (defun array-move-to-cell (a-row a-column) |
| 157 | "Move to array row A-ROW and array column A-COLUMN. | 173 | "Move to array row A-ROW and array column A-COLUMN. |
| 158 | Leave point at the beginning of the field and return the new buffer column." | 174 | Leave point at the beginning of the field and return the new buffer column." |
| 159 | (let ((goal-line (+ (* lines-per-row (1- a-row)) | 175 | (let ((goal-line (+ (* array-lines-per-row (1- a-row)) |
| 160 | (if rows-numbered 1 0) | 176 | (if array-rows-numbered 1 0) |
| 161 | (floor (1- a-column) columns-per-line))) | 177 | (floor (1- a-column) array-columns-per-line))) |
| 162 | (goal-column (* field-width (% (1- a-column) columns-per-line)))) | 178 | (goal-column (* array-field-width (% (1- a-column) array-columns-per-line)))) |
| 163 | (goto-char (point-min)) | 179 | (goto-char (point-min)) |
| 164 | (forward-line goal-line) | 180 | (forward-line goal-line) |
| 165 | (move-to-column-untabify goal-column))) | 181 | (move-to-column-untabify goal-column))) |
| @@ -167,23 +183,23 @@ Leave point at the beginning of the field and return the new buffer column." | |||
| 167 | (defun array-move-to-row (a-row) | 183 | (defun array-move-to-row (a-row) |
| 168 | "Move to array row A-ROW preserving the current array column. | 184 | "Move to array row A-ROW preserving the current array column. |
| 169 | Leave point at the beginning of the field and return the new array row." | 185 | Leave point at the beginning of the field and return the new array row." |
| 170 | ;; Requires that buffer-line and buffer-column be current. | 186 | ;; Requires that array-buffer-line and array-buffer-column be current. |
| 171 | (let ((goal-line (+ (* lines-per-row (1- a-row)) | 187 | (let ((goal-line (+ (* array-lines-per-row (1- a-row)) |
| 172 | (% buffer-line lines-per-row))) | 188 | (% array-buffer-line array-lines-per-row))) |
| 173 | (goal-column (- buffer-column (% buffer-column field-width)))) | 189 | (goal-column (- array-buffer-column (% array-buffer-column array-field-width)))) |
| 174 | (forward-line (- goal-line buffer-line)) | 190 | (forward-line (- goal-line array-buffer-line)) |
| 175 | (move-to-column-untabify goal-column) | 191 | (move-to-column-untabify goal-column) |
| 176 | a-row)) | 192 | a-row)) |
| 177 | 193 | ||
| 178 | (defun array-move-to-column (a-column) | 194 | (defun array-move-to-column (a-column) |
| 179 | "Move to array column A-COLUMN preserving the current array row. | 195 | "Move to array column A-COLUMN preserving the current array row. |
| 180 | Leave point at the beginning of the field and return the new array column." | 196 | Leave point at the beginning of the field and return the new array column." |
| 181 | ;; Requires that buffer-line and buffer-column be current. | 197 | ;; Requires that array-buffer-line and array-buffer-column be current. |
| 182 | (let ((goal-line (+ (- buffer-line (% buffer-line lines-per-row)) | 198 | (let ((goal-line (+ (- array-buffer-line (% array-buffer-line array-lines-per-row)) |
| 183 | (if rows-numbered 1 0) | 199 | (if array-rows-numbered 1 0) |
| 184 | (floor (1- a-column) columns-per-line))) | 200 | (floor (1- a-column) array-columns-per-line))) |
| 185 | (goal-column (* field-width (% (1- a-column) columns-per-line)))) | 201 | (goal-column (* array-field-width (% (1- a-column) array-columns-per-line)))) |
| 186 | (forward-line (- goal-line buffer-line)) | 202 | (forward-line (- goal-line array-buffer-line)) |
| 187 | (move-to-column-untabify goal-column) | 203 | (move-to-column-untabify goal-column) |
| 188 | a-column)) | 204 | a-column)) |
| 189 | 205 | ||
| @@ -191,17 +207,17 @@ Leave point at the beginning of the field and return the new array column." | |||
| 191 | "Move one array row in direction SIGN (1 or -1). | 207 | "Move one array row in direction SIGN (1 or -1). |
| 192 | Leave point at the beginning of the field and return the new array row. | 208 | Leave point at the beginning of the field and return the new array row. |
| 193 | If requested to move beyond the array bounds, signal an error." | 209 | If requested to move beyond the array bounds, signal an error." |
| 194 | ;; Requires that buffer-line and buffer-column be current. | 210 | ;; Requires that array-buffer-line and array-buffer-column be current. |
| 195 | (let ((goal-column (array-beginning-of-field)) | 211 | (let ((goal-column (array-beginning-of-field)) |
| 196 | (array-row (or (array-current-row) | 212 | (array-row (or (array-current-row) |
| 197 | (error "Cursor is not in a valid array cell.")))) | 213 | (error "Cursor is not in a valid array cell")))) |
| 198 | (cond ((and (= array-row max-row) (= sign 1)) | 214 | (cond ((and (= array-row array-max-row) (= sign 1)) |
| 199 | (error "End of array.")) | 215 | (error "End of array")) |
| 200 | ((and (= array-row 1) (= sign -1)) | 216 | ((and (= array-row 1) (= sign -1)) |
| 201 | (error "Beginning of array.")) | 217 | (error "Beginning of array")) |
| 202 | (t | 218 | (t |
| 203 | (progn | 219 | (progn |
| 204 | (forward-line (* sign lines-per-row)) | 220 | (forward-line (* sign array-lines-per-row)) |
| 205 | (move-to-column-untabify goal-column) | 221 | (move-to-column-untabify goal-column) |
| 206 | (+ array-row sign)))))) | 222 | (+ array-row sign)))))) |
| 207 | 223 | ||
| @@ -209,34 +225,34 @@ If requested to move beyond the array bounds, signal an error." | |||
| 209 | "Move one array column in direction SIGN (1 or -1). | 225 | "Move one array column in direction SIGN (1 or -1). |
| 210 | Leave point at the beginning of the field and return the new array column. | 226 | Leave point at the beginning of the field and return the new array column. |
| 211 | If requested to move beyond the array bounds, signal an error." | 227 | If requested to move beyond the array bounds, signal an error." |
| 212 | ;; Requires that buffer-line and buffer-column be current. | 228 | ;; Requires that array-buffer-line and array-buffer-column be current. |
| 213 | (let ((array-column (or (array-current-column) | 229 | (let ((array-column (or (array-current-column) |
| 214 | (error "Cursor is not in a valid array cell.")))) | 230 | (error "Cursor is not in a valid array cell")))) |
| 215 | (cond ((and (= array-column max-column) (= sign 1)) | 231 | (cond ((and (= array-column array-max-column) (= sign 1)) |
| 216 | (error "End of array.")) | 232 | (error "End of array")) |
| 217 | ((and (= array-column 1) (= sign -1)) | 233 | ((and (= array-column 1) (= sign -1)) |
| 218 | (error "Beginning of array.")) | 234 | (error "Beginning of array")) |
| 219 | (t | 235 | (t |
| 220 | (cond | 236 | (cond |
| 221 | ;; Going backward from first column on the line. | 237 | ;; Going backward from first column on the line. |
| 222 | ((and (= sign -1) (= 1 (% array-column columns-per-line))) | 238 | ((and (= sign -1) (= 1 (% array-column array-columns-per-line))) |
| 223 | (forward-line -1) | 239 | (forward-line -1) |
| 224 | (move-to-column-untabify | 240 | (move-to-column-untabify |
| 225 | (* field-width (1- columns-per-line)))) | 241 | (* array-field-width (1- array-columns-per-line)))) |
| 226 | ;; Going forward from last column on the line. | 242 | ;; Going forward from last column on the line. |
| 227 | ((and (= sign 1) (zerop (% array-column columns-per-line))) | 243 | ((and (= sign 1) (zerop (% array-column array-columns-per-line))) |
| 228 | (forward-line 1)) | 244 | (forward-line 1)) |
| 229 | ;; Somewhere in the middle of the line. | 245 | ;; Somewhere in the middle of the line. |
| 230 | (t | 246 | (t |
| 231 | (move-to-column-untabify (+ (array-beginning-of-field) | 247 | (move-to-column-untabify (+ (array-beginning-of-field) |
| 232 | (* field-width sign))))) | 248 | (* array-field-width sign))))) |
| 233 | (+ array-column sign))))) | 249 | (+ array-column sign))))) |
| 234 | 250 | ||
| 235 | (defun array-normalize-cursor () | 251 | (defun array-normalize-cursor () |
| 236 | "Move the cursor to the first non-whitespace character in the field and, | 252 | "Move the cursor to the first non-whitespace character in the field. |
| 237 | if necessary, scroll horizontally to keep the cursor in view." | 253 | If necessary, scroll horizontally to keep the cursor in view." |
| 238 | ;; Assumes point is at the beginning of the field. | 254 | ;; Assumes point is at the beginning of the field. |
| 239 | (let ((buffer-column (current-column))) | 255 | (let ((array-buffer-column (current-column))) |
| 240 | (skip-chars-forward " \t" | 256 | (skip-chars-forward " \t" |
| 241 | (1- (save-excursion (array-end-of-field t) (point)))) | 257 | (1- (save-excursion (array-end-of-field t) (point)))) |
| 242 | (array-maybe-scroll-horizontally))) | 258 | (array-maybe-scroll-horizontally))) |
| @@ -244,21 +260,21 @@ if necessary, scroll horizontally to keep the cursor in view." | |||
| 244 | (defun array-maybe-scroll-horizontally () | 260 | (defun array-maybe-scroll-horizontally () |
| 245 | "If necessary, scroll horizontally to keep the cursor in view." | 261 | "If necessary, scroll horizontally to keep the cursor in view." |
| 246 | ;; This is only called from array-normalize-cursor so | 262 | ;; This is only called from array-normalize-cursor so |
| 247 | ;; buffer-column will always be current. | 263 | ;; array-buffer-column will always be current. |
| 248 | (let ((w-hscroll (window-hscroll)) | 264 | (let ((w-hscroll (window-hscroll)) |
| 249 | (w-width (window-width))) | 265 | (w-width (window-width))) |
| 250 | (cond | 266 | (cond |
| 251 | ((and (>= buffer-column w-hscroll) | 267 | ((and (>= array-buffer-column w-hscroll) |
| 252 | (<= buffer-column (+ w-hscroll w-width))) | 268 | (<= array-buffer-column (+ w-hscroll w-width))) |
| 253 | ;; It's already visible. Do nothing. | 269 | ;; It's already visible. Do nothing. |
| 254 | nil) | 270 | nil) |
| 255 | ((> buffer-column (+ w-hscroll w-width)) | 271 | ((> array-buffer-column (+ w-hscroll w-width)) |
| 256 | ;; It's to the right. Scroll left. | 272 | ;; It's to the right. Scroll left. |
| 257 | (scroll-left (- (- buffer-column w-hscroll) | 273 | (scroll-left (- (- array-buffer-column w-hscroll) |
| 258 | (/ w-width 2)))) | 274 | (/ w-width 2)))) |
| 259 | (t | 275 | (t |
| 260 | ;; It's to the left. Scroll right. | 276 | ;; It's to the left. Scroll right. |
| 261 | (scroll-right (+ (- w-hscroll buffer-column) | 277 | (scroll-right (+ (- w-hscroll array-buffer-column) |
| 262 | (/ w-width 2))))))) | 278 | (/ w-width 2))))))) |
| 263 | 279 | ||
| 264 | 280 | ||
| @@ -269,15 +285,15 @@ if necessary, scroll horizontally to keep the cursor in view." | |||
| 269 | "Move down one array row, staying in the current array column. | 285 | "Move down one array row, staying in the current array column. |
| 270 | If optional ARG is given, move down ARG array rows." | 286 | If optional ARG is given, move down ARG array rows." |
| 271 | (interactive "p") | 287 | (interactive "p") |
| 272 | (let ((buffer-line (current-line)) | 288 | (let ((array-buffer-line (current-line)) |
| 273 | (buffer-column (current-column))) | 289 | (array-buffer-column (current-column))) |
| 274 | (if (= (abs arg) 1) | 290 | (if (= (abs arg) 1) |
| 275 | (array-move-one-row arg) | 291 | (array-move-one-row arg) |
| 276 | (array-move-to-row | 292 | (array-move-to-row |
| 277 | (limit-index (+ (or (array-current-row) | 293 | (limit-index (+ (or (array-current-row) |
| 278 | (error "Cursor is not in an array cell.")) | 294 | (error "Cursor is not in an array cell")) |
| 279 | arg) | 295 | arg) |
| 280 | max-row)))) | 296 | array-max-row)))) |
| 281 | (array-normalize-cursor)) | 297 | (array-normalize-cursor)) |
| 282 | 298 | ||
| 283 | (defun array-previous-row (&optional arg) | 299 | (defun array-previous-row (&optional arg) |
| @@ -291,15 +307,15 @@ If optional ARG is given, move up ARG array rows." | |||
| 291 | If optional ARG is given, move forward ARG array columns. | 307 | If optional ARG is given, move forward ARG array columns. |
| 292 | If necessary, keep the cursor in the window by scrolling right or left." | 308 | If necessary, keep the cursor in the window by scrolling right or left." |
| 293 | (interactive "p") | 309 | (interactive "p") |
| 294 | (let ((buffer-line (current-line)) | 310 | (let ((array-buffer-line (current-line)) |
| 295 | (buffer-column (current-column))) | 311 | (array-buffer-column (current-column))) |
| 296 | (if (= (abs arg) 1) | 312 | (if (= (abs arg) 1) |
| 297 | (array-move-one-column arg) | 313 | (array-move-one-column arg) |
| 298 | (array-move-to-column | 314 | (array-move-to-column |
| 299 | (limit-index (+ (or (array-current-column) | 315 | (limit-index (+ (or (array-current-column) |
| 300 | (error "Cursor is not in an array cell.")) | 316 | (error "Cursor is not in an array cell")) |
| 301 | arg) | 317 | arg) |
| 302 | max-column)))) | 318 | array-max-column)))) |
| 303 | (array-normalize-cursor)) | 319 | (array-normalize-cursor)) |
| 304 | 320 | ||
| 305 | (defun array-backward-column (&optional arg) | 321 | (defun array-backward-column (&optional arg) |
| @@ -313,8 +329,8 @@ If necessary, keep the cursor in the window by scrolling right or left." | |||
| 313 | "Go to array row A-ROW and array column A-COLUMN." | 329 | "Go to array row A-ROW and array column A-COLUMN." |
| 314 | (interactive "nArray row: \nnArray column: ") | 330 | (interactive "nArray row: \nnArray column: ") |
| 315 | (array-move-to-cell | 331 | (array-move-to-cell |
| 316 | (limit-index a-row max-row) | 332 | (limit-index a-row array-max-row) |
| 317 | (limit-index a-column max-column)) | 333 | (limit-index a-column array-max-column)) |
| 318 | (array-normalize-cursor)) | 334 | (array-normalize-cursor)) |
| 319 | 335 | ||
| 320 | 336 | ||
| @@ -323,7 +339,7 @@ If necessary, keep the cursor in the window by scrolling right or left." | |||
| 323 | 339 | ||
| 324 | (defun array-field-string () | 340 | (defun array-field-string () |
| 325 | "Return the field string at the current cursor location." | 341 | "Return the field string at the current cursor location." |
| 326 | ;; Requires that buffer-column be current. | 342 | ;; Requires that array-buffer-column be current. |
| 327 | (buffer-substring | 343 | (buffer-substring |
| 328 | (save-excursion (array-beginning-of-field t) (point)) | 344 | (save-excursion (array-beginning-of-field t) (point)) |
| 329 | (save-excursion (array-end-of-field t) (point)))) | 345 | (save-excursion (array-end-of-field t) (point)))) |
| @@ -332,32 +348,32 @@ If necessary, keep the cursor in the window by scrolling right or left." | |||
| 332 | "Copy the current field into one array row in direction SIGN (1 or -1). | 348 | "Copy the current field into one array row in direction SIGN (1 or -1). |
| 333 | Leave point at the beginning of the field and return the new array row. | 349 | Leave point at the beginning of the field and return the new array row. |
| 334 | If requested to move beyond the array bounds, signal an error." | 350 | If requested to move beyond the array bounds, signal an error." |
| 335 | ;; Requires that buffer-line, buffer-column, and copy-string be current. | 351 | ;; Requires that array-buffer-line, array-buffer-column, and array-copy-string be current. |
| 336 | (let ((a-row (array-move-one-row sign))) | 352 | (let ((a-row (array-move-one-row sign))) |
| 337 | (let ((inhibit-quit t)) | 353 | (let ((inhibit-quit t)) |
| 338 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) | 354 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) |
| 339 | (insert copy-string)) | 355 | (insert array-copy-string)) |
| 340 | (move-to-column buffer-column) | 356 | (move-to-column array-buffer-column) |
| 341 | a-row)) | 357 | a-row)) |
| 342 | 358 | ||
| 343 | (defun array-copy-once-horizontally (sign) | 359 | (defun array-copy-once-horizontally (sign) |
| 344 | "Copy the current field into one array column in direction SIGN (1 or -1). | 360 | "Copy the current field into one array column in direction SIGN (1 or -1). |
| 345 | Leave point at the beginning of the field and return the new array column. | 361 | Leave point at the beginning of the field and return the new array column. |
| 346 | If requested to move beyond the array bounds, signal an error." | 362 | If requested to move beyond the array bounds, signal an error." |
| 347 | ;; Requires that buffer-line, buffer-column, and copy-string be current. | 363 | ;; Requires that array-buffer-line, array-buffer-column, and array-copy-string be current. |
| 348 | (let ((a-column (array-move-one-column sign))) | 364 | (let ((a-column (array-move-one-column sign))) |
| 349 | (array-update-buffer-position) | 365 | (array-update-buffer-position) |
| 350 | (let ((inhibit-quit t)) | 366 | (let ((inhibit-quit t)) |
| 351 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) | 367 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) |
| 352 | (insert copy-string)) | 368 | (insert array-copy-string)) |
| 353 | (move-to-column buffer-column) | 369 | (move-to-column array-buffer-column) |
| 354 | a-column)) | 370 | a-column)) |
| 355 | 371 | ||
| 356 | (defun array-copy-to-row (a-row) | 372 | (defun array-copy-to-row (a-row) |
| 357 | "Copy the current field vertically into every cell up to and including A-ROW. | 373 | "Copy the current field vertically into every cell up to and including A-ROW. |
| 358 | Leave point at the beginning of the field." | 374 | Leave point at the beginning of the field." |
| 359 | ;; Requires that buffer-line, buffer-column, array-row, and | 375 | ;; Requires that array-buffer-line, array-buffer-column, array-row, and |
| 360 | ;; copy-string be current. | 376 | ;; array-copy-string be current. |
| 361 | (let* ((num (- a-row array-row)) | 377 | (let* ((num (- a-row array-row)) |
| 362 | (count (abs num)) | 378 | (count (abs num)) |
| 363 | (sign (if (zerop count) () (/ num count)))) | 379 | (sign (if (zerop count) () (/ num count)))) |
| @@ -366,15 +382,15 @@ Leave point at the beginning of the field." | |||
| 366 | (array-update-buffer-position) | 382 | (array-update-buffer-position) |
| 367 | (let ((inhibit-quit t)) | 383 | (let ((inhibit-quit t)) |
| 368 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) | 384 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) |
| 369 | (insert copy-string)) | 385 | (insert array-copy-string)) |
| 370 | (move-to-column buffer-column) | 386 | (move-to-column array-buffer-column) |
| 371 | (setq count (1- count))))) | 387 | (setq count (1- count))))) |
| 372 | 388 | ||
| 373 | (defun array-copy-to-column (a-column) | 389 | (defun array-copy-to-column (a-column) |
| 374 | "Copy the current field horizontally into every cell up to and including | 390 | "Copy current field horizontally into every cell up to and including A-COLUMN. |
| 375 | A-COLUMN. Leave point at the beginning of the field." | 391 | Leave point at the beginning of the field." |
| 376 | ;; Requires that buffer-line, buffer-column, array-column, and | 392 | ;; Requires that array-buffer-line, array-buffer-column, array-column, and |
| 377 | ;; copy-string be current. | 393 | ;; array-copy-string be current. |
| 378 | (let* ((num (- a-column array-column)) | 394 | (let* ((num (- a-column array-column)) |
| 379 | (count (abs num)) | 395 | (count (abs num)) |
| 380 | (sign (if (zerop count) () (/ num count)))) | 396 | (sign (if (zerop count) () (/ num count)))) |
| @@ -383,19 +399,19 @@ A-COLUMN. Leave point at the beginning of the field." | |||
| 383 | (array-update-buffer-position) | 399 | (array-update-buffer-position) |
| 384 | (let ((inhibit-quit t)) | 400 | (let ((inhibit-quit t)) |
| 385 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) | 401 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) |
| 386 | (insert copy-string)) | 402 | (insert array-copy-string)) |
| 387 | (move-to-column buffer-column) | 403 | (move-to-column array-buffer-column) |
| 388 | (setq count (1- count))))) | 404 | (setq count (1- count))))) |
| 389 | 405 | ||
| 390 | (defun array-copy-to-cell (a-row a-column) | 406 | (defun array-copy-to-cell (a-row a-column) |
| 391 | "Copy the current field into the cell at A-ROW, A-COLUMN. | 407 | "Copy the current field into the cell at A-ROW, A-COLUMN. |
| 392 | Leave point at the beginning of the field." | 408 | Leave point at the beginning of the field." |
| 393 | ;; Requires that copy-string be current. | 409 | ;; Requires that array-copy-string be current. |
| 394 | (array-move-to-cell a-row a-column) | 410 | (array-move-to-cell a-row a-column) |
| 395 | (array-update-buffer-position) | 411 | (array-update-buffer-position) |
| 396 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) | 412 | (delete-region (point) (save-excursion (array-end-of-field t) (point))) |
| 397 | (insert copy-string) | 413 | (insert array-copy-string) |
| 398 | (move-to-column buffer-column)) | 414 | (move-to-column array-buffer-column)) |
| 399 | 415 | ||
| 400 | 416 | ||
| 401 | 417 | ||
| @@ -405,15 +421,15 @@ Leave point at the beginning of the field." | |||
| 405 | "Copy the current field one array row down. | 421 | "Copy the current field one array row down. |
| 406 | If optional ARG is given, copy down through ARG array rows." | 422 | If optional ARG is given, copy down through ARG array rows." |
| 407 | (interactive "p") | 423 | (interactive "p") |
| 408 | (let* ((buffer-line (current-line)) | 424 | (let* ((array-buffer-line (current-line)) |
| 409 | (buffer-column (current-column)) | 425 | (array-buffer-column (current-column)) |
| 410 | (array-row (or (array-current-row) | 426 | (array-row (or (array-current-row) |
| 411 | (error "Cursor is not in a valid array cell."))) | 427 | (error "Cursor is not in a valid array cell"))) |
| 412 | (copy-string (array-field-string))) | 428 | (array-copy-string (array-field-string))) |
| 413 | (if (= (abs arg) 1) | 429 | (if (= (abs arg) 1) |
| 414 | (array-copy-once-vertically arg) | 430 | (array-copy-once-vertically arg) |
| 415 | (array-copy-to-row | 431 | (array-copy-to-row |
| 416 | (limit-index (+ array-row arg) max-row)))) | 432 | (limit-index (+ array-row arg) array-max-row)))) |
| 417 | (array-normalize-cursor)) | 433 | (array-normalize-cursor)) |
| 418 | 434 | ||
| 419 | (defun array-copy-up (&optional arg) | 435 | (defun array-copy-up (&optional arg) |
| @@ -426,15 +442,15 @@ If optional ARG is given, copy up through ARG array rows." | |||
| 426 | "Copy the current field one array column to the right. | 442 | "Copy the current field one array column to the right. |
| 427 | If optional ARG is given, copy through ARG array columns to the right." | 443 | If optional ARG is given, copy through ARG array columns to the right." |
| 428 | (interactive "p") | 444 | (interactive "p") |
| 429 | (let* ((buffer-line (current-line)) | 445 | (let* ((array-buffer-line (current-line)) |
| 430 | (buffer-column (current-column)) | 446 | (array-buffer-column (current-column)) |
| 431 | (array-column (or (array-current-column) | 447 | (array-column (or (array-current-column) |
| 432 | (error "Cursor is not in a valid array cell."))) | 448 | (error "Cursor is not in a valid array cell"))) |
| 433 | (copy-string (array-field-string))) | 449 | (array-copy-string (array-field-string))) |
| 434 | (if (= (abs arg) 1) | 450 | (if (= (abs arg) 1) |
| 435 | (array-copy-once-horizontally arg) | 451 | (array-copy-once-horizontally arg) |
| 436 | (array-copy-to-column | 452 | (array-copy-to-column |
| 437 | (limit-index (+ array-column arg) max-column)))) | 453 | (limit-index (+ array-column arg) array-max-column)))) |
| 438 | (array-normalize-cursor)) | 454 | (array-normalize-cursor)) |
| 439 | 455 | ||
| 440 | (defun array-copy-backward (&optional arg) | 456 | (defun array-copy-backward (&optional arg) |
| @@ -450,18 +466,18 @@ If optional ARG is given, copy through ARG array columns to the right." | |||
| 450 | (array-update-buffer-position) | 466 | (array-update-buffer-position) |
| 451 | (array-update-array-position) | 467 | (array-update-array-position) |
| 452 | (if (not array-column) | 468 | (if (not array-column) |
| 453 | (error "Cursor is not in a valid array cell.")) | 469 | (error "Cursor is not in a valid array cell")) |
| 454 | (message "Working...") | 470 | (message "Working...") |
| 455 | (let ((this-row 0)) | 471 | (let ((this-row 0)) |
| 456 | (while (< this-row max-row) | 472 | (while (< this-row array-max-row) |
| 457 | (setq this-row (1+ this-row)) | 473 | (setq this-row (1+ this-row)) |
| 458 | (array-move-to-cell this-row array-column) | 474 | (array-move-to-cell this-row array-column) |
| 459 | (array-update-buffer-position) | 475 | (array-update-buffer-position) |
| 460 | (let ((copy-string (array-field-string))) | 476 | (let ((array-copy-string (array-field-string))) |
| 461 | (if (= (abs arg) 1) | 477 | (if (= (abs arg) 1) |
| 462 | (array-copy-once-horizontally arg) | 478 | (array-copy-once-horizontally arg) |
| 463 | (array-copy-to-column | 479 | (array-copy-to-column |
| 464 | (limit-index (+ array-column arg) max-column)))))) | 480 | (limit-index (+ array-column arg) array-max-column)))))) |
| 465 | (message "Working...done") | 481 | (message "Working...done") |
| 466 | (array-move-to-row array-row) | 482 | (array-move-to-row array-row) |
| 467 | (array-normalize-cursor)) | 483 | (array-normalize-cursor)) |
| @@ -479,22 +495,22 @@ If optional ARG is given, copy through ARG rows down." | |||
| 479 | (array-update-buffer-position) | 495 | (array-update-buffer-position) |
| 480 | (array-update-array-position) | 496 | (array-update-array-position) |
| 481 | (if (not array-row) | 497 | (if (not array-row) |
| 482 | (error "Cursor is not in a valid array cell.")) | 498 | (error "Cursor is not in a valid array cell")) |
| 483 | (cond | 499 | (cond |
| 484 | ((and (= array-row 1) (= arg -1)) | 500 | ((and (= array-row 1) (= arg -1)) |
| 485 | (error "Beginning of array.")) | 501 | (error "Beginning of array")) |
| 486 | ((and (= array-row max-row) (= arg 1)) | 502 | ((and (= array-row array-max-row) (= arg 1)) |
| 487 | (error "End of array.")) | 503 | (error "End of array")) |
| 488 | (t | 504 | (t |
| 489 | (let* ((copy-string | 505 | (let* ((array-copy-string |
| 490 | (buffer-substring | 506 | (buffer-substring |
| 491 | (save-excursion (array-move-to-cell array-row 1) | 507 | (save-excursion (array-move-to-cell array-row 1) |
| 492 | (point)) | 508 | (point)) |
| 493 | (save-excursion (array-move-to-cell array-row max-column) | 509 | (save-excursion (array-move-to-cell array-row array-max-column) |
| 494 | (forward-line 1) | 510 | (forward-line 1) |
| 495 | (point)))) | 511 | (point)))) |
| 496 | (this-row array-row) | 512 | (this-row array-row) |
| 497 | (goal-row (limit-index (+ this-row arg) max-row)) | 513 | (goal-row (limit-index (+ this-row arg) array-max-row)) |
| 498 | (num (- goal-row this-row)) | 514 | (num (- goal-row this-row)) |
| 499 | (count (abs num)) | 515 | (count (abs num)) |
| 500 | (sign (if (not (zerop count)) (/ num count)))) | 516 | (sign (if (not (zerop count)) (/ num count)))) |
| @@ -504,10 +520,10 @@ If optional ARG is given, copy through ARG rows down." | |||
| 504 | (let ((inhibit-quit t)) | 520 | (let ((inhibit-quit t)) |
| 505 | (delete-region (point) | 521 | (delete-region (point) |
| 506 | (save-excursion | 522 | (save-excursion |
| 507 | (array-move-to-cell this-row max-column) | 523 | (array-move-to-cell this-row array-max-column) |
| 508 | (forward-line 1) | 524 | (forward-line 1) |
| 509 | (point))) | 525 | (point))) |
| 510 | (insert copy-string)) | 526 | (insert array-copy-string)) |
| 511 | (setq count (1- count))) | 527 | (setq count (1- count))) |
| 512 | (array-move-to-cell goal-row (or array-column 1))))) | 528 | (array-move-to-cell goal-row (or array-column 1))))) |
| 513 | (array-normalize-cursor)) | 529 | (array-normalize-cursor)) |
| @@ -524,28 +540,28 @@ If optional ARG is given, copy through ARG rows up." | |||
| 524 | ;; Bind arguments. | 540 | ;; Bind arguments. |
| 525 | (array-update-buffer-position) | 541 | (array-update-buffer-position) |
| 526 | (let ((p-row (or (array-current-row) | 542 | (let ((p-row (or (array-current-row) |
| 527 | (error "Cursor is not in a valid array cell."))) | 543 | (error "Cursor is not in a valid array cell"))) |
| 528 | (p-column (or (array-current-column) | 544 | (p-column (or (array-current-column) |
| 529 | (error "Cursor is not in a valid array cell."))) | 545 | (error "Cursor is not in a valid array cell"))) |
| 530 | (m-row | 546 | (m-row |
| 531 | (save-excursion | 547 | (save-excursion |
| 532 | (exchange-point-and-mark) | 548 | (exchange-point-and-mark) |
| 533 | (array-update-buffer-position) | 549 | (array-update-buffer-position) |
| 534 | (or (array-current-row) | 550 | (or (array-current-row) |
| 535 | (error "Mark is not in a valid array cell.")))) | 551 | (error "Mark is not in a valid array cell")))) |
| 536 | (m-column | 552 | (m-column |
| 537 | (save-excursion | 553 | (save-excursion |
| 538 | (exchange-point-and-mark) | 554 | (exchange-point-and-mark) |
| 539 | (array-update-buffer-position) | 555 | (array-update-buffer-position) |
| 540 | (or (array-current-column) | 556 | (or (array-current-column) |
| 541 | (error "Mark is not in a valid array cell."))))) | 557 | (error "Mark is not in a valid array cell"))))) |
| 542 | (message "Working...") | 558 | (message "Working...") |
| 543 | (let ((top-row (min m-row p-row)) | 559 | (let ((top-row (min m-row p-row)) |
| 544 | (bottom-row (max m-row p-row)) | 560 | (bottom-row (max m-row p-row)) |
| 545 | (left-column (min m-column p-column)) | 561 | (left-column (min m-column p-column)) |
| 546 | (right-column (max m-column p-column))) | 562 | (right-column (max m-column p-column))) |
| 547 | ;; Do the first row. | 563 | ;; Do the first row. |
| 548 | (let ((copy-string | 564 | (let ((array-copy-string |
| 549 | (save-excursion | 565 | (save-excursion |
| 550 | (array-move-to-cell m-row m-column) | 566 | (array-move-to-cell m-row m-column) |
| 551 | (array-update-buffer-position) | 567 | (array-update-buffer-position) |
| @@ -556,12 +572,12 @@ If optional ARG is given, copy through ARG rows up." | |||
| 556 | (array-copy-to-column right-column)) | 572 | (array-copy-to-column right-column)) |
| 557 | ;; Do the rest of the rows. | 573 | ;; Do the rest of the rows. |
| 558 | (array-move-to-cell top-row left-column) | 574 | (array-move-to-cell top-row left-column) |
| 559 | (let ((copy-string | 575 | (let ((array-copy-string |
| 560 | (buffer-substring | 576 | (buffer-substring |
| 561 | (point) | 577 | (point) |
| 562 | (save-excursion | 578 | (save-excursion |
| 563 | (array-move-to-cell top-row right-column) | 579 | (array-move-to-cell top-row right-column) |
| 564 | (setq buffer-column (current-column)) | 580 | (setq array-buffer-column (current-column)) |
| 565 | (array-end-of-field t) | 581 | (array-end-of-field t) |
| 566 | (point)))) | 582 | (point)))) |
| 567 | (this-row top-row)) | 583 | (this-row top-row)) |
| @@ -573,10 +589,10 @@ If optional ARG is given, copy through ARG rows up." | |||
| 573 | (point) | 589 | (point) |
| 574 | (save-excursion | 590 | (save-excursion |
| 575 | (array-move-to-cell this-row right-column) | 591 | (array-move-to-cell this-row right-column) |
| 576 | (setq buffer-column (current-column)) | 592 | (setq array-buffer-column (current-column)) |
| 577 | (array-end-of-field t) | 593 | (array-end-of-field t) |
| 578 | (point))) | 594 | (point))) |
| 579 | (insert copy-string))))) | 595 | (insert array-copy-string))))) |
| 580 | (message "Working...done") | 596 | (message "Working...done") |
| 581 | (array-goto-cell p-row p-column))) | 597 | (array-goto-cell p-row p-column))) |
| 582 | 598 | ||
| @@ -587,30 +603,30 @@ If optional ARG is given, copy through ARG rows up." | |||
| 587 | (defun array-make-template () | 603 | (defun array-make-template () |
| 588 | "Create the template of an array." | 604 | "Create the template of an array." |
| 589 | (interactive) | 605 | (interactive) |
| 590 | ;; If there is a conflict between field-width and init-string, resolve it. | 606 | ;; If there is a conflict between array-field-width and init-string, resolve it. |
| 591 | (let ((check t) | 607 | (let ((check t) |
| 592 | (len)) | 608 | (len)) |
| 593 | (while check | 609 | (while check |
| 594 | (setq init-field (read-input "Initial field value: ")) | 610 | (setq array-init-field (read-input "Initial field value: ")) |
| 595 | (setq len (length init-field)) | 611 | (setq len (length array-init-field)) |
| 596 | (if (/= len field-width) | 612 | (if (/= len array-field-width) |
| 597 | (if (y-or-n-p (format "Change field width to %d? " len)) | 613 | (if (y-or-n-p (format "Change field width to %d? " len)) |
| 598 | (progn (setq field-width len) | 614 | (progn (setq array-field-width len) |
| 599 | (setq check nil))) | 615 | (setq check nil))) |
| 600 | (setq check nil)))) | 616 | (setq check nil)))) |
| 601 | (goto-char (point-min)) | 617 | (goto-char (point-min)) |
| 602 | (message "Working...") | 618 | (message "Working...") |
| 603 | (let ((this-row 1)) | 619 | (let ((this-row 1)) |
| 604 | ;; Loop through the rows. | 620 | ;; Loop through the rows. |
| 605 | (while (<= this-row max-row) | 621 | (while (<= this-row array-max-row) |
| 606 | (if rows-numbered | 622 | (if array-rows-numbered |
| 607 | (insert (format "%d:\n" this-row))) | 623 | (insert (format "%d:\n" this-row))) |
| 608 | (let ((this-column 1)) | 624 | (let ((this-column 1)) |
| 609 | ;; Loop through the columns. | 625 | ;; Loop through the columns. |
| 610 | (while (<= this-column max-column) | 626 | (while (<= this-column array-max-column) |
| 611 | (insert init-field) | 627 | (insert array-init-field) |
| 612 | (if (and (zerop (% this-column columns-per-line)) | 628 | (if (and (zerop (% this-column array-columns-per-line)) |
| 613 | (/= this-column max-column)) | 629 | (/= this-column array-max-column)) |
| 614 | (newline)) | 630 | (newline)) |
| 615 | (setq this-column (1+ this-column)))) | 631 | (setq this-column (1+ this-column)))) |
| 616 | (setq this-row (1+ this-row)) | 632 | (setq this-row (1+ this-row)) |
| @@ -619,21 +635,21 @@ If optional ARG is given, copy through ARG rows up." | |||
| 619 | (array-goto-cell 1 1)) | 635 | (array-goto-cell 1 1)) |
| 620 | 636 | ||
| 621 | (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered) | 637 | (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered) |
| 622 | "Reconfigure the state of `rows-numbered' and `columns-per-line'. | 638 | "Reconfigure the state of `array-rows-numbered' and `array-columns-per-line'. |
| 623 | NEW-COLUMNS-PER-LINE is the desired value of `columns-per-line' and | 639 | NEW-COLUMNS-PER-LINE is the desired value of `array-columns-per-line' and |
| 624 | NEW-ROWS-NUMBERED (a character, either ?y or ?n) is the desired value | 640 | NEW-ROWS-NUMBERED (a character, either ?y or ?n) is the desired value |
| 625 | of rows-numbered." | 641 | of array-rows-numbered." |
| 626 | (interactive "nColumns per line: \ncRows numbered? (y or n) ") | 642 | (interactive "nColumns per line: \ncRows numbered? (y or n) ") |
| 627 | ;; Check on new-columns-per-line | 643 | ;; Check on new-columns-per-line |
| 628 | (let ((check t)) | 644 | (let ((check t)) |
| 629 | (while check | 645 | (while check |
| 630 | (if (and (>= new-columns-per-line 1) | 646 | (if (and (>= new-columns-per-line 1) |
| 631 | (<= new-columns-per-line max-column)) | 647 | (<= new-columns-per-line array-max-column)) |
| 632 | (setq check nil) | 648 | (setq check nil) |
| 633 | (setq new-columns-per-line | 649 | (setq new-columns-per-line |
| 634 | (string-to-int | 650 | (string-to-int |
| 635 | (read-input | 651 | (read-input |
| 636 | (format "Columns per line (1 - %d): " max-column))))))) | 652 | (format "Columns per line (1 - %d): " array-max-column))))))) |
| 637 | ;; Check on new-rows-numbered. It has to be done this way | 653 | ;; Check on new-rows-numbered. It has to be done this way |
| 638 | ;; because interactive does not have y-or-n-p. | 654 | ;; because interactive does not have y-or-n-p. |
| 639 | (cond | 655 | (cond |
| @@ -647,13 +663,13 @@ of rows-numbered." | |||
| 647 | (array-update-buffer-position) | 663 | (array-update-buffer-position) |
| 648 | (let* ((main-buffer (buffer-name (current-buffer))) | 664 | (let* ((main-buffer (buffer-name (current-buffer))) |
| 649 | (temp-buffer (generate-new-buffer " *Array*")) | 665 | (temp-buffer (generate-new-buffer " *Array*")) |
| 650 | (temp-max-row max-row) | 666 | (temp-max-row array-max-row) |
| 651 | (temp-max-column max-column) | 667 | (temp-max-column array-max-column) |
| 652 | (old-rows-numbered rows-numbered) | 668 | (old-rows-numbered array-rows-numbered) |
| 653 | (old-columns-per-line columns-per-line) | 669 | (old-columns-per-line array-columns-per-line) |
| 654 | (old-lines-per-row lines-per-row) | 670 | (old-lines-per-row array-lines-per-row) |
| 655 | (old-field-width field-width) | 671 | (old-field-width array-field-width) |
| 656 | (old-line-length line-length) | 672 | (old-line-length array-line-length) |
| 657 | (this-row 1)) | 673 | (this-row 1)) |
| 658 | (array-update-array-position) | 674 | (array-update-array-position) |
| 659 | ;; Do the cutting in a temporary buffer. | 675 | ;; Do the cutting in a temporary buffer. |
| @@ -701,12 +717,12 @@ of rows-numbered." | |||
| 701 | (let ((inhibit-quit t)) | 717 | (let ((inhibit-quit t)) |
| 702 | (set-buffer main-buffer) | 718 | (set-buffer main-buffer) |
| 703 | (erase-buffer) | 719 | (erase-buffer) |
| 704 | (insert-buffer temp-buffer) | 720 | (insert-buffer temp-buffer) |
| 705 | ;; Update local variables. | 721 | ;; Update local variables. |
| 706 | (setq columns-per-line new-columns-per-line) | 722 | (setq array-columns-per-line new-columns-per-line) |
| 707 | (setq rows-numbered new-rows-numbered) | 723 | (setq array-rows-numbered new-rows-numbered) |
| 708 | (setq line-length (* old-field-width new-columns-per-line)) | 724 | (setq array-line-length (* old-field-width new-columns-per-line)) |
| 709 | (setq lines-per-row | 725 | (setq array-lines-per-row |
| 710 | (+ (floor (1- temp-max-column) new-columns-per-line) | 726 | (+ (floor (1- temp-max-column) new-columns-per-line) |
| 711 | (if new-rows-numbered 2 1))) | 727 | (if new-rows-numbered 2 1))) |
| 712 | (array-goto-cell (or array-row 1) (or array-column 1))) | 728 | (array-goto-cell (or array-row 1) (or array-column 1))) |
| @@ -716,7 +732,7 @@ of rows-numbered." | |||
| 716 | (defun array-expand-rows () | 732 | (defun array-expand-rows () |
| 717 | "Expand the rows so each fits on one line and remove row numbers." | 733 | "Expand the rows so each fits on one line and remove row numbers." |
| 718 | (interactive) | 734 | (interactive) |
| 719 | (array-reconfigure-rows max-column ?n)) | 735 | (array-reconfigure-rows array-max-column ?n)) |
| 720 | 736 | ||
| 721 | 737 | ||
| 722 | 738 | ||
| @@ -728,12 +744,12 @@ of rows-numbered." | |||
| 728 | (t index))) | 744 | (t index))) |
| 729 | 745 | ||
| 730 | (defun xor (pred1 pred2) | 746 | (defun xor (pred1 pred2) |
| 731 | "Returns the logical exclusive or of predicates PRED1 and PRED2." | 747 | "Return the logical exclusive or of predicates PRED1 and PRED2." |
| 732 | (and (or pred1 pred2) | 748 | (and (or pred1 pred2) |
| 733 | (not (and pred1 pred2)))) | 749 | (not (and pred1 pred2)))) |
| 734 | 750 | ||
| 735 | (defun current-line () | 751 | (defun current-line () |
| 736 | "Return the current buffer line at point. The first line is 0." | 752 | "Return the current buffer line at point. The first line is 0." |
| 737 | (save-excursion | 753 | (save-excursion |
| 738 | (beginning-of-line) | 754 | (beginning-of-line) |
| 739 | (count-lines (point-min) (point)))) | 755 | (count-lines (point-min) (point)))) |
| @@ -744,8 +760,8 @@ Return COLUMN." | |||
| 744 | (or (and (= column (move-to-column column)) | 760 | (or (and (= column (move-to-column column)) |
| 745 | column) | 761 | column) |
| 746 | ;; There is a tab in the way. | 762 | ;; There is a tab in the way. |
| 747 | (if respect-tabs | 763 | (if array-respect-tabs |
| 748 | (error "There is a TAB character in the way.") | 764 | (error "There is a TAB character in the way") |
| 749 | (progn | 765 | (progn |
| 750 | (untabify-backward) | 766 | (untabify-backward) |
| 751 | (move-to-column column))))) | 767 | (move-to-column column))))) |
| @@ -761,7 +777,7 @@ Return COLUMN." | |||
| 761 | 777 | ||
| 762 | ;;; Array mode. | 778 | ;;; Array mode. |
| 763 | 779 | ||
| 764 | (defvar array-mode-map nil | 780 | (defvar array-mode-map nil |
| 765 | "Keymap used in array mode.") | 781 | "Keymap used in array mode.") |
| 766 | 782 | ||
| 767 | (if array-mode-map | 783 | (if array-mode-map |
| @@ -798,10 +814,10 @@ Return COLUMN." | |||
| 798 | considered to be a two-dimensional set of strings. The strings are | 814 | considered to be a two-dimensional set of strings. The strings are |
| 799 | NOT recognized as integers or real numbers. | 815 | NOT recognized as integers or real numbers. |
| 800 | 816 | ||
| 801 | The array MUST reside at the top of the buffer. | 817 | The array MUST reside at the top of the buffer. |
| 802 | 818 | ||
| 803 | TABs are not respected, and may be converted into spaces at any time. | 819 | TABs are not respected, and may be converted into spaces at any time. |
| 804 | Setting the variable 'respect-tabs to non-nil will prevent TAB conversion, | 820 | Setting the variable 'array-respect-tabs to non-nil will prevent TAB conversion, |
| 805 | but will cause many functions to give errors if they encounter one. | 821 | but will cause many functions to give errors if they encounter one. |
| 806 | 822 | ||
| 807 | Upon entering array mode, you will be prompted for the values of | 823 | Upon entering array mode, you will be prompted for the values of |
| @@ -811,16 +827,16 @@ in array mode may have different values assigned to the variables. | |||
| 811 | The variables are: | 827 | The variables are: |
| 812 | 828 | ||
| 813 | Variables you assign: | 829 | Variables you assign: |
| 814 | max-row: The number of rows in the array. | 830 | array-max-row: The number of rows in the array. |
| 815 | max-column: The number of columns in the array. | 831 | array-max-column: The number of columns in the array. |
| 816 | columns-per-line: The number of columns in the array per line of buffer. | 832 | array-columns-per-line: The number of columns in the array per line of buffer. |
| 817 | field-width: The width of each field, in characters. | 833 | array-field-width: The width of each field, in characters. |
| 818 | rows-numbered: A logical variable describing whether to ignore | 834 | array-rows-numbered: A logical variable describing whether to ignore |
| 819 | row numbers in the buffer. | 835 | row numbers in the buffer. |
| 820 | 836 | ||
| 821 | Variables which are calculated: | 837 | Variables which are calculated: |
| 822 | line-length: The number of characters in a buffer line. | 838 | array-line-length: The number of characters in a buffer line. |
| 823 | lines-per-row: The number of buffer lines used to display each row. | 839 | array-lines-per-row: The number of buffer lines used to display each row. |
| 824 | 840 | ||
| 825 | The following commands are available (an asterisk indicates it may | 841 | The following commands are available (an asterisk indicates it may |
| 826 | take a numeric prefix argument): | 842 | take a numeric prefix argument): |
| @@ -857,32 +873,32 @@ Entering array mode calls the function `array-mode-hook'." | |||
| 857 | 873 | ||
| 858 | (interactive) | 874 | (interactive) |
| 859 | ;; Number of rows in the array. | 875 | ;; Number of rows in the array. |
| 860 | (make-local-variable 'max-row) | 876 | (make-local-variable 'array-max-row) |
| 861 | ;; Number of columns in the array. | 877 | ;; Number of columns in the array. |
| 862 | (make-local-variable 'max-column) | 878 | (make-local-variable 'array-max-column) |
| 863 | ;; Number of array columns per line. | 879 | ;; Number of array columns per line. |
| 864 | (make-local-variable 'columns-per-line) | 880 | (make-local-variable 'array-columns-per-line) |
| 865 | ;; Width of a field in the array. | 881 | ;; Width of a field in the array. |
| 866 | (make-local-variable 'field-width) | 882 | (make-local-variable 'array-field-width) |
| 867 | ;; Are rows numbered in the buffer? | 883 | ;; Are rows numbered in the buffer? |
| 868 | (make-local-variable 'rows-numbered) | 884 | (make-local-variable 'array-rows-numbered) |
| 869 | ;; Length of a line in the array. | 885 | ;; Length of a line in the array. |
| 870 | (make-local-variable 'line-length) | 886 | (make-local-variable 'array-line-length) |
| 871 | ;; Number of lines per array row. | 887 | ;; Number of lines per array row. |
| 872 | (make-local-variable 'lines-per-row) | 888 | (make-local-variable 'array-lines-per-row) |
| 873 | ;; Current line number of point in the buffer. | 889 | ;; Current line number of point in the buffer. |
| 874 | (make-local-variable 'buffer-line) | 890 | (make-local-variable 'array-buffer-line) |
| 875 | ;; Current column number of point in the buffer. | 891 | ;; Current column number of point in the buffer. |
| 876 | (make-local-variable 'buffer-column) | 892 | (make-local-variable 'array-buffer-column) |
| 877 | ;; Current array row location of point. | 893 | ;; Current array row location of point. |
| 878 | (make-local-variable 'array-row) | 894 | (make-local-variable 'array-row) |
| 879 | ;; Current array column location of point. | 895 | ;; Current array column location of point. |
| 880 | (make-local-variable 'array-column) | 896 | (make-local-variable 'array-column) |
| 881 | ;; Current field string being copied. | 897 | ;; Current field string being copied. |
| 882 | (make-local-variable 'copy-string) | 898 | (make-local-variable 'array-copy-string) |
| 883 | ;; Should TAB conversion be prevented? | 899 | ;; Should TAB conversion be prevented? |
| 884 | (make-local-variable 'respect-tabs) | 900 | (make-local-variable 'array-respect-tabs) |
| 885 | (setq respect-tabs nil) | 901 | (setq array-respect-tabs nil) |
| 886 | (array-init-local-variables) | 902 | (array-init-local-variables) |
| 887 | (setq major-mode 'array-mode) | 903 | (setq major-mode 'array-mode) |
| 888 | (setq mode-name "Array") | 904 | (setq mode-name "Array") |
| @@ -898,8 +914,7 @@ Entering array mode calls the function `array-mode-hook'." | |||
| 898 | ;;; Initialization functions. These are not interactive. | 914 | ;;; Initialization functions. These are not interactive. |
| 899 | 915 | ||
| 900 | (defun array-init-local-variables () | 916 | (defun array-init-local-variables () |
| 901 | "Initialize the variables associated with the | 917 | "Initialize the variables associated with the array in this buffer." |
| 902 | array in this buffer." | ||
| 903 | (array-init-max-row) | 918 | (array-init-max-row) |
| 904 | (array-init-max-column) | 919 | (array-init-max-column) |
| 905 | (array-init-columns-per-line) | 920 | (array-init-columns-per-line) |
| @@ -910,42 +925,42 @@ array in this buffer." | |||
| 910 | (message "")) | 925 | (message "")) |
| 911 | 926 | ||
| 912 | (defun array-init-max-row (&optional arg) | 927 | (defun array-init-max-row (&optional arg) |
| 913 | "Initialize the value of max-row." | 928 | "Initialize the value of `array-max-row'." |
| 914 | (setq max-row | 929 | (setq array-max-row |
| 915 | (or arg (string-to-int (read-input "Number of array rows: "))))) | 930 | (or arg (string-to-int (read-input "Number of array rows: "))))) |
| 916 | 931 | ||
| 917 | (defun array-init-max-column (&optional arg) | 932 | (defun array-init-max-column (&optional arg) |
| 918 | "Initialize the value of max-column." | 933 | "Initialize the value of `array-max-column'." |
| 919 | (setq max-column | 934 | (setq array-max-column |
| 920 | (or arg (string-to-int (read-input "Number of array columns: "))))) | 935 | (or arg (string-to-int (read-input "Number of array columns: "))))) |
| 921 | 936 | ||
| 922 | (defun array-init-columns-per-line (&optional arg) | 937 | (defun array-init-columns-per-line (&optional arg) |
| 923 | "Initialize the value of columns-per-line." | 938 | "Initialize the value of `array-columns-per-line'." |
| 924 | (setq columns-per-line | 939 | (setq array-columns-per-line |
| 925 | (or arg (string-to-int (read-input "Array columns per line: "))))) | 940 | (or arg (string-to-int (read-input "Array columns per line: "))))) |
| 926 | 941 | ||
| 927 | (defun array-init-field-width (&optional arg) | 942 | (defun array-init-field-width (&optional arg) |
| 928 | "Initialize the value of field-width." | 943 | "Initialize the value of `array-field-width'." |
| 929 | (setq field-width | 944 | (setq array-field-width |
| 930 | (or arg (string-to-int (read-input "Field width: "))))) | 945 | (or arg (string-to-int (read-input "Field width: "))))) |
| 931 | 946 | ||
| 932 | (defun array-init-rows-numbered (&optional arg) | 947 | (defun array-init-rows-numbered (&optional arg) |
| 933 | "Initialize the value of rows-numbered." | 948 | "Initialize the value of `array-rows-numbered'." |
| 934 | (setq rows-numbered | 949 | (setq array-rows-numbered |
| 935 | (or arg (y-or-n-p "Rows numbered? ")))) | 950 | (or arg (y-or-n-p "Rows numbered? ")))) |
| 936 | 951 | ||
| 937 | (defun array-init-line-length (&optional arg) | 952 | (defun array-init-line-length (&optional arg) |
| 938 | "Initialize the value of line-length." | 953 | "Initialize the value of `array-line-length'." |
| 939 | (setq line-length | 954 | (setq array-line-length |
| 940 | (or arg | 955 | (or arg |
| 941 | (* field-width columns-per-line)))) | 956 | (* array-field-width array-columns-per-line)))) |
| 942 | 957 | ||
| 943 | (defun array-init-lines-per-row (&optional arg) | 958 | (defun array-init-lines-per-row (&optional arg) |
| 944 | "Initialize the value of lines-per-row." | 959 | "Initialize the value of `array-lines-per-row'." |
| 945 | (setq lines-per-row | 960 | (setq array-lines-per-row |
| 946 | (or arg | 961 | (or arg |
| 947 | (+ (floor (1- max-column) columns-per-line) | 962 | (+ (floor (1- array-max-column) array-columns-per-line) |
| 948 | (if rows-numbered 2 1))))) | 963 | (if array-rows-numbered 2 1))))) |
| 949 | 964 | ||
| 950 | (provide 'array) | 965 | (provide 'array) |
| 951 | 966 | ||