Mercurial > emacs
annotate lisp/array.el @ 98824:3808838357b8
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 18 Oct 2008 14:26:18 +0000 |
parents | ee5932bf781d |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
27286
diff
changeset
|
1 ;;; array.el --- array editing commands for GNU Emacs |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
180
diff
changeset
|
2 |
74439 | 3 ;; Copyright (C) 1987, 2000, 2001, 2002, 2003, 2004, |
79721 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
845 | 5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
6 ;; Author David M. Brown |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
8 ;; Keywords: extensions |
180 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
180 | 13 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
15 ;; (at your option) any later version. |
180 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
180 | 24 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
25 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
26 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 ;; Commands for editing a buffer interpreted as a rectangular array |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
28 ;; or matrix of whitespace-separated strings. You specify the array |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
29 ;; dimensions and some other parameters at startup time. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
30 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
31 ;; Written by dmb%morgoth@harvard.harvard.edu (address is old) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
32 ;; (David M. Brown at Goldberg-Zoino & Associates, Inc.) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
33 ;; Thanks to cph@kleph.ai.mit.edu for assistance |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
34 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
35 ;; To do: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
36 ;; Smooth initialization process by grokking local variables list |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
37 ;; at end of buffer or parsing buffer using whitespace as delimiters. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
38 ;; Make 'array-copy-column-right faster. |
180 | 39 |
40 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
41 ;;; Code: |
180 | 42 |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
43 (defvar array-max-column nil "Number of columns in the array.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
44 (defvar array-columns-per-line nil "Number of array columns per line.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
45 (defvar array-buffer-column nil "Current column number of point in the buffer.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
46 (defvar array-line-length nil "Length of a line in the array.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
47 (defvar array-buffer-line nil "Current line number of point in the buffer.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
48 (defvar array-lines-per-row nil "Number of lines per array row.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
49 (defvar array-max-row nil "Number of rows in the array.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
50 (defvar array-field-width nil "Width of a field in the array.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
51 (defvar array-row nil "Current array row location of point.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
52 (defvar array-column nil "Current array column location of point.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
53 (defvar array-rows-numbered nil "Are rows numbered in the buffer?") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
54 (defvar array-copy-string nil "Current field string being copied.") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
55 (defvar array-respect-tabs nil "Should TAB conversion be prevented?") |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
56 |
180 | 57 ;;; Internal information functions. |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42704
diff
changeset
|
58 |
180 | 59 (defun array-cursor-in-array-range () |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
60 "Return t if the cursor is in a valid array cell. |
180 | 61 Its ok to be on a row number line." |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
62 (let ((columns-last-line (% array-max-column array-columns-per-line))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
63 ;; Requires array-buffer-line and array-buffer-column to be current. |
180 | 64 (not (or |
65 ;; The cursor is too far to the right. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
66 (>= array-buffer-column array-line-length) |
180 | 67 ;; The cursor is below the last row. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
68 (>= array-buffer-line (* array-lines-per-row array-max-row)) |
180 | 69 ;; The cursor is on the last line of the row, the line is smaller |
70 ;; than the others, and the cursor is after the last array column | |
71 ;; on the line. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
72 (and (zerop (% (1+ array-buffer-line) array-lines-per-row)) |
180 | 73 (not (zerop columns-last-line)) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
74 (>= array-buffer-column (* columns-last-line array-field-width))))))) |
180 | 75 |
76 (defun array-current-row () | |
77 "Return the array row of the field in which the cursor is located." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
78 ;; Requires array-buffer-line and array-buffer-column to be current. |
180 | 79 (and (array-cursor-in-array-range) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
80 (1+ (floor array-buffer-line array-lines-per-row)))) |
180 | 81 |
82 (defun array-current-column () | |
83 "Return the array column of the field in which the cursor is located." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
84 ;; Requires array-buffer-line and array-buffer-column to be current. |
180 | 85 (and (array-cursor-in-array-range) |
86 ;; It's not okay to be on a row number line. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
87 (not (and array-rows-numbered |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
88 (zerop (% array-buffer-line array-lines-per-row)))) |
180 | 89 (+ |
90 ;; Array columns due to line differences. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
91 (* array-columns-per-line |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
92 (if array-rows-numbered |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
93 (1- (% array-buffer-line array-lines-per-row)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
94 (% array-buffer-line array-lines-per-row))) |
180 | 95 ;; Array columns on the current line. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
96 (1+ (floor array-buffer-column array-field-width))))) |
180 | 97 |
98 (defun array-update-array-position (&optional a-row a-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
99 "Set `array-row' and `array-column' to their current values. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
100 Set them to the optional arguments A-ROW and A-COLUMN if those are supplied." |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
101 ;; Requires that array-buffer-line and array-buffer-column be current. |
180 | 102 (setq array-row (or a-row (array-current-row)) |
103 array-column (or a-column (array-current-column)))) | |
104 | |
105 (defun array-update-buffer-position () | |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
106 "Set `array-buffer-line' and `array-buffer-column' to their current values." |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
107 (setq array-buffer-line (current-line) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
108 array-buffer-column (current-column))) |
180 | 109 |
110 | |
111 | |
112 ;;; Information commands. | |
113 | |
114 (defun array-what-position () | |
115 "Display the row and column in which the cursor is positioned." | |
116 (interactive) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
117 (let ((array-buffer-line (current-line)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
118 (array-buffer-column (current-column))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
119 (message "Array row: %s Array column: %s" |
14338
0f8f00733165
(array-what-position): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
120 (prin1-to-string (array-current-row)) |
0f8f00733165
(array-what-position): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
121 (prin1-to-string (array-current-column))))) |
180 | 122 |
123 (defun array-display-local-variables () | |
124 "Display the current state of the local variables in the minibuffer." | |
125 (interactive) | |
126 (let ((buf (buffer-name (current-buffer)))) | |
127 (with-output-to-temp-buffer "*Local Variables*" | |
128 (buffer-disable-undo standard-output) | |
129 (terpri) | |
130 (princ (format " Buffer: %s\n\n" buf)) | |
131 (princ (format " max-row: %s\n" | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
132 (prin1-to-string array-max-row))) |
180 | 133 (princ (format " max-column: %s\n" |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
134 (prin1-to-string array-max-column))) |
180 | 135 (princ (format " columns-per-line: %s\n" |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
136 (prin1-to-string array-columns-per-line))) |
180 | 137 (princ (format " field-width: %s\n" |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
138 (prin1-to-string array-field-width))) |
180 | 139 (princ (format " rows-numbered: %s\n" |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
140 (prin1-to-string array-rows-numbered))) |
180 | 141 (princ (format " lines-per-row: %s\n" |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
142 (prin1-to-string array-lines-per-row))) |
180 | 143 (princ (format " line-length: %s\n" |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
144 (prin1-to-string array-line-length)))))) |
180 | 145 |
146 | |
147 | |
148 ;;; Internal movement functions. | |
149 | |
150 (defun array-beginning-of-field (&optional go-there) | |
151 "Return the column of the beginning of the current field. | |
152 Optional argument GO-THERE, if non-nil, means go there too." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
153 ;; Requires that array-buffer-column be current. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
154 (let ((goal-column (- array-buffer-column (% array-buffer-column array-field-width)))) |
180 | 155 (if go-there |
156 (move-to-column-untabify goal-column) | |
157 goal-column))) | |
158 | |
159 (defun array-end-of-field (&optional go-there) | |
160 "Return the column of the end of the current array field. | |
161 If optional argument GO-THERE is non-nil, go there too." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
162 ;; Requires that array-buffer-column be current. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
163 (let ((goal-column (+ (- array-buffer-column (% array-buffer-column array-field-width)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
164 array-field-width))) |
180 | 165 (if go-there |
166 (move-to-column-untabify goal-column) | |
167 goal-column))) | |
168 | |
169 (defun array-move-to-cell (a-row a-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
170 "Move to array row A-ROW and array column A-COLUMN. |
180 | 171 Leave point at the beginning of the field and return the new buffer column." |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
172 (let ((goal-line (+ (* array-lines-per-row (1- a-row)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
173 (if array-rows-numbered 1 0) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
174 (floor (1- a-column) array-columns-per-line))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
175 (goal-column (* array-field-width (% (1- a-column) array-columns-per-line)))) |
180 | 176 (goto-char (point-min)) |
177 (forward-line goal-line) | |
178 (move-to-column-untabify goal-column))) | |
179 | |
180 (defun array-move-to-row (a-row) | |
181 "Move to array row A-ROW preserving the current array column. | |
182 Leave point at the beginning of the field and return the new array row." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
183 ;; Requires that array-buffer-line and array-buffer-column be current. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
184 (let ((goal-line (+ (* array-lines-per-row (1- a-row)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
185 (% array-buffer-line array-lines-per-row))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
186 (goal-column (- array-buffer-column (% array-buffer-column array-field-width)))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
187 (forward-line (- goal-line array-buffer-line)) |
180 | 188 (move-to-column-untabify goal-column) |
189 a-row)) | |
190 | |
191 (defun array-move-to-column (a-column) | |
192 "Move to array column A-COLUMN preserving the current array row. | |
193 Leave point at the beginning of the field and return the new array column." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
194 ;; Requires that array-buffer-line and array-buffer-column be current. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
195 (let ((goal-line (+ (- array-buffer-line (% array-buffer-line array-lines-per-row)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
196 (if array-rows-numbered 1 0) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
197 (floor (1- a-column) array-columns-per-line))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
198 (goal-column (* array-field-width (% (1- a-column) array-columns-per-line)))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
199 (forward-line (- goal-line array-buffer-line)) |
180 | 200 (move-to-column-untabify goal-column) |
201 a-column)) | |
202 | |
203 (defun array-move-one-row (sign) | |
204 "Move one array row in direction SIGN (1 or -1). | |
205 Leave point at the beginning of the field and return the new array row. | |
206 If requested to move beyond the array bounds, signal an error." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
207 ;; Requires that array-buffer-line and array-buffer-column be current. |
180 | 208 (let ((goal-column (array-beginning-of-field)) |
209 (array-row (or (array-current-row) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
210 (error "Cursor is not in a valid array cell")))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
211 (cond ((and (= array-row array-max-row) (= sign 1)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
212 (error "End of array")) |
180 | 213 ((and (= array-row 1) (= sign -1)) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
214 (error "Beginning of array")) |
180 | 215 (t |
216 (progn | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
217 (forward-line (* sign array-lines-per-row)) |
180 | 218 (move-to-column-untabify goal-column) |
219 (+ array-row sign)))))) | |
220 | |
221 (defun array-move-one-column (sign) | |
222 "Move one array column in direction SIGN (1 or -1). | |
223 Leave point at the beginning of the field and return the new array column. | |
224 If requested to move beyond the array bounds, signal an error." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
225 ;; Requires that array-buffer-line and array-buffer-column be current. |
180 | 226 (let ((array-column (or (array-current-column) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
227 (error "Cursor is not in a valid array cell")))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
228 (cond ((and (= array-column array-max-column) (= sign 1)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
229 (error "End of array")) |
180 | 230 ((and (= array-column 1) (= sign -1)) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
231 (error "Beginning of array")) |
180 | 232 (t |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
233 (cond |
180 | 234 ;; Going backward from first column on the line. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
235 ((and (= sign -1) (= 1 (% array-column array-columns-per-line))) |
180 | 236 (forward-line -1) |
237 (move-to-column-untabify | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
238 (* array-field-width (1- array-columns-per-line)))) |
180 | 239 ;; Going forward from last column on the line. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
240 ((and (= sign 1) (zerop (% array-column array-columns-per-line))) |
180 | 241 (forward-line 1)) |
242 ;; Somewhere in the middle of the line. | |
243 (t | |
244 (move-to-column-untabify (+ (array-beginning-of-field) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
245 (* array-field-width sign))))) |
180 | 246 (+ array-column sign))))) |
247 | |
248 (defun array-normalize-cursor () | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
249 "Move the cursor to the first non-whitespace character in the field. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
250 If necessary, scroll horizontally to keep the cursor in view." |
180 | 251 ;; Assumes point is at the beginning of the field. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
252 (let ((array-buffer-column (current-column))) |
180 | 253 (skip-chars-forward " \t" |
254 (1- (save-excursion (array-end-of-field t) (point)))) | |
255 (array-maybe-scroll-horizontally))) | |
256 | |
257 (defun array-maybe-scroll-horizontally () | |
258 "If necessary, scroll horizontally to keep the cursor in view." | |
259 ;; This is only called from array-normalize-cursor so | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
260 ;; array-buffer-column will always be current. |
180 | 261 (let ((w-hscroll (window-hscroll)) |
262 (w-width (window-width))) | |
263 (cond | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
264 ((and (>= array-buffer-column w-hscroll) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
265 (<= array-buffer-column (+ w-hscroll w-width))) |
180 | 266 ;; It's already visible. Do nothing. |
267 nil) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
268 ((> array-buffer-column (+ w-hscroll w-width)) |
180 | 269 ;; It's to the right. Scroll left. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
270 (scroll-left (- (- array-buffer-column w-hscroll) |
180 | 271 (/ w-width 2)))) |
272 (t | |
273 ;; It's to the left. Scroll right. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
274 (scroll-right (+ (- w-hscroll array-buffer-column) |
180 | 275 (/ w-width 2))))))) |
276 | |
277 | |
278 | |
279 ;;; Movement commands. | |
280 | |
281 (defun array-next-row (&optional arg) | |
282 "Move down one array row, staying in the current array column. | |
283 If optional ARG is given, move down ARG array rows." | |
284 (interactive "p") | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
285 (let ((array-buffer-line (current-line)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
286 (array-buffer-column (current-column))) |
180 | 287 (if (= (abs arg) 1) |
288 (array-move-one-row arg) | |
289 (array-move-to-row | |
290 (limit-index (+ (or (array-current-row) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
291 (error "Cursor is not in an array cell")) |
180 | 292 arg) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
293 array-max-row)))) |
180 | 294 (array-normalize-cursor)) |
295 | |
296 (defun array-previous-row (&optional arg) | |
297 "Move up one array row, staying in the current array column. | |
298 If optional ARG is given, move up ARG array rows." | |
299 (interactive "p") | |
300 (array-next-row (- arg))) | |
301 | |
302 (defun array-forward-column (&optional arg) | |
303 "Move forward one field, staying in the current array row. | |
304 If optional ARG is given, move forward ARG array columns. | |
305 If necessary, keep the cursor in the window by scrolling right or left." | |
306 (interactive "p") | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
307 (let ((array-buffer-line (current-line)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
308 (array-buffer-column (current-column))) |
180 | 309 (if (= (abs arg) 1) |
310 (array-move-one-column arg) | |
311 (array-move-to-column | |
312 (limit-index (+ (or (array-current-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
313 (error "Cursor is not in an array cell")) |
180 | 314 arg) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
315 array-max-column)))) |
180 | 316 (array-normalize-cursor)) |
317 | |
318 (defun array-backward-column (&optional arg) | |
319 "Move backward one field, staying in the current array row. | |
320 If optional ARG is given, move backward ARG array columns. | |
321 If necessary, keep the cursor in the window by scrolling right or left." | |
322 (interactive "p") | |
323 (array-forward-column (- arg))) | |
324 | |
325 (defun array-goto-cell (a-row a-column) | |
326 "Go to array row A-ROW and array column A-COLUMN." | |
327 (interactive "nArray row: \nnArray column: ") | |
328 (array-move-to-cell | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
329 (limit-index a-row array-max-row) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
330 (limit-index a-column array-max-column)) |
180 | 331 (array-normalize-cursor)) |
332 | |
333 | |
334 | |
335 ;;; Internal copying functions. | |
336 | |
337 (defun array-field-string () | |
338 "Return the field string at the current cursor location." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
339 ;; Requires that array-buffer-column be current. |
180 | 340 (buffer-substring |
341 (save-excursion (array-beginning-of-field t) (point)) | |
342 (save-excursion (array-end-of-field t) (point)))) | |
343 | |
344 (defun array-copy-once-vertically (sign) | |
345 "Copy the current field into one array row in direction SIGN (1 or -1). | |
346 Leave point at the beginning of the field and return the new array row. | |
347 If requested to move beyond the array bounds, signal an error." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
348 ;; Requires that array-buffer-line, array-buffer-column, and array-copy-string be current. |
180 | 349 (let ((a-row (array-move-one-row sign))) |
350 (let ((inhibit-quit t)) | |
351 (delete-region (point) (save-excursion (array-end-of-field t) (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
352 (insert array-copy-string)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
353 (move-to-column array-buffer-column) |
180 | 354 a-row)) |
355 | |
356 (defun array-copy-once-horizontally (sign) | |
357 "Copy the current field into one array column in direction SIGN (1 or -1). | |
358 Leave point at the beginning of the field and return the new array column. | |
359 If requested to move beyond the array bounds, signal an error." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
360 ;; Requires that array-buffer-line, array-buffer-column, and array-copy-string be current. |
180 | 361 (let ((a-column (array-move-one-column sign))) |
362 (array-update-buffer-position) | |
363 (let ((inhibit-quit t)) | |
364 (delete-region (point) (save-excursion (array-end-of-field t) (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
365 (insert array-copy-string)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
366 (move-to-column array-buffer-column) |
180 | 367 a-column)) |
368 | |
369 (defun array-copy-to-row (a-row) | |
370 "Copy the current field vertically into every cell up to and including A-ROW. | |
371 Leave point at the beginning of the field." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
372 ;; Requires that array-buffer-line, array-buffer-column, array-row, and |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
373 ;; array-copy-string be current. |
180 | 374 (let* ((num (- a-row array-row)) |
375 (count (abs num)) | |
376 (sign (if (zerop count) () (/ num count)))) | |
377 (while (> count 0) | |
378 (array-move-one-row sign) | |
379 (array-update-buffer-position) | |
380 (let ((inhibit-quit t)) | |
381 (delete-region (point) (save-excursion (array-end-of-field t) (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
382 (insert array-copy-string)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
383 (move-to-column array-buffer-column) |
180 | 384 (setq count (1- count))))) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42704
diff
changeset
|
385 |
180 | 386 (defun array-copy-to-column (a-column) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
387 "Copy current field horizontally into every cell up to and including A-COLUMN. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
388 Leave point at the beginning of the field." |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
389 ;; Requires that array-buffer-line, array-buffer-column, array-column, and |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
390 ;; array-copy-string be current. |
180 | 391 (let* ((num (- a-column array-column)) |
392 (count (abs num)) | |
393 (sign (if (zerop count) () (/ num count)))) | |
394 (while (> count 0) | |
395 (array-move-one-column sign) | |
396 (array-update-buffer-position) | |
397 (let ((inhibit-quit t)) | |
398 (delete-region (point) (save-excursion (array-end-of-field t) (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
399 (insert array-copy-string)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
400 (move-to-column array-buffer-column) |
180 | 401 (setq count (1- count))))) |
402 | |
403 (defun array-copy-to-cell (a-row a-column) | |
404 "Copy the current field into the cell at A-ROW, A-COLUMN. | |
405 Leave point at the beginning of the field." | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
406 ;; Requires that array-copy-string be current. |
180 | 407 (array-move-to-cell a-row a-column) |
408 (array-update-buffer-position) | |
409 (delete-region (point) (save-excursion (array-end-of-field t) (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
410 (insert array-copy-string) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
411 (move-to-column array-buffer-column)) |
180 | 412 |
413 | |
414 | |
415 ;;; Commands for copying. | |
416 | |
417 (defun array-copy-down (&optional arg) | |
418 "Copy the current field one array row down. | |
419 If optional ARG is given, copy down through ARG array rows." | |
420 (interactive "p") | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
421 (let* ((array-buffer-line (current-line)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
422 (array-buffer-column (current-column)) |
180 | 423 (array-row (or (array-current-row) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
424 (error "Cursor is not in a valid array cell"))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
425 (array-copy-string (array-field-string))) |
180 | 426 (if (= (abs arg) 1) |
427 (array-copy-once-vertically arg) | |
428 (array-copy-to-row | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
429 (limit-index (+ array-row arg) array-max-row)))) |
180 | 430 (array-normalize-cursor)) |
431 | |
432 (defun array-copy-up (&optional arg) | |
433 "Copy the current field one array row up. | |
434 If optional ARG is given, copy up through ARG array rows." | |
435 (interactive "p") | |
436 (array-copy-down (- arg))) | |
437 | |
438 (defun array-copy-forward (&optional arg) | |
439 "Copy the current field one array column to the right. | |
440 If optional ARG is given, copy through ARG array columns to the right." | |
441 (interactive "p") | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
442 (let* ((array-buffer-line (current-line)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
443 (array-buffer-column (current-column)) |
180 | 444 (array-column (or (array-current-column) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
445 (error "Cursor is not in a valid array cell"))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
446 (array-copy-string (array-field-string))) |
180 | 447 (if (= (abs arg) 1) |
448 (array-copy-once-horizontally arg) | |
449 (array-copy-to-column | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
450 (limit-index (+ array-column arg) array-max-column)))) |
180 | 451 (array-normalize-cursor)) |
452 | |
453 (defun array-copy-backward (&optional arg) | |
454 "Copy the current field one array column to the left. | |
455 If optional ARG is given, copy through ARG array columns to the left." | |
456 (interactive "p") | |
457 (array-copy-forward (- arg))) | |
458 | |
459 (defun array-copy-column-forward (&optional arg) | |
460 "Copy the entire current column in to the column to the right. | |
461 If optional ARG is given, copy through ARG array columns to the right." | |
462 (interactive "p") | |
463 (array-update-buffer-position) | |
464 (array-update-array-position) | |
465 (if (not array-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
466 (error "Cursor is not in a valid array cell")) |
180 | 467 (message "Working...") |
468 (let ((this-row 0)) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
469 (while (< this-row array-max-row) |
180 | 470 (setq this-row (1+ this-row)) |
471 (array-move-to-cell this-row array-column) | |
472 (array-update-buffer-position) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
473 (let ((array-copy-string (array-field-string))) |
180 | 474 (if (= (abs arg) 1) |
475 (array-copy-once-horizontally arg) | |
476 (array-copy-to-column | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
477 (limit-index (+ array-column arg) array-max-column)))))) |
180 | 478 (message "Working...done") |
479 (array-move-to-row array-row) | |
480 (array-normalize-cursor)) | |
481 | |
482 (defun array-copy-column-backward (&optional arg) | |
483 "Copy the entire current column one column to the left. | |
484 If optional ARG is given, copy through ARG columns to the left." | |
485 (interactive "p") | |
486 (array-copy-column-forward (- arg))) | |
487 | |
488 (defun array-copy-row-down (&optional arg) | |
489 "Copy the entire current row one row down. | |
490 If optional ARG is given, copy through ARG rows down." | |
491 (interactive "p") | |
492 (array-update-buffer-position) | |
493 (array-update-array-position) | |
494 (if (not array-row) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
495 (error "Cursor is not in a valid array cell")) |
180 | 496 (cond |
497 ((and (= array-row 1) (= arg -1)) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
498 (error "Beginning of array")) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
499 ((and (= array-row array-max-row) (= arg 1)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
500 (error "End of array")) |
180 | 501 (t |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
502 (let* ((array-copy-string |
180 | 503 (buffer-substring |
504 (save-excursion (array-move-to-cell array-row 1) | |
505 (point)) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
506 (save-excursion (array-move-to-cell array-row array-max-column) |
180 | 507 (forward-line 1) |
508 (point)))) | |
509 (this-row array-row) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
510 (goal-row (limit-index (+ this-row arg) array-max-row)) |
180 | 511 (num (- goal-row this-row)) |
512 (count (abs num)) | |
513 (sign (if (not (zerop count)) (/ num count)))) | |
514 (while (> count 0) | |
515 (setq this-row (+ this-row sign)) | |
516 (array-move-to-cell this-row 1) | |
517 (let ((inhibit-quit t)) | |
518 (delete-region (point) | |
519 (save-excursion | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
520 (array-move-to-cell this-row array-max-column) |
180 | 521 (forward-line 1) |
522 (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
523 (insert array-copy-string)) |
180 | 524 (setq count (1- count))) |
525 (array-move-to-cell goal-row (or array-column 1))))) | |
526 (array-normalize-cursor)) | |
527 | |
528 (defun array-copy-row-up (&optional arg) | |
529 "Copy the entire current array row into the row above. | |
530 If optional ARG is given, copy through ARG rows up." | |
531 (interactive "p") | |
532 (array-copy-row-down (- arg))) | |
533 | |
534 (defun array-fill-rectangle () | |
535 "Copy the field at mark into every cell between mark and point." | |
536 (interactive) | |
537 ;; Bind arguments. | |
538 (array-update-buffer-position) | |
539 (let ((p-row (or (array-current-row) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
540 (error "Cursor is not in a valid array cell"))) |
180 | 541 (p-column (or (array-current-column) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
542 (error "Cursor is not in a valid array cell"))) |
180 | 543 (m-row |
544 (save-excursion | |
545 (exchange-point-and-mark) | |
546 (array-update-buffer-position) | |
547 (or (array-current-row) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
548 (error "Mark is not in a valid array cell")))) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
549 (m-column |
180 | 550 (save-excursion |
551 (exchange-point-and-mark) | |
552 (array-update-buffer-position) | |
553 (or (array-current-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
554 (error "Mark is not in a valid array cell"))))) |
180 | 555 (message "Working...") |
556 (let ((top-row (min m-row p-row)) | |
557 (bottom-row (max m-row p-row)) | |
558 (left-column (min m-column p-column)) | |
559 (right-column (max m-column p-column))) | |
560 ;; Do the first row. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
561 (let ((array-copy-string |
180 | 562 (save-excursion |
563 (array-move-to-cell m-row m-column) | |
564 (array-update-buffer-position) | |
565 (array-field-string)))) | |
566 (array-copy-to-cell top-row left-column) | |
567 (array-update-array-position top-row left-column) | |
568 (array-update-buffer-position) | |
569 (array-copy-to-column right-column)) | |
570 ;; Do the rest of the rows. | |
571 (array-move-to-cell top-row left-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
572 (let ((array-copy-string |
180 | 573 (buffer-substring |
574 (point) | |
575 (save-excursion | |
576 (array-move-to-cell top-row right-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
577 (setq array-buffer-column (current-column)) |
180 | 578 (array-end-of-field t) |
579 (point)))) | |
580 (this-row top-row)) | |
581 (while (/= this-row bottom-row) | |
582 (setq this-row (1+ this-row)) | |
583 (array-move-to-cell this-row left-column) | |
584 (let ((inhibit-quit t)) | |
585 (delete-region | |
586 (point) | |
587 (save-excursion | |
588 (array-move-to-cell this-row right-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
589 (setq array-buffer-column (current-column)) |
180 | 590 (array-end-of-field t) |
591 (point))) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
592 (insert array-copy-string))))) |
180 | 593 (message "Working...done") |
594 (array-goto-cell p-row p-column))) | |
595 | |
596 | |
597 | |
598 ;;; Reconfiguration of the array. | |
599 | |
600 (defun array-make-template () | |
601 "Create the template of an array." | |
602 (interactive) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
603 ;; If there is a conflict between array-field-width and init-string, resolve it. |
180 | 604 (let ((check t) |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
605 (len) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
606 init-field) |
180 | 607 (while check |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
608 (setq init-field (read-string "Initial field value: ")) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
609 (setq len (length init-field)) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
610 (if (/= len array-field-width) |
180 | 611 (if (y-or-n-p (format "Change field width to %d? " len)) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
612 (progn (setq array-field-width len) |
180 | 613 (setq check nil))) |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
614 (setq check nil))) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
615 (goto-char (point-min)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
616 (message "Working...") |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
617 (let ((this-row 1)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
618 ;; Loop through the rows. |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
619 (while (<= this-row array-max-row) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
620 (if array-rows-numbered |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
621 (insert (format "%d:\n" this-row))) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
622 (let ((this-column 1)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
623 ;; Loop through the columns. |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
624 (while (<= this-column array-max-column) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
625 (insert init-field) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
626 (if (and (zerop (% this-column array-columns-per-line)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
627 (/= this-column array-max-column)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
628 (newline)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
629 (setq this-column (1+ this-column)))) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
630 (setq this-row (1+ this-row)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
631 (newline))) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
632 (message "Working...done")) |
180 | 633 (array-goto-cell 1 1)) |
634 | |
635 (defun array-reconfigure-rows (new-columns-per-line new-rows-numbered) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
636 "Reconfigure the state of `array-rows-numbered' and `array-columns-per-line'. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
637 NEW-COLUMNS-PER-LINE is the desired value of `array-columns-per-line' and |
180 | 638 NEW-ROWS-NUMBERED (a character, either ?y or ?n) is the desired value |
64429
dd1d759e63db
(array-mode, array-reconfigure-rows, untabify-backward): Fix typos in
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
639 of `array-rows-numbered'." |
180 | 640 (interactive "nColumns per line: \ncRows numbered? (y or n) ") |
641 ;; Check on new-columns-per-line | |
642 (let ((check t)) | |
643 (while check | |
644 (if (and (>= new-columns-per-line 1) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
645 (<= new-columns-per-line array-max-column)) |
180 | 646 (setq check nil) |
647 (setq new-columns-per-line | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
648 (string-to-number |
62458
2c228409c44d
Replace `read-input' by `read-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62402
diff
changeset
|
649 (read-string |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
650 (format "Columns per line (1 - %d): " array-max-column))))))) |
180 | 651 ;; Check on new-rows-numbered. It has to be done this way |
652 ;; because interactive does not have y-or-n-p. | |
653 (cond | |
654 ((eq new-rows-numbered ?y) | |
655 (setq new-rows-numbered t)) | |
656 ((eq new-rows-numbered ?n) | |
657 (setq new-rows-numbered nil)) | |
658 (t | |
659 (setq new-rows-numbered (y-or-n-p "Rows numbered? ")))) | |
660 (message "Working...") | |
661 (array-update-buffer-position) | |
662 (let* ((main-buffer (buffer-name (current-buffer))) | |
25428
4caa1d53d0e4
(array-reconfigure-rows): Use generate-new-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
25226
diff
changeset
|
663 (temp-buffer (generate-new-buffer " *Array*")) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
664 (temp-max-row array-max-row) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
665 (temp-max-column array-max-column) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
666 (old-rows-numbered array-rows-numbered) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
667 (old-columns-per-line array-columns-per-line) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
668 (old-lines-per-row array-lines-per-row) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
669 (old-field-width array-field-width) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
670 (old-line-length array-line-length) |
180 | 671 (this-row 1)) |
672 (array-update-array-position) | |
673 ;; Do the cutting in a temporary buffer. | |
674 (copy-to-buffer temp-buffer (point-min) (point-max)) | |
675 (set-buffer temp-buffer) | |
676 (goto-char (point-min)) | |
677 (while (<= this-row temp-max-row) | |
678 ;; Deal with row number. | |
679 (cond | |
680 ((or (and old-rows-numbered new-rows-numbered) | |
681 (and (not old-rows-numbered) (not new-rows-numbered))) | |
682 ;; Nothing is changed. | |
683 ()) | |
684 ((and old-rows-numbered (not new-rows-numbered)) | |
685 ;; Delete the row number. | |
686 (kill-line 1)) | |
687 (t | |
688 ;; Add the row number. | |
41567
37ca208c68f0
(array-reconfigure-rows): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents:
38412
diff
changeset
|
689 (insert (format "%d:\n" this-row)))) |
180 | 690 ;; Deal with the array columns in this row. |
691 (cond | |
692 ((= old-columns-per-line new-columns-per-line) | |
693 ;; Nothing is changed. Go to the next row. | |
694 (forward-line (- old-lines-per-row (if old-rows-numbered 1 0)))) | |
695 (t | |
696 ;; First expand the row. Then cut it up into new pieces. | |
697 (let ((newlines-to-be-removed | |
698 (floor (1- temp-max-column) old-columns-per-line)) | |
699 (newlines-removed 0) | |
700 (newlines-to-be-added | |
701 (floor (1- temp-max-column) new-columns-per-line)) | |
702 (newlines-added 0)) | |
703 (while (< newlines-removed newlines-to-be-removed) | |
704 (move-to-column-untabify | |
705 (* (1+ newlines-removed) old-line-length)) | |
706 (kill-line 1) | |
707 (setq newlines-removed (1+ newlines-removed))) | |
708 (beginning-of-line) | |
709 (while (< newlines-added newlines-to-be-added) | |
710 (move-to-column-untabify (* old-field-width new-columns-per-line)) | |
711 (newline) | |
712 (setq newlines-added (1+ newlines-added))) | |
713 (forward-line 1)))) | |
714 (setq this-row (1+ this-row))) | |
715 (let ((inhibit-quit t)) | |
716 (set-buffer main-buffer) | |
717 (erase-buffer) | |
64429
dd1d759e63db
(array-mode, array-reconfigure-rows, untabify-backward): Fix typos in
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
718 (insert-buffer-substring temp-buffer) |
180 | 719 ;; Update local variables. |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
720 (setq array-columns-per-line new-columns-per-line) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
721 (setq array-rows-numbered new-rows-numbered) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
722 (setq array-line-length (* old-field-width new-columns-per-line)) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
723 (setq array-lines-per-row |
4514
e64f012944e0
(abs, ceiling, floor): Remove, since they now redefine
Paul Eggert <eggert@twinsun.com>
parents:
2307
diff
changeset
|
724 (+ (floor (1- temp-max-column) new-columns-per-line) |
e64f012944e0
(abs, ceiling, floor): Remove, since they now redefine
Paul Eggert <eggert@twinsun.com>
parents:
2307
diff
changeset
|
725 (if new-rows-numbered 2 1))) |
180 | 726 (array-goto-cell (or array-row 1) (or array-column 1))) |
727 (kill-buffer temp-buffer)) | |
728 (message "Working...done")) | |
729 | |
730 (defun array-expand-rows () | |
731 "Expand the rows so each fits on one line and remove row numbers." | |
732 (interactive) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
733 (array-reconfigure-rows array-max-column ?n)) |
180 | 734 |
735 | |
736 | |
737 ;;; Utilities. | |
738 | |
739 (defun limit-index (index limit) | |
740 (cond ((< index 1) 1) | |
741 ((> index limit) limit) | |
742 (t index))) | |
743 | |
744 (defun xor (pred1 pred2) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
745 "Return the logical exclusive or of predicates PRED1 and PRED2." |
180 | 746 (and (or pred1 pred2) |
747 (not (and pred1 pred2)))) | |
748 | |
749 (defun current-line () | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
750 "Return the current buffer line at point. The first line is 0." |
180 | 751 (save-excursion |
752 (beginning-of-line) | |
753 (count-lines (point-min) (point)))) | |
754 | |
755 (defun move-to-column-untabify (column) | |
756 "Move to COLUMN on the current line, untabifying if necessary. | |
757 Return COLUMN." | |
758 (or (and (= column (move-to-column column)) | |
759 column) | |
760 ;; There is a tab in the way. | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
761 (if array-respect-tabs |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
762 (error "There is a TAB character in the way") |
180 | 763 (progn |
764 (untabify-backward) | |
765 (move-to-column column))))) | |
766 | |
767 (defun untabify-backward () | |
64429
dd1d759e63db
(array-mode, array-reconfigure-rows, untabify-backward): Fix typos in
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
768 "Untabify the preceding TAB." |
180 | 769 (save-excursion |
770 (let ((start (point))) | |
771 (backward-char 1) | |
772 (untabify (point) start)))) | |
773 | |
774 | |
775 | |
776 ;;; Array mode. | |
777 | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
778 (defvar array-mode-map nil |
180 | 779 "Keymap used in array mode.") |
780 | |
781 (if array-mode-map | |
782 () | |
783 (setq array-mode-map (make-keymap)) | |
784 ;; Bind keys. | |
785 (define-key array-mode-map "\M-ad" 'array-display-local-variables) | |
786 (define-key array-mode-map "\M-am" 'array-make-template) | |
787 (define-key array-mode-map "\M-ae" 'array-expand-rows) | |
788 (define-key array-mode-map "\M-ar" 'array-reconfigure-rows) | |
789 (define-key array-mode-map "\M-a=" 'array-what-position) | |
790 (define-key array-mode-map "\M-ag" 'array-goto-cell) | |
791 (define-key array-mode-map "\M-af" 'array-fill-rectangle) | |
792 (define-key array-mode-map "\C-n" 'array-next-row) | |
793 (define-key array-mode-map "\C-p" 'array-previous-row) | |
794 (define-key array-mode-map "\C-f" 'array-forward-column) | |
795 (define-key array-mode-map "\C-b" 'array-backward-column) | |
796 (define-key array-mode-map "\M-n" 'array-copy-down) | |
797 (define-key array-mode-map "\M-p" 'array-copy-up) | |
798 (define-key array-mode-map "\M-f" 'array-copy-forward) | |
799 (define-key array-mode-map "\M-b" 'array-copy-backward) | |
800 (define-key array-mode-map "\M-\C-n" 'array-copy-row-down) | |
801 (define-key array-mode-map "\M-\C-p" 'array-copy-row-up) | |
802 (define-key array-mode-map "\M-\C-f" 'array-copy-column-forward) | |
803 (define-key array-mode-map "\M-\C-b" 'array-copy-column-backward)) | |
804 | |
805 (put 'array-mode 'mode-class 'special) | |
806 | |
21631
e9650ae37732
(array-mode): Add autoload cookie.
Dave Love <fx@gnu.org>
parents:
14338
diff
changeset
|
807 ;;;###autoload |
180 | 808 (defun array-mode () |
809 "Major mode for editing arrays. | |
810 | |
811 Array mode is a specialized mode for editing arrays. An array is | |
812 considered to be a two-dimensional set of strings. The strings are | |
813 NOT recognized as integers or real numbers. | |
814 | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
815 The array MUST reside at the top of the buffer. |
180 | 816 |
817 TABs are not respected, and may be converted into spaces at any time. | |
64429
dd1d759e63db
(array-mode, array-reconfigure-rows, untabify-backward): Fix typos in
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
818 Setting the variable `array-respect-tabs' to non-nil will prevent TAB conversion, |
180 | 819 but will cause many functions to give errors if they encounter one. |
820 | |
821 Upon entering array mode, you will be prompted for the values of | |
822 several variables. Others will be calculated based on the values you | |
42704 | 823 supply. These variables are all local to the buffer. Other buffer |
180 | 824 in array mode may have different values assigned to the variables. |
825 The variables are: | |
826 | |
827 Variables you assign: | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
828 array-max-row: The number of rows in the array. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
829 array-max-column: The number of columns in the array. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
830 array-columns-per-line: The number of columns in the array per line of buffer. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
831 array-field-width: The width of each field, in characters. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
832 array-rows-numbered: A logical variable describing whether to ignore |
180 | 833 row numbers in the buffer. |
834 | |
835 Variables which are calculated: | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
836 array-line-length: The number of characters in a buffer line. |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
837 array-lines-per-row: The number of buffer lines used to display each row. |
180 | 838 |
839 The following commands are available (an asterisk indicates it may | |
840 take a numeric prefix argument): | |
841 | |
842 * \\<array-mode-map>\\[array-forward-column] Move forward one column. | |
843 * \\[array-backward-column] Move backward one column. | |
844 * \\[array-next-row] Move down one row. | |
845 * \\[array-previous-row] Move up one row. | |
846 | |
847 * \\[array-copy-forward] Copy the current field into the column to the right. | |
848 * \\[array-copy-backward] Copy the current field into the column to the left. | |
849 * \\[array-copy-down] Copy the current field into the row below. | |
850 * \\[array-copy-up] Copy the current field into the row above. | |
851 | |
852 * \\[array-copy-column-forward] Copy the current column into the column to the right. | |
853 * \\[array-copy-column-backward] Copy the current column into the column to the left. | |
854 * \\[array-copy-row-down] Copy the current row into the row below. | |
855 * \\[array-copy-row-up] Copy the current row into the row above. | |
856 | |
857 \\[array-fill-rectangle] Copy the field at mark into every cell with row and column | |
858 between that of point and mark. | |
859 | |
860 \\[array-what-position] Display the current array row and column. | |
861 \\[array-goto-cell] Go to a particular array cell. | |
862 | |
863 \\[array-make-template] Make a template for a new array. | |
864 \\[array-reconfigure-rows] Reconfigure the array. | |
865 \\[array-expand-rows] Expand the array (remove row numbers and | |
866 newlines inside rows) | |
867 | |
868 \\[array-display-local-variables] Display the current values of local variables. | |
869 | |
870 Entering array mode calls the function `array-mode-hook'." | |
871 | |
872 (interactive) | |
62715
d07ea6e0706b
(array-mode): Use kill-all-local-variables and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62458
diff
changeset
|
873 (kill-all-local-variables) |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
874 (make-local-variable 'array-buffer-line) |
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
875 (make-local-variable 'array-buffer-column) |
180 | 876 (make-local-variable 'array-row) |
877 (make-local-variable 'array-column) | |
27227
10ee0084db53
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
Dave Love <fx@gnu.org>
parents:
25428
diff
changeset
|
878 (make-local-variable 'array-copy-string) |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
879 (set (make-local-variable 'array-respect-tabs) nil) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
880 (set (make-local-variable 'array-max-row) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
881 (read-number "Number of array rows: ")) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
882 (set (make-local-variable 'array-max-column) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
883 (read-number "Number of array columns: ")) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
884 (set (make-local-variable 'array-columns-per-line) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
885 (read-number "Array columns per line: ")) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
886 (set (make-local-variable 'array-field-width) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
887 (read-number "Field width: ")) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
888 (set (make-local-variable 'array-rows-numbered) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
889 (y-or-n-p "Rows numbered? ")) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
890 (set (make-local-variable 'array-line-length) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
891 (* array-field-width array-columns-per-line)) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
892 (set (make-local-variable 'array-lines-per-row) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
893 (+ (floor (1- array-max-column) array-columns-per-line) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
894 (if array-rows-numbered 2 1))) |
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
895 (message "") |
180 | 896 (setq major-mode 'array-mode) |
897 (setq mode-name "Array") | |
11591
5f3aa9df448e
(array-mode): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
4514
diff
changeset
|
898 (force-mode-line-update) |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
899 (set (make-local-variable 'truncate-lines) t) |
13603
cb0d1b1782f4
(array-mode): Set overwrite-mode to overwrite-mode-textual.
Richard M. Stallman <rms@gnu.org>
parents:
11591
diff
changeset
|
900 (setq overwrite-mode 'overwrite-mode-textual) |
180 | 901 (use-local-map array-mode-map) |
62715
d07ea6e0706b
(array-mode): Use kill-all-local-variables and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62458
diff
changeset
|
902 (run-mode-hooks 'array-mode-hook)) |
180 | 903 |
904 | |
905 | |
25226 | 906 (provide 'array) |
907 | |
68249
de87ce42a058
Move defvars out of eval-when-compile.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
908 ;; arch-tag: 0086605d-79fe-4a1a-992a-456417261f80 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
180
diff
changeset
|
909 ;;; array.el ends here |