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