• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching defs:array

0 ;;; array.el --- array editing commands for GNU Emacs
29 ;; Commands for editing a buffer interpreted as a rectangular array
30 ;; or matrix of whitespace-separated strings. You specify the array
40 ;; Make 'array-copy-column-right faster.
46 (defvar array-max-column nil "Number of columns in the array.")
47 (defvar array-columns-per-line nil "Number of array columns per line.")
48 (defvar array-buffer-column nil "Current column number of point in the buffer.")
49 (defvar array-line-length nil "Length of a line in the array.")
50 (defvar array-buffer-line nil "Current line number of point in the buffer.")
51 (defvar array-lines-per-row nil "Number of lines per array row.")
52 (defvar array-max-row nil "Number of rows in the array.")
53 (defvar array-field-width nil "Width of a field in the array.")
54 (defvar array-row nil "Current array row location of point.")
55 (defvar array-column nil "Current array column location of point.")
56 (defvar array-rows-numbered nil "Are rows numbered in the buffer?")
57 (defvar array-copy-string nil "Current field string being copied.")
58 (defvar array-respect-tabs nil "Should TAB conversion be prevented?")
62 (defun array-cursor-in-array-range ()
63 "Return t if the cursor is in a valid array cell.
65 (let ((columns-last-line (% array-max-column array-columns-per-line)))
66 ;; Requires array-buffer-line and array-buffer-column to be current.
69 (>= array-buffer-column array-line-length)
71 (>= array-buffer-line (* array-lines-per-row array-max-row))
73 ;; than the others, and the cursor is after the last array column
75 (and (zerop (% (1+ array-buffer-line) array-lines-per-row))
77 (>= array-buffer-column (* columns-last-line array-field-width)))))))
79 (defun array-current-row ()
80 "Return the array row of the field in which the cursor is located."
81 ;; Requires array-buffer-line and array-buffer-column to be current.
82 (and (array-cursor-in-array-range)
83 (1+ (floor array-buffer-line array-lines-per-row))))
85 (defun array-current-column ()
86 "Return the array column of the field in which the cursor is located."
87 ;; Requires array-buffer-line and array-buffer-column to be current.
88 (and (array-cursor-in-array-range)
90 (not (and array-rows-numbered
91 (zerop (% array-buffer-line array-lines-per-row))))
94 (* array-columns-per-line
95 (if array-rows-numbered
96 (1- (% array-buffer-line array-lines-per-row))
97 (% array-buffer-line array-lines-per-row)))
99 (1+ (floor array-buffer-column array-field-width)))))
101 (defun array-update-array-position (&optional a-row a-column)
102 "Set `array-row' and `array-column' to their current values.
104 ;; Requires that array-buffer-line and array-buffer-column be current.
105 (setq array-row (or a-row (array-current-row))
106 array-column (or a-column (array-current-column))))
108 (defun array-update-buffer-position ()
109 "Set `array-buffer-line' and `array-buffer-column' to their current values."
110 (setq array-buffer-line (current-line)
111 array-buffer-column (current-column)))
118 (defun array-what-position ()
121 (let ((array-buffer-line (current-line))
122 (array-buffer-column (current-column)))
124 (prin1-to-string (array-current-row))
125 (prin1-to-string (array-current-column)))))
127 (defun array-display-local-variables ()
136 (prin1-to-string array-max-row)))
138 (prin1-to-string array-max-column)))
140 (prin1-to-string array-columns-per-line)))
142 (prin1-to-string array-field-width)))
144 (prin1-to-string array-rows-numbered)))
146 (prin1-to-string array-lines-per-row)))
148 (prin1-to-string array-line-length))))))
155 (defun array-beginning-of-field (&optional go-there)
158 ;; Requires that array-buffer-column be current.
159 (let ((goal-column (- array-buffer-column (% array-buffer-column array-field-width))))
164 (defun array-end-of-field (&optional go-there)
165 "Return the column of the end of the current array field.
167 ;; Requires that array-buffer-column be current.
168 (let ((goal-column (+ (- array-buffer-column (% array-buffer-column array-field-width))
169 array-field-width)))
174 (defun array-move-to-cell (a-row a-column)
175 "Move to array row A-ROW and array column A-COLUMN.
177 (let ((goal-line (+ (* array-lines-per-row (1- a-row))
178 (if array-rows-numbered 1 0)
179 (floor (1- a-column) array-columns-per-line)))
180 (goal-column (* array-field-width (% (1- a-column) array-columns-per-line))))
185 (defun array-move-to-row (a-row)
186 "Move to array row A-ROW preserving the current array column.
187 Leave point at the beginning of the field and return the new array row."
188 ;; Requires that array-buffer-line and array-buffer-column be current.
189 (let ((goal-line (+ (* array-lines-per-row (1- a-row))
190 (% array-buffer-line array-lines-per-row)))
191 (goal-column (- array-buffer-column (% array-buffer-column array-field-width))))
192 (forward-line (- goal-line array-buffer-line))
196 (defun array-move-to-column (a-column)
197 "Move to array column A-COLUMN preserving the current array row.
198 Leave point at the beginning of the field and return the new array column."
199 ;; Requires that array-buffer-line and array-buffer-column be current.
200 (let ((goal-line (+ (- array-buffer-line (% array-buffer-line array-lines-per-row))
201 (if array-rows-numbered 1 0)
202 (floor (1- a-column) array-columns-per-line)))
203 (goal-column (* array-field-width (% (1- a-column) array-columns-per-line))))
204 (forward-line (- goal-line array-buffer-line))
208 (defun array-move-one-row (sign)
209 "Move one array row in direction SIGN (1 or -1).
210 Leave point at the beginning of the field and return the new array row.
211 If requested to move beyond the array bounds, signal an error."
212 ;; Requires that array-buffer-line and array-buffer-column be current.
213 (let ((goal-column (array-beginning-of-field))
214 (array-row (or (array-current-row)
215 (error "Cursor is not in a valid array cell"))))
216 (cond ((and (= array-row array-max-row) (= sign 1))
217 (error "End of array"))
218 ((and (= array-row 1) (= sign -1))
219 (error "Beginning of array"))
222 (forward-line (* sign array-lines-per-row))
224 (+ array-row sign))))))
226 (defun array-move-one-column (sign)
227 "Move one array column in direction SIGN (1 or -1).
228 Leave point at the beginning of the field and return the new array column.
229 If requested to move beyond the array bounds, signal an error."
230 ;; Requires that array-buffer-line and array-buffer-column be current.
231 (let ((array-column (or (array-current-column)
232 (error "Cursor is not in a valid array cell"))))
233 (cond ((and (= array-column array-max-column) (= sign 1))
234 (error "End of array"))
235 ((and (= array-column 1) (= sign -1))
236 (error "Beginning of array"))
240 ((and (= sign -1) (= 1 (% array-column array-columns-per-line)))
243 (* array-field-width (1- array-columns-per-line))))
245 ((and (= sign 1) (zerop (% array-column array-columns-per-line)))
249 (move-to-column-untabify (+ (array-beginning-of-field)
250 (* array-field-width sign)))))
251 (+ array-column sign)))))
253 (defun array-normalize-cursor ()
257 (let ((array-buffer-column (current-column)))
259 (1- (save-excursion (array-end-of-field t) (point))))
260 (array-maybe-scroll-horizontally)))
262 (defun array-maybe-scroll-horizontally ()
264 ;; This is only called from array-normalize-cursor so
265 ;; array-buffer-column will always be current.
269 ((and (>= array-buffer-column w-hscroll)
270 (<= array-buffer-column (+ w-hscroll w-width)))
273 ((> array-buffer-column (+ w-hscroll w-width))
275 (scroll-left (- (- array-buffer-column w-hscroll)
279 (scroll-right (+ (- w-hscroll array-buffer-column)
287 (defun array-next-row (&optional arg)
288 "Move down one array row, staying in the current array column.
289 If optional ARG is given, move down ARG array rows."
291 (let ((array-buffer-line (current-line))
292 (array-buffer-column (current-column)))
294 (array-move-one-row arg)
295 (array-move-to-row
296 (limit-index (+ (or (array-current-row)
297 (error "Cursor is not in an array cell"))
299 array-max-row))))
300 (array-normalize-cursor))
302 (defun array-previous-row (&optional arg)
303 "Move up one array row, staying in the current array column.
304 If optional ARG is given, move up ARG array rows."
306 (array-next-row (- arg)))
308 (defun array-forward-column (&optional arg)
309 "Move forward one field, staying in the current array row.
310 If optional ARG is given, move forward ARG array columns.
313 (let ((array-buffer-line (current-line))
314 (array-buffer-column (current-column)))
316 (array-move-one-column arg)
317 (array-move-to-column
318 (limit-index (+ (or (array-current-column)
319 (error "Cursor is not in an array cell"))
321 array-max-column))))
322 (array-normalize-cursor))
324 (defun array-backward-column (&optional arg)
325 "Move backward one field, staying in the current array row.
326 If optional ARG is given, move backward ARG array columns.
329 (array-forward-column (- arg)))
331 (defun array-goto-cell (a-row a-column)
332 "Go to array row A-ROW and array column A-COLUMN."
334 (array-move-to-cell
335 (limit-index a-row array-max-row)
336 (limit-index a-column array-max-column))
337 (array-normalize-cursor))
344 (defun array-field-string ()
346 ;; Requires that array-buffer-column be current.
348 (save-excursion (array-beginning-of-field t) (point))
349 (save-excursion (array-end-of-field t) (point))))
351 (defun array-copy-once-vertically (sign)
352 "Copy the current field into one array row in direction SIGN (1 or -1).
353 Leave point at the beginning of the field and return the new array row.
354 If requested to move beyond the array bounds, signal an error."
355 ;; Requires that array-buffer-line, array-buffer-column, and array-copy-string be current.
356 (let ((a-row (array-move-one-row sign)))
358 (delete-region (point) (save-excursion (array-end-of-field t) (point)))
359 (insert array-copy-string))
360 (move-to-column array-buffer-column)
363 (defun array-copy-once-horizontally (sign)
364 "Copy the current field into one array column in direction SIGN (1 or -1).
365 Leave point at the beginning of the field and return the new array column.
366 If requested to move beyond the array bounds, signal an error."
367 ;; Requires that array-buffer-line, array-buffer-column, and array-copy-string be current.
368 (let ((a-column (array-move-one-column sign)))
369 (array-update-buffer-position)
371 (delete-region (point) (save-excursion (array-end-of-field t) (point)))
372 (insert array-copy-string))
373 (move-to-column array-buffer-column)
376 (defun array-copy-to-row (a-row)
379 ;; Requires that array-buffer-line, array-buffer-column, array-row, and
380 ;; array-copy-string be current.
381 (let* ((num (- a-row array-row))
385 (array-move-one-row sign)
386 (array-update-buffer-position)
388 (delete-region (point) (save-excursion (array-end-of-field t) (point)))
389 (insert array-copy-string))
390 (move-to-column array-buffer-column)
393 (defun array-copy-to-column (a-column)
396 ;; Requires that array-buffer-line, array-buffer-column, array-column, and
397 ;; array-copy-string be current.
398 (let* ((num (- a-column array-column))
402 (array-move-one-column sign)
403 (array-update-buffer-position)
405 (delete-region (point) (save-excursion (array-end-of-field t) (point)))
406 (insert array-copy-string))
407 (move-to-column array-buffer-column)
410 (defun array-copy-to-cell (a-row a-column)
413 ;; Requires that array-copy-string be current.
414 (array-move-to-cell a-row a-column)
415 (array-update-buffer-position)
416 (delete-region (point) (save-excursion (array-end-of-field t) (point)))
417 (insert array-copy-string)
418 (move-to-column array-buffer-column))
425 (defun array-copy-down (&optional arg)
426 "Copy the current field one array row down.
427 If optional ARG is given, copy down through ARG array rows."
429 (let* ((array-buffer-line (current-line))
430 (array-buffer-column (current-column))
431 (array-row (or (array-current-row)
432 (error "Cursor is not in a valid array cell")))
433 (array-copy-string (array-field-string)))
435 (array-copy-once-vertically arg)
436 (array-copy-to-row
437 (limit-index (+ array-row arg) array-max-row))))
438 (array-normalize-cursor))
440 (defun array-copy-up (&optional arg)
441 "Copy the current field one array row up.
442 If optional ARG is given, copy up through ARG array rows."
444 (array-copy-down (- arg)))
446 (defun array-copy-forward (&optional arg)
447 "Copy the current field one array column to the right.
448 If optional ARG is given, copy through ARG array columns to the right."
450 (let* ((array-buffer-line (current-line))
451 (array-buffer-column (current-column))
452 (array-column (or (array-current-column)
453 (error "Cursor is not in a valid array cell")))
454 (array-copy-string (array-field-string)))
456 (array-copy-once-horizontally arg)
457 (array-copy-to-column
458 (limit-index (+ array-column arg) array-max-column))))
459 (array-normalize-cursor))
461 (defun array-copy-backward (&optional arg)
462 "Copy the current field one array column to the left.
463 If optional ARG is given, copy through ARG array columns to the left."
465 (array-copy-forward (- arg)))
467 (defun array-copy-column-forward (&optional arg)
469 If optional ARG is given, copy through ARG array columns to the right."
471 (array-update-buffer-position)
472 (array-update-array-position)
473 (if (not array-column)
474 (error "Cursor is not in a valid array cell"))
477 (while (< this-row array-max-row)
479 (array-move-to-cell this-row array-column)
480 (array-update-buffer-position)
481 (let ((array-copy-string (array-field-string)))
483 (array-copy-once-horizontally arg)
484 (array-copy-to-column
485 (limit-index (+ array-column arg) array-max-column))))))
487 (array-move-to-row array-row)
488 (array-normalize-cursor))
490 (defun array-copy-column-backward (&optional arg)
494 (array-copy-column-forward (- arg)))
496 (defun array-copy-row-down (&optional arg)
500 (array-update-buffer-position)
501 (array-update-array-position)
502 (if (not array-row)
503 (error "Cursor is not in a valid array cell"))
505 ((and (= array-row 1) (= arg -1))
506 (error "Beginning of array"))
507 ((and (= array-row array-max-row) (= arg 1))
508 (error "End of array"))
510 (let* ((array-copy-string
512 (save-excursion (array-move-to-cell array-row 1)
514 (save-excursion (array-move-to-cell array-row array-max-column)
517 (this-row array-row)
518 (goal-row (limit-index (+ this-row arg) array-max-row))
524 (array-move-to-cell this-row 1)
528 (array-move-to-cell this-row array-max-column)
531 (insert array-copy-string))
533 (array-move-to-cell goal-row (or array-column 1)))))
534 (array-normalize-cursor))
536 (defun array-copy-row-up (&optional arg)
537 "Copy the entire current array row into the row above.
540 (array-copy-row-down (- arg)))
542 (defun array-fill-rectangle ()
546 (array-update-buffer-position)
547 (let ((p-row (or (array-current-row)
548 (error "Cursor is not in a valid array cell")))
549 (p-column (or (array-current-column)
550 (error "Cursor is not in a valid array cell")))
554 (array-update-buffer-position)
555 (or (array-current-row)
556 (error "Mark is not in a valid array cell"))))
560 (array-update-buffer-position)
561 (or (array-current-column)
562 (error "Mark is not in a valid array cell")))))
569 (let ((array-copy-string
571 (array-move-to-cell m-row m-column)
572 (array-update-buffer-position)
573 (array-field-string))))
574 (array-copy-to-cell top-row left-column)
575 (array-update-array-position top-row left-column)
576 (array-update-buffer-position)
577 (array-copy-to-column right-column))
579 (array-move-to-cell top-row left-column)
580 (let ((array-copy-string
584 (array-move-to-cell top-row right-column)
585 (setq array-buffer-column (current-column))
586 (array-end-of-field t)
591 (array-move-to-cell this-row left-column)
596 (array-move-to-cell this-row right-column)
597 (setq array-buffer-column (current-column))
598 (array-end-of-field t)
600 (insert array-copy-string)))))
602 (array-goto-cell p-row p-column)))
607 ;;; Reconfiguration of the array.
609 (defun array-make-template ()
610 "Create the template of an array."
612 ;; If there is a conflict between array-field-width and init-string, resolve it.
619 (if (/= len array-field-width)
621 (progn (setq array-field-width len)
628 (while (<= this-row array-max-row)
629 (if array-rows-numbered
633 (while (<= this-column array-max-column)
635 (if (and (zerop (% this-column array-columns-per-line))
636 (/= this-column array-max-column))
642 (array-goto-cell 1 1))
644 (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered)
645 "Reconfigure the state of `array-rows-numbered' and `array-columns-per-line'.
646 NEW-COLUMNS-PER-LINE is the desired value of `array-columns-per-line' and
648 of `array-rows-numbered'."
654 (<= new-columns-per-line array-max-column))
659 (format "Columns per line (1 - %d): " array-max-column)))))))
670 (array-update-buffer-position)
673 (temp-max-row array-max-row)
674 (temp-max-column array-max-column)
675 (old-rows-numbered array-rows-numbered)
676 (old-columns-per-line array-columns-per-line)
677 (old-lines-per-row array-lines-per-row)
678 (old-field-width array-field-width)
679 (old-line-length array-line-length)
681 (array-update-array-position)
699 ;; Deal with the array columns in this row.
729 (setq array-columns-per-line new-columns-per-line)
730 (setq array-rows-numbered new-rows-numbered)
731 (setq array-line-length (* old-field-width new-columns-per-line))
732 (setq array-lines-per-row
735 (array-goto-cell (or array-row 1) (or array-column 1)))
739 (defun array-expand-rows ()
742 (array-reconfigure-rows array-max-column ?n))
771 (if array-respect-tabs
789 (defvar array-mode-map nil
790 "Keymap used in array mode.")
792 (if array-mode-map
794 (setq array-mode-map (make-keymap))
796 (define-key array-mode-map "\M-ad" 'array-display-local-variables)
797 (define-key array-mode-map "\M-am" 'array-make-template)
798 (define-key array-mode-map "\M-ae" 'array-expand-rows)
799 (define-key array-mode-map "\M-ar" 'array-reconfigure-rows)
800 (define-key array-mode-map "\M-a=" 'array-what-position)
801 (define-key array-mode-map "\M-ag" 'array-goto-cell)
802 (define-key array-mode-map "\M-af" 'array-fill-rectangle)
803 (define-key array-mode-map "\C-n" 'array-next-row)
804 (define-key array-mode-map "\C-p" 'array-previous-row)
805 (define-key array-mode-map "\C-f" 'array-forward-column)
806 (define-key array-mode-map "\C-b" 'array-backward-column)
807 (define-key array-mode-map "\M-n" 'array-copy-down)
808 (define-key array-mode-map "\M-p" 'array-copy-up)
809 (define-key array-mode-map "\M-f" 'array-copy-forward)
810 (define-key array-mode-map "\M-b" 'array-copy-backward)
811 (define-key array-mode-map "\M-\C-n" 'array-copy-row-down)
812 (define-key array-mode-map "\M-\C-p" 'array-copy-row-up)
813 (define-key array-mode-map "\M-\C-f" 'array-copy-column-forward)
814 (define-key array-mode-map "\M-\C-b" 'array-copy-column-backward))
816 (put 'array-mode 'mode-class 'special)
819 (defun array-mode ()
822 Array mode is a specialized mode for editing arrays. An array is
826 The array MUST reside at the top of the buffer.
829 Setting the variable `array-respect-tabs' to non-nil will prevent TAB conversion,
832 Upon entering array mode, you will be prompted for the values of
835 in array mode may have different values assigned to the variables.
839 array-max-row: The number of rows in the array.
840 array-max-column: The number of columns in the array.
841 array-columns-per-line: The number of columns in the array per line of buffer.
842 array-field-width: The width of each field, in characters.
843 array-rows-numbered: A logical variable describing whether to ignore
847 array-line-length: The number of characters in a buffer line.
848 array-lines-per-row: The number of buffer lines used to display each row.
853 * \\<array-mode-map>\\[array-forward-column] Move forward one column.
854 * \\[array-backward-column] Move backward one column.
855 * \\[array-next-row] Move down one row.
856 * \\[array-previous-row] Move up one row.
858 * \\[array-copy-forward] Copy the current field into the column to the right.
859 * \\[array-copy-backward] Copy the current field into the column to the left.
860 * \\[array-copy-down] Copy the current field into the row below.
861 * \\[array-copy-up] Copy the current field into the row above.
863 * \\[array-copy-column-forward] Copy the current column into the column to the right.
864 * \\[array-copy-column-backward] Copy the current column into the column to the left.
865 * \\[array-copy-row-down] Copy the current row into the row below.
866 * \\[array-copy-row-up] Copy the current row into the row above.
868 \\[array-fill-rectangle] Copy the field at mark into every cell with row and column
871 \\[array-what-position] Display the current array row and column.
872 \\[array-goto-cell] Go to a particular array cell.
874 \\[array-make-template] Make a template for a new array.
875 \\[array-reconfigure-rows] Reconfigure the array.
876 \\[array-expand-rows] Expand the array (remove row numbers and
879 \\[array-display-local-variables] Display the current values of local variables.
881 Entering array mode calls the function `array-mode-hook'."
885 (make-local-variable 'array-buffer-line)
886 (make-local-variable 'array-buffer-column)
887 (make-local-variable 'array-row)
888 (make-local-variable 'array-column)
889 (make-local-variable 'array-copy-string)
890 (set (make-local-variable 'array-respect-tabs) nil)
891 (set (make-local-variable 'array-max-row)
892 (read-number "Number of array rows: "))
893 (set (make-local-variable 'array-max-column)
894 (read-number "Number of array columns: "))
895 (set (make-local-variable 'array-columns-per-line)
897 (set (make-local-variable 'array-field-width)
899 (set (make-local-variable 'array-rows-numbered)
901 (set (make-local-variable 'array-line-length)
902 (* array-field-width array-columns-per-line))
903 (set (make-local-variable 'array-lines-per-row)
904 (+ (floor (1- array-max-column) array-columns-per-line)
905 (if array-rows-numbered 2 1)))
907 (setq major-mode 'array-mode)
912 (use-local-map array-mode-map)
913 (run-mode-hooks 'array-mode-hook))
918 (provide 'array)
921 ;;; array.el ends here