Mercurial > emacs
annotate lisp/textmodes/two-column.el @ 8736:fe48762e68de
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 14 Sep 1994 09:05:48 +0000 |
parents | cc7cd83ccf3f |
children | 5dc02bbeb4be |
rev | line source |
---|---|
809 | 1 ;;; two-column.el --- minor mode for editing of two-column text |
2 | |
7300 | 3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc. |
840
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
809
diff
changeset
|
4 |
809 | 5 ;; Author: Daniel Pfeiffer <pfeiffer@cix.cict.fr> |
6 ;; Adapted-By: ESR | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6118
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
809 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
2373 | 26 ;; This package gives you the ability to edit text in a two-column format. |
27 | |
809 | 28 ;; --8<---- two-column.el ----8<--------8<--------8<--------8<--------8<------- |
29 ;; Esperanto: English: | |
30 | |
31 ;; Minora modalo por samtempa dukolumna Minor mode for simultaneous | |
32 ;; tajpado two-column editing | |
33 | |
34 ;; Tiu minora modalo ebligas al vi This minor mode allows you to | |
35 ;; tajpi sendepende en du apudaj independently edit two adjacent | |
36 ;; bufroj. Vi havas tri eblecojn por buffers. You have three ways to | |
37 ;; eki ^gin. ^Ciu donas al vi start it up. Each gives you a | |
38 ;; horizontale disigatan fenestron, horizontally split window similar to | |
39 ;; simila al fina apareco de via the final outcome of your text: | |
40 ;; teksto: | |
41 | |
42 ;; C-x 6 2 asocias novan bufron nomatan associates a new buffer called | |
43 ;; same, sed kun 2C/ anta^u. the same, but with 2C/ | |
44 ;; prepended. | |
45 | |
46 ;; C-x 6 b asocias alian bufron. Vi povas associates another buffer. | |
47 ;; anka^u asocii dataron, se vi This can be used to associate a | |
48 ;; ^jus anta^ue faris C-x C-f. file if you just did C-x C-f. | |
49 | |
50 ;; C-x 6 u disigas jam dukolumnan tekston unmerges a two-column text into | |
51 ;; en du bufroj ekde la nuna two buffers from the current | |
52 ;; linio, kaj je la nuna kolumno. line and at the current column. | |
53 ;; La anta^uaj signoj (ofte The preceding characters (often | |
54 ;; tabeligilo a^u |) estas la tab or |) are the column | |
55 ;; kolumna disiganto. Linioj kiuj separator. Lines that don't | |
56 ;; ne enhavas ilin ne estas have them won't be separated. | |
57 ;; disigitaj. Kiel la kvara kaj Like the fourth and fifth line | |
58 ;; la kvina linio se vi disigas if you unmerge this file from | |
59 ;; ^ci dataron ekde la unua angla the first english word. | |
60 ;; vorto. | |
61 | |
62 ;; Je ^cia flanko estas bufro, kiu On each side is a buffer that knows | |
63 ;; konas la alian. Kun la ordonoj C-x about the other. With the commands | |
64 ;; 6 SPC, C-x 6 DEL kaj C-x 6 RET oni C-x 6 SPC, C-x 6 DEL and C-x 6 RET | |
65 ;; povas suben- a^u supreniri unu you can simultaneously scroll up or | |
66 ;; ekranon, kaj subeniri linion, down by a screenfull and by a line | |
67 ;; samtempe en la du bufroj. Al la alia in both buffers. Empty lines are | |
68 ;; bufro estas aldonataj linioj se added to the other buffer if | |
69 ;; necesas, por ke vi vidu la saman necessary, so that you see the same | |
70 ;; parton. Per C-x 6 C-l vi povas part. With C-x 6 C-l you can | |
71 ;; recentrigi la linion. Kiam vi nur recenter the line. When you only | |
72 ;; plu havas unu el la du bufroj have one of the two buffers onscreen | |
73 ;; surekrane vi revidos la alian per you can get the other back with C-x | |
74 ;; denove C-x 6 2. 6 2 once more. | |
75 | |
76 ;; Se vi volas meti longajn liniojn If you include long lines, i.e which | |
77 ;; (ekz. programerojn) en la kunigotan will span both columns (eg. source | |
78 ;; tekston, ili devas esti en la code), they should be in what will | |
79 ;; estonte unua kolumno. La alia devas be the first column, with the | |
80 ;; havi malplenajn linion apud ili. associated buffer having empty lines | |
81 ;; next to them. | |
82 | |
83 ;; Averto: en Emacs kiam vi ^san^gas la Attention: in Emacs when you change | |
84 ;; ma^joran modalon, la minoraj modaloj the major mode, the minor modes are | |
85 ;; estas anka^u elmemorigitaj. Tiu- also purged from memory. In that | |
86 ;; okaze vi devas religi la du bufrojn case you must reassociate the two | |
87 ;; per iu C-x 6-ordono, ekz. C-x 6 b. buffers with any C-x 6-command, e.g. | |
88 ;; C-x 6 b. | |
89 | |
90 ;; Kiam vi estos kontenta de la When you have edited both buffers to | |
91 ;; rezulto, vi kunmetos la du kolumnojn your content, you merge them with | |
92 ;; per C-x 6 1. Se vi poste vidas C-x 6 1. If you then see a problem, | |
93 ;; problemon, vi neniigu la kunmeton you undo the merge with C-x u and | |
94 ;; per C-x u kaj plue modifu la du continue to edit the two buffers. | |
95 ;; bufrojn. Kiam vi ne plu volas tajpi When you no longer want to edit in | |
96 ;; dukolumne, vi eliru el la minora two columns, you turn off the minor | |
97 ;; modalo per C-x 6 k. mode with C-x 6 k. | |
98 | |
99 | |
100 ;; An^stata^u tri `autoload' kaj tri | Instead of three `autoload' and | |
101 ;; `global-set-key' vi povas uzi la | three `global-set-key' you can use | |
102 ;; jenon en via dataro ~/.emacs, por | the following in your file | |
6118 | 103 ;; memstare ^sar^gi la modalon: | ~/.emacs, to automatically load |
923 | 104 ;; | the mode: |
809 | 105 |
106 ;; (global-set-key "\C-x6" | |
107 ;; '(lambda () (interactive) | |
108 ;; (load-library "two-column") | |
109 ;; (call-interactively | |
110 ;; (cdr (assq (read-char) tc-mode-map))))) | |
111 | |
112 ;; Se vi ^satus havi la dukolumnajn | If you'd like to have the | |
113 ;; ordonojn je funkciklavo <f2>, vi | two-column commands on function | |
114 ;; povas uzi la jenon en via dataro | key <f2>, you can use the | |
923 | 115 ;; ~/.emacs: | following in your file ~/.emacs: |
809 | 116 |
923 | 117 ;; (global-set-key [f2] (function |
118 ;; (lambda () | |
119 ;; (interactive) | |
120 ;; (load-library "two-column") | |
121 ;; (global-set-key [f2] tc-mode-map) | |
122 ;; (call-interactively | |
123 ;; (cdr (assq (read-char) tc-mode-map)))))) | |
809 | 124 |
125 ;; In addition to two-column editing of text, for example for writing a | |
126 ;; bilingual text side-by-side as shown below in the file's prolog, other | |
127 ;; interesting uses have been found for this minor mode: | |
128 ;; | |
129 ;; | |
923 | 130 ;; You can separate the columns with {+} C-x 6 u or <f2> u if you prefer |
131 ;; any string that pleases you, by {+} handles these with a prefix argument | |
132 ;; setting tc-separator. For {+} that enables you to declare the | |
133 ;; example "{+} " if you like to {+} desired length of such a string. | |
809 | 134 ;; amuse yourself. |
135 ;; | |
136 ;; | |
137 ;; keyword You can write any text corresponding to a | |
138 ;; given keyword in a filled paragraph next to | |
139 ;; it. Note that the width of the first column | |
140 ;; may be less than window-min-width in the | |
141 ;; result, but will be displayed at that width. | |
142 ;; | |
143 ;; another This is not a three- or multi-column mode. | |
144 ;; The example in the file's prolog required | |
145 ;; working on two columns and then treating the | |
146 ;; result as one column in order to add the | |
147 ;; third. | |
148 ;; | |
149 ;; | |
150 ;; Programmers might like the ability to split off the comment column of | |
151 ;; a file that looks like the following. The advantage is that with | |
152 ;; (setq fill-prefix "-- ") you can run M-q (fill-paragraph) on the | |
153 ;; comment. The problem is, code quickly gets rather wide, so you need | |
154 ;; to use a narrower comment column, which is less interesting, unless | |
155 ;; you have a 132-column screen. Code lines that reach beyond | |
156 ;; comment-column are no problem, except that you won't always see their | |
157 ;; end during editing. | |
158 ;; | |
159 ;; BEGIN -- This is just some meaningless | |
160 ;; FOR i IN 1..10 LOOP -- code in Ada, that runs foobar | |
161 ;; foobar( i ); -- once for each argument from one | |
162 ;; END LOOP; -- to ten, and then we're already | |
163 ;; END; -- through with it. | |
164 ;; | |
165 ;; Better yet, you can put the point before "This", type M-3 C-x 6 u | |
166 ;; which makes "-- " the separator between a no-comments Ada buffer, and | |
167 ;; a plain text comment buffer. When you put them back together, every | |
168 ;; non-empty line of the 2nd column will again be preceded by "-- ". | |
169 ;; | |
170 ;; | |
171 ;; The <f2> function key hack (which is one of the rare times when | |
172 ;; function keys are mnemonic) at the end of the file's prolog requires | |
173 ;; that the lisp/term/*.el for your terminal use the standard | |
174 ;; conventions. Too bad that some don't (at least not in version 18.55). | |
175 ;; The Sun one is hopelessly non-standard, and vt2[024]0 somehow forgot | |
176 ;; to define <f1> thru <f5>. (It defines <pf1> thru <pf4> instead, but | |
177 ;; that is not what we need on an X terminal.) If you want to use those, | |
178 ;; you'll need another hack something like: | |
179 ;; | |
180 ;; (if (string= (system-name) "cix") | |
181 ;; (progn | |
182 ;; (load-library "term/vt200.el") | |
183 ;; (define-key CSI-map "12~" (cons function-keymap ?\^b))) | |
184 ;; (global-unset-key "\e[") | |
185 ;; (define-key esc-map "[225z" (cons function-keymap ?\^b))) | |
186 ;; | |
187 ;; where "cix" is the non-sun machine I use. Actually I use the same X | |
188 ;; terminal to connect to both machines, and I want to keep my ~/.emacs | |
189 ;; identical on both. Bother, the two Emacses don't recognize the same | |
190 ;; keys and assign different sequences to those they do! I sure hope all | |
191 ;; this nonsense will stop with version 19 (or preferably soon) where I'd | |
192 ;; like to be able to say (define-key some-map '<f2> some-cmd), and see | |
193 ;; <f2> rather than some unintelligible ESC-sequence in command key | |
194 ;; sequences. | |
195 | |
196 ;;; Code: | |
197 | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
198 ;;;;; Set up keymap ;;;;; |
809 | 199 |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
200 ;;;###autoload |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
201 (defvar tc-mode-map nil |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
202 "Keymap for commands for two-column mode.") |
809 | 203 |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
204 ;;;###autoload |
809 | 205 (if tc-mode-map |
206 () | |
207 (setq tc-mode-map (make-sparse-keymap)) | |
208 (define-key tc-mode-map "1" 'tc-merge) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
209 (define-key tc-mode-map "2" 'tc-two-columns) |
809 | 210 (define-key tc-mode-map "b" 'tc-associate-buffer) |
6117
5366b606f90d
(tc-mode-map): Fix binding of tc-dissociate.
Karl Heuer <kwzh@gnu.org>
parents:
2571
diff
changeset
|
211 (define-key tc-mode-map "d" 'tc-dissociate) |
809 | 212 (define-key tc-mode-map "\C-l" 'tc-recenter) |
213 (define-key tc-mode-map "o" 'tc-associated-buffer) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
214 (define-key tc-mode-map "s" 'tc-split) |
809 | 215 (define-key tc-mode-map "{" 'shrink-window-horizontally) |
216 (define-key tc-mode-map "}" 'enlarge-window-horizontally) | |
217 (define-key tc-mode-map " " 'tc-scroll-up) | |
218 (define-key tc-mode-map "\^?" 'tc-scroll-down) | |
219 (define-key tc-mode-map "\C-m" 'tc-scroll-line)) | |
220 | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
221 ;;;###autoload |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
222 (global-set-key "\C-x6" tc-mode-map) |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
223 |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
224 ;;;;; variable declarations ;;;;; |
809 | 225 |
226 ;; markers seem to be the only buffer-id not affected by renaming | |
227 ;; a buffer. This nevertheless loses when a buffer is killed. | |
228 (defvar tc-other nil | |
229 "Marker to the associated buffer, if non-nil.") | |
230 (make-variable-buffer-local 'tc-other) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
231 (put 'tc-other 'permanent-local t) |
809 | 232 |
233 (setq minor-mode-alist (cons '(tc-other " 2C") minor-mode-alist)) | |
234 | |
235 ;; rearranged, so that the pertinent info will show in 40 columns | |
236 (defvar tc-mode-line-format | |
237 '("-%*- %15b --" (-3 . "%p") "--%[(" mode-name | |
7069 | 238 minor-mode-alist mode-line-process "%n" ")%]%-") |
809 | 239 "*Value of mode-line-format for a buffer in two-column minor mode.") |
240 | |
241 (defvar tc-separator "" | |
242 "*A string inserted between the two columns when merging. | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
243 This gets set locally by \\[tc-split].") |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
244 (put 'tc-separator 'permanent-local t) |
809 | 245 |
246 (defvar tc-window-width 40 | |
247 "*The width of the first column. (Must be at least `window-min-width') | |
248 This value is local for every buffer that sets it.") | |
249 (make-variable-buffer-local 'tc-window-width) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
250 (put 'tc-window-width 'permanent-local t) |
809 | 251 |
252 (defvar tc-beyond-fill-column 4 | |
253 "*Base for calculating `fill-column' for a buffer in two-column minor mode. | |
254 The value of `fill-column' becomes `tc-window-width' for this buffer | |
255 minus this value.") | |
256 | |
257 (defvar tc-mode-hook nil | |
258 "Function called, if non-nil, whenever turning on two-column minor mode. | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
259 It can get called by \\[tc-two-columns] (tc-two-columns), \\[tc-split] (tc-split) |
809 | 260 and \\[tc-associate-buffer] (tc-associate-buffer), on both buffers.") |
261 | |
262 ;;;;; base functions ;;;;; | |
263 | |
264 ;; the access method for the other buffer. this tries to remedy against | |
265 ;; lost local variables and lost buffers. | |
266 (defun tc-other () | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
267 (if tc-other |
809 | 268 (or (prog1 |
269 (marker-buffer tc-other) | |
270 (setq mode-line-format tc-mode-line-format )) | |
271 ; The associated buffer somehow got killed. | |
272 (progn | |
273 ; The other variables may later be useful if the user | |
274 ; reestablishes the association. | |
275 (kill-local-variable 'tc-other) | |
276 (kill-local-variable 'mode-line-format) | |
277 nil)))) | |
278 | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
279 ;;;###autoload |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
280 (defun tc-two-columns (&optional buffer) |
809 | 281 "Split current window vertically for two-column editing. |
282 | |
283 When called the first time, associates a buffer with the current | |
284 buffer. Both buffers are put in two-column minor mode and | |
285 tc-mode-hook gets called on both. These buffers remember | |
286 about one another, even when renamed. | |
287 | |
288 When called again, restores the screen layout with the current buffer | |
289 first and the associated buffer to it's right. | |
290 | |
291 If you include long lines, i.e which will span both columns (eg. | |
292 source code), they should be in what will be the first column, with | |
293 the associated buffer having empty lines next to them. | |
294 | |
295 You have the following commands at your disposal: | |
296 | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
297 \\[tc-two-columns] Rearrange screen |
809 | 298 \\[tc-associate-buffer] Reassociate buffer after changing major mode |
299 \\[tc-scroll-up] Scroll both buffers up by a screenfull | |
300 \\[tc-scroll-down] Scroll both buffers down by a screenful | |
301 \\[tc-scroll-line] Scroll both buffers up by one or more lines | |
302 \\[tc-recenter] Recenter and realign other buffer | |
303 \\[shrink-window-horizontally], \\[enlarge-window-horizontally] Shrink, enlarge current column | |
304 \\[tc-associated-buffer] Switch to associated buffer | |
305 \\[tc-merge] Merge both buffers | |
306 | |
307 These keybindings can be customized in your ~/.emacs by `tc-prefix' | |
308 and `tc-mode-map'. | |
309 | |
310 The appearance of the screen can be customized by the variables | |
311 `tc-window-width', `tc-beyond-fill-column', | |
312 `tc-mode-line-format' and `truncate-partial-width-windows'." | |
313 | |
314 (interactive "P") | |
315 ; first go to full width, so that we can certainly split into | |
316 ; two windows | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
317 (if (< (window-width) (frame-width)) |
809 | 318 (enlarge-window 99999 t)) |
319 (split-window-horizontally | |
320 (max window-min-width (min tc-window-width | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
321 (- (frame-width) window-min-width)))) |
809 | 322 (if (tc-other) |
323 (progn | |
324 (other-window 1) | |
325 (switch-to-buffer (tc-other)) | |
326 (other-window -1) | |
327 ; align buffers if necessary | |
328 (tc-scroll-line 0)) | |
329 | |
330 ; set up minor mode linking two buffers | |
331 (setq fill-column (- tc-window-width | |
332 tc-beyond-fill-column) | |
333 mode-line-format tc-mode-line-format) | |
334 (run-hooks tc-mode-hook) | |
335 (let ((other (point-marker))) | |
336 (other-window 1) | |
337 (switch-to-buffer | |
338 (or buffer | |
339 (generate-new-buffer | |
340 (concat "2C/" (buffer-name))))) | |
341 (or buffer | |
342 (text-mode)) | |
343 (setq fill-column (- tc-window-width | |
344 tc-beyond-fill-column) | |
345 mode-line-format tc-mode-line-format | |
346 tc-other other | |
347 other (point-marker)) | |
348 (run-hooks tc-mode-hook) | |
349 (other-window -1) | |
350 (setq tc-other other)))) | |
351 | |
2571
b65cf676a09b
All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2549
diff
changeset
|
352 (defalias 'tc-mode 'tc-two-columns) |
809 | 353 |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
354 ;;;###autoload |
809 | 355 (defun tc-associate-buffer () |
356 "Associate another buffer with this one in two-column minor mode. | |
357 Can also be used to associate a just previously visited file, by | |
358 accepting the proposed default buffer. | |
359 | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
360 See \\[tc-two-columns] and `lisp/two-column.el' for further details." |
809 | 361 (interactive) |
362 (let ((b1 (current-buffer)) | |
363 (b2 (or (tc-other) | |
364 (read-buffer "Associate buffer: " (other-buffer))))) | |
365 (save-excursion | |
366 (setq tc-other nil) | |
367 (set-buffer b2) | |
368 (and (tc-other) | |
369 (not (eq b1 (tc-other))) | |
370 (error "Buffer already associated with buffer `%s'." | |
371 (buffer-name (tc-other)))) | |
372 (setq b1 (and (assq 'tc-window-width (buffer-local-variables)) | |
373 tc-window-width))) | |
374 ; if other buffer has a local width, adjust here too | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
375 (if b1 (setq tc-window-width (- (frame-width) b1))) |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
376 (tc-two-columns b2))) |
809 | 377 |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
378 ;;;###autoload |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
379 (defun tc-split (arg) |
809 | 380 "Unmerge a two-column text into two buffers in two-column minor mode. |
381 The text is unmerged at the cursor's column which becomes the local | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
382 value of `tc-window-width'. Only lines that have the ARG same |
809 | 383 preceding characters at that column get split. The ARG preceding |
384 characters without any leading whitespace become the local value for | |
385 `tc-separator'. This way lines that continue across both | |
386 columns remain untouched in the first buffer. | |
387 | |
388 This function can be used with a prototype line, to set up things as | |
389 you like them. You write the first line of each column with the | |
390 separator you like and then unmerge that line. E.g.: | |
391 | |
392 First column's text sSs Second columns text | |
393 \\___/\\ | |
394 / \\ | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
395 5 character Separator You type M-5 \\[tc-split] with the point here |
809 | 396 |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
397 See \\[tc-two-columns] and `lisp/two-column.el' for further details." |
809 | 398 (interactive "p") |
399 (and (tc-other) | |
400 (if (y-or-n-p (concat "Overwrite associated buffer `" | |
401 (buffer-name (tc-other)) | |
402 "'? ")) | |
403 (save-excursion | |
404 (set-buffer (tc-other)) | |
405 (erase-buffer)) | |
406 (signal 'quit nil))) | |
407 (let ((point (point)) | |
408 ; make next-line always come back to same column | |
409 (goal-column (current-column)) | |
410 ; a counter for empty lines in other buffer | |
411 (n (1- (count-lines (point-min) (point)))) | |
412 chars other) | |
413 (save-excursion | |
414 (backward-char arg) | |
415 (setq chars (buffer-substring (point) point)) | |
416 (skip-chars-forward " \t" point) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
417 (make-local-variable 'tc-separator) |
809 | 418 (setq tc-separator (buffer-substring (point) point) |
419 tc-window-width (current-column))) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
420 (tc-two-columns) |
809 | 421 (setq other (tc-other)) |
422 ; now we're ready to actually unmerge | |
423 (save-excursion | |
424 (while (not (eobp)) | |
425 (if (not (and (= (current-column) goal-column) | |
426 (string= chars | |
427 (buffer-substring (point) | |
428 (save-excursion | |
429 (backward-char arg) | |
430 (point)))))) | |
431 (setq n (1+ n)) | |
432 (setq point (point)) | |
433 (backward-char arg) | |
434 (skip-chars-backward " \t") | |
435 (delete-region point (point)) | |
436 (setq point (point)) | |
437 (insert-char ?\n n) | |
438 (append-to-buffer other point (progn (end-of-line) | |
439 (if (eobp) | |
440 (point) | |
441 (1+ (point))))) | |
442 (delete-region point (point)) | |
443 (setq n 0)) | |
444 (next-line 1))))) | |
445 | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
446 ;;;###autoload |
2549
5fbd6bdf6b6a
(tc-dissociate): Renamed from tc-kill-association.
Richard M. Stallman <rms@gnu.org>
parents:
2373
diff
changeset
|
447 (defun tc-dissociate () |
809 | 448 "Turn off two-column minor mode in current and associated buffer. |
449 If the associated buffer is unmodified and empty, it is killed." | |
450 (interactive) | |
451 (let ((buffer (current-buffer))) | |
452 (save-excursion | |
453 (and (tc-other) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
454 (set-buffer (tc-other)) |
809 | 455 (or (not (tc-other)) |
456 (eq buffer (tc-other))) | |
457 (if (and (not (buffer-modified-p)) | |
458 (eobp) (bobp)) | |
459 (kill-buffer nil) | |
460 (kill-local-variable 'tc-other) | |
461 (kill-local-variable 'tc-window-width) | |
462 (kill-local-variable 'tc-separator) | |
463 (kill-local-variable 'mode-line-format) | |
464 (kill-local-variable 'fill-column)))) | |
465 (kill-local-variable 'tc-other) | |
466 (kill-local-variable 'tc-window-width) | |
467 (kill-local-variable 'tc-separator) | |
468 (kill-local-variable 'mode-line-format) | |
469 (kill-local-variable 'fill-column))) | |
470 | |
471 | |
472 ;; this doesn't use yank-rectangle, so that the first column can | |
473 ;; contain long lines | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
474 ;;;###autoload |
809 | 475 (defun tc-merge () |
476 "Merges the associated buffer with the current buffer. | |
477 They get merged at the column, which is the value of | |
478 `tc-window-width', i.e. usually at the vertical window | |
479 separator. This separator gets replaced with white space. Beyond | |
480 that the value of gets inserted on merged lines. The two columns are | |
481 thus pasted side by side, in a single text. If the other buffer is | |
482 not displayed to the left of this one, then this one becomes the left | |
483 column. | |
484 | |
485 If you want `tc-separator' on empty lines in the second column, | |
486 you should put just one space in them. In the final result, you can strip | |
487 off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ] + $ RET RET" | |
488 | |
489 (interactive) | |
490 (or (tc-other) | |
491 (error "You must first set two-column minor mode.")) | |
492 (and (> (car (window-edges)) 0) ; not touching left edge of screen | |
493 (eq (window-buffer (previous-window)) | |
494 (tc-other)) | |
495 (other-window -1)) | |
496 (save-excursion | |
497 (let ((b1 (current-buffer)) | |
498 (b2 (tc-other)) | |
499 string) | |
500 (goto-char (point-min)) | |
501 (set-buffer b2) | |
502 (goto-char (point-min)) | |
503 (while (not (eobp)) | |
504 (setq string (buffer-substring (point) | |
505 (progn (end-of-line) (point)))) | |
506 (or (eobp) | |
507 (forward-char)) ; next line | |
508 (set-buffer b1) | |
509 (if (string= string "") | |
510 () | |
511 (end-of-line) | |
512 (indent-to-column tc-window-width) | |
513 (insert tc-separator string)) | |
514 (next-line 1) ; add one if necessary | |
515 (set-buffer b2)))) | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
516 (if (< (window-width) (frame-width)) |
809 | 517 (enlarge-window 99999 t))) |
518 | |
519 ;;;;; utility functions ;;;;; | |
520 | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
521 ;;;###autoload |
809 | 522 (defun tc-associated-buffer () |
523 "Switch to associated buffer." | |
524 (interactive) | |
525 (or (tc-other) | |
526 (error "You must set two-column minor mode.")) | |
527 (if (get-buffer-window (tc-other)) | |
528 (select-window (get-buffer-window (tc-other))) | |
529 (switch-to-buffer (tc-other)))) | |
530 | |
531 ;; It would be desirable to intercept anything that causes the current | |
532 ;; window to scroll. Maybe a `scroll-hook'? | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
533 ;;;###autoload |
809 | 534 (defun tc-scroll-line (arg) |
535 "Scroll current window upward by ARG lines. | |
536 The associated window gets scrolled to the same line." | |
537 (interactive "p") | |
538 (or (tc-other) | |
539 (error "You must set two-column minor mode.")) | |
540 ; scroll-up has a bug on arg 0 at end of buffer | |
541 (or (zerop arg) | |
542 (scroll-up arg)) | |
543 (setq arg (count-lines (point-min) (window-start))) | |
544 ; too bad that pre 18.57 Emacs makes save-window-excursion restore | |
545 ; the point. When it becomes extinct, we can simplify this. | |
546 (if (get-buffer-window (tc-other)) | |
547 (let ((window (selected-window))) | |
548 (select-window (get-buffer-window (tc-other))) | |
549 (setq arg (- arg (count-lines (point-min) (window-start)))) | |
550 ; make sure that other buffer has enough lines | |
551 (save-excursion | |
552 (goto-char (point-max)) | |
553 (insert-char ?\n | |
554 (- arg (count-lines (window-start) (point-max)) -1))) | |
555 (or (zerop arg) | |
556 (scroll-up arg)) | |
557 (select-window window)))) | |
558 | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
559 ;;;###autoload |
809 | 560 (defun tc-scroll-up (arg) |
561 "Scroll current window upward by ARG screens. | |
562 The associated window gets scrolled to the same line." | |
563 (interactive "p") | |
564 (tc-scroll-line (* arg (- (window-height) | |
565 next-screen-context-lines 1)))) | |
566 | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
567 ;;;###autoload |
809 | 568 (defun tc-scroll-down (arg) |
569 "Scroll current window downward by ARG screens. | |
570 The associated window gets scrolled to the same line." | |
571 (interactive "p") | |
572 (tc-scroll-line (* arg (- next-screen-context-lines | |
573 (window-height) -1)))) | |
574 | |
1904
cca15d76f3e5
* two-column.el: Add autoloads for the functions defined in
Jim Blandy <jimb@redhat.com>
parents:
1245
diff
changeset
|
575 ;;;###autoload |
809 | 576 (defun tc-recenter (arg) |
577 "Center point in window. With ARG, put point on line ARG. | |
578 This counts from bottom if ARG is negative. The associated window | |
579 gets scrolled to the same line." | |
580 (interactive "P") | |
581 (setq arg (and arg (prefix-numeric-value arg))) | |
582 (tc-scroll-line (- (count-lines (window-start) (point)) | |
583 (cond ((null arg) (/ (window-height) 2)) | |
584 ((< arg 0) (+ (window-height) arg)) | |
585 ( arg))))) | |
586 | |
587 (defun enlarge-window-horizontally (arg) | |
588 "Make current window ARG columns wider." | |
589 (interactive "p") | |
590 (enlarge-window arg t) | |
591 (and (tc-other) | |
592 (setq tc-window-width (+ tc-window-width arg)) | |
593 (set-buffer (tc-other)) | |
594 (setq tc-window-width (- tc-window-width arg)))) | |
595 | |
596 (defun shrink-window-horizontally (arg) | |
597 "Make current window ARG columns narrower." | |
598 (interactive "p") | |
599 (enlarge-window-horizontally (- arg))) | |
600 | |
1245
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
601 (provide 'two-column) |
f8a5da3d18e8
Use frame-width instead of screen-width.
Richard M. Stallman <rms@gnu.org>
parents:
923
diff
changeset
|
602 |
809 | 603 ;;; two-column.el ends here |