annotate lisp/array.el @ 25765:416e6af8f06a

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