annotate lisp/packages/array.el @ 100:4be1180a9e89 r20-1b2

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