0
|
1 ;;; two-column.el --- minor mode for editing of two-column text
|
|
2
|
4
|
3 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
0
|
4
|
4
|
5 ;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
|
|
6 ;; Adapted-By: ESR, Daniel Pfeiffer
|
0
|
7
|
4
|
8 ;; Esperanto: English:
|
0
|
9
|
4
|
10 ;; ^Ci dosiero estas ero de GNU Emacs. This file is part of GNU Emacs.
|
0
|
11
|
4
|
12 ;; GNU Emacs estas libera programaro; GNU Emacs is free software; you can
|
|
13 ;; vi povas disdoni ^gin kaj/a^u modifi redistribute it and/or modify it
|
|
14 ;; ^gin sub la kondi^coj de la GNU under the terms of the GNU General
|
|
15 ;; ^Generala Publika Licenco kiel pub- Public License as published by the
|
|
16 ;; likigita far la Liberprogramara Fon- Free Software Foundation; either
|
|
17 ;; da^jo; a^u eldono 2a, a^u (la^u via version 2, or (at your option) any
|
|
18 ;; elekto) ajna posta eldono. later version.
|
0
|
19
|
4
|
20 ;; GNU Emacs estas disdonata en la GNU Emacs is distributed in the hope
|
|
21 ;; espero ke ^gi estos utila, sed SEN that it will be useful, but WITHOUT
|
|
22 ;; IA GARANTIO; sen e^c la implicita ANY WARRANTY; without even the
|
|
23 ;; garantio de VENDEBLECO a^u PRETECO implied warranty of MERCHANTABILITY
|
|
24 ;; POR DETERMINITA CELO. Vidu la GNU or FITNESS FOR A PARTICULAR PURPOSE.
|
|
25 ;; ^Generala Publika Licenco por plenaj See the GNU General Public License
|
|
26 ;; detaloj. for more details.
|
0
|
27
|
4
|
28 ;; Vi devus ricevinti kopion de la GNU You should have received a copy of
|
|
29 ;; ^Generala Publika Licenco kune kun the GNU General Public License along
|
|
30 ;; GNU Emacs; vidu la dosieron COPYING. with GNU Emacs; see the file
|
|
31 ;; Alikaze skribu al la COPYING. If not, write to the
|
|
32
|
|
33 ;; Free Software Foundation, 59 Temple Place - Suite 330
|
|
34 ;; Boston, MA 02111-1307, USA.
|
|
35
|
|
36 ;;; Synched up with: FSF 19.34.
|
|
37
|
|
38 ;;; Komentario: Commentary:
|
0
|
39
|
4
|
40 ;; Adapter's note: Don't even think of using this package. The version
|
|
41 ;; of this file in 19.14 didn't work, so I replaced it with the one in GNU
|
|
42 ;; Emacs 19.34, which didn't work either. However, from tests done with
|
|
43 ;; 19.34, it doesn't appear to run there either. At least this file is
|
|
44 ;; synched with FSF in case someone decides to fix it. -sb
|
0
|
45
|
4
|
46 ;; Tiu programaro ebligas vin redakti This package gives you the ability
|
|
47 ;; dukolumnan tekston. to edit text in a two-column format.
|
|
48
|
0
|
49
|
4
|
50 ;; Vi havas tri eblecojn por eki tiun You have three ways to start up this
|
|
51 ;; mal^cefan modalon. ^Ciu donas al vi minor mode. Each gives you a
|
|
52 ;; horizontale disigatan fenestron, si- horizontally split window similar to
|
|
53 ;; milan al fina apareco de via teksto: the final outcome of your text:
|
0
|
54
|
|
55
|
4
|
56 ;; f2 2 asocias novan bufron nomatan associates a new buffer called
|
|
57 ;; C-x 6 2 same, sed kun 2C/ anta^u. the same, but with 2C/
|
|
58 ;; prepended.
|
0
|
59
|
4
|
60 ;; f2 b asocias alian bufron. Vi povas associates another buffer.
|
|
61 ;; C-x 6 b anka^u asocii dataron, se vi This can be used to associate a
|
|
62 ;; ^jus anta^ue faris C-x C-f. file if you just did C-x C-f.
|
0
|
63
|
4
|
64 ;; f2 s disigas jam dukolumnan tekston splits a two-column text into
|
|
65 ;; C-x 6 s en du bufroj ekde la nuna two buffers from the current
|
|
66 ;; linio, kaj je la nuna kolumno. line and at the current column.
|
|
67 ;; La anta^uaj signoj (ofte The preceding characters (often
|
|
68 ;; tabeligilo a^u |) estas la tab or |) are the column
|
|
69 ;; kolumna disiganto. Linioj kiuj separator. Lines that don't
|
|
70 ;; ne enhavas ilin ne estas have them won't be separated.
|
|
71 ;; disigitaj. Kiel la kvara kaj Like the fourth and fifth line
|
|
72 ;; la kvina linio se vi disigas if you split this file from
|
|
73 ;; ^ci dataron ekde la unua angla the first english word.
|
|
74 ;; vorto.
|
0
|
75
|
4
|
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 vakajn 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 ;; ^cefan modalon, la mal^cefaj 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.
|
0
|
89
|
4
|
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 mal^cefa two columns, you turn off the minor
|
|
97 ;; modalo per C-x 6 d. mode with C-x 6 d.
|
|
98
|
|
99
|
|
100 ;; Aldone al dukolumna redaktado, ek- In addition to two-column editing of
|
|
101 ;; zemple por skribi dulingvan tekston text, for example for writing a
|
|
102 ;; flank-al-flanke kiel ^ci tiu, aliaj bilingual text side-by-side as shown
|
|
103 ;; interesaj uzoj trovitas por tiu mal- here, other interesting uses have
|
|
104 ;; ^cefa modalo: been found for this minor mode:
|
|
105
|
|
106 ;; Vi povas disigi la kolumnojn per {+} You can separate the columns with
|
|
107 ;; ajna pla^ca ^ceno starigante {+} any string that pleases you, by
|
|
108 ;; `2C-separator'. Ekzemple "{+} " {+} setting `2C-separator'. For example
|
|
109 ;; por amuzi^gi. f2 s a^u C-x 6 s {+} "{+} " if you'd like to have fun.
|
|
110 ;; traktas tiujn kun prefiksa {+} f2 s or C-x 6 s handles these with a
|
|
111 ;; argumento kiu signifas la longon {+} prefix argument that means the
|
|
112 ;; de tia ^ceno. {+} desired length of such a string.
|
|
113
|
|
114
|
|
115 ;; Programistoj eble ^satus la eblecon Programmers might like the ability
|
|
116 ;; forspliti la komentarian kolumnon de to split off the comment column of a
|
|
117 ;; dosiero kiel la sekvanta. Vi povas file that looks like the following.
|
|
118 ;; rearan^gigi la paragrafon. La pro- You can fill-paragraph the comment.
|
|
119 ;; blemo estas ke koda^jo tuj lar- The problem is, code quickly gets
|
|
120 ;; ^gi^gas, tiel ke vi bezonas pli rather wide, so you need to use a
|
|
121 ;; mallar^gan komentarian kolumnon. narrower comment column. Code lines
|
|
122 ;; Koda^jaj linioj tra `comment-column' that reach beyond `comment-column'
|
|
123 ;; ne problemas, krom ke vi ne vidos are no problem, except that you
|
|
124 ;; iliajn finojn dum redaktado. won't see their end during editing.
|
|
125
|
|
126
|
0
|
127 ;; BEGIN -- This is just some meaningless
|
|
128 ;; FOR i IN 1..10 LOOP -- code in Ada, that runs foobar
|
4
|
129 ;; foobar( i ); -- once for each argument from one
|
0
|
130 ;; END LOOP; -- to ten, and then we're already
|
|
131 ;; END; -- through with it.
|
4
|
132
|
|
133 ;; Pli bone ankora^u, vi povas pozici- Better yet, you can put the point
|
|
134 ;; i^gi anta^u "This", tajpi M-3 f2 s before "This", type M-3 f2 s
|
|
135 ;; kiu igas "-- " la separigilon inter which makes "-- " the separator
|
|
136 ;; senkomentaria Ada bufro kaj nur- between a no-comments Ada buffer,
|
|
137 ;; teksta komentaria bufro. Kiam vi and a plain text comment buffer.
|
|
138 ;; denove kuni^gos ilin, ^ciu nevaka When you put them back together,
|
|
139 ;; linio de l' dua kolumno denove every non-empty line of the 2nd
|
|
140 ;; anta^uhavos "-- ". column will again be preceded by
|
|
141 ;; "-- ".
|
|
142
|
0
|
143
|
|
144 ;;; Code:
|
|
145
|
4
|
146
|
|
147 ;; Lucid patch
|
|
148 (or (fboundp 'frame-width)
|
|
149 (fset 'frame-width 'screen-width))
|
|
150
|
|
151
|
0
|
152 ;;;;; Set up keymap ;;;;;
|
|
153
|
4
|
154 (defvar 2C-mode-map
|
|
155 (let ((map (make-sparse-keymap)))
|
|
156 (define-key map "2" '2C-two-columns)
|
|
157 (define-key map [f2] '2C-two-columns)
|
|
158 (define-key map "b" '2C-associate-buffer)
|
|
159 (define-key map "s" '2C-split)
|
|
160 map)
|
|
161 "Keymap for commands for setting up two-column mode.")
|
|
162
|
|
163
|
|
164
|
|
165 ;;;###autoload (autoload '2C-command "two-column" () t 'keymap)
|
|
166 (fset '2C-command 2C-mode-map)
|
|
167
|
|
168 ;; Urgh. Autoloading list this keybinding causes two-column.elc to get
|
|
169 ;; dumped with XEmacs.
|
|
170
|
|
171 ;; This one is for historical reasons and simple keyboards, it is not
|
|
172 ;; at all mnemonic. All usual sequences containing 2 were used, and
|
|
173 ;; f2 could not be set up in a standard way under Emacs 18.
|
|
174 (global-set-key "\C-x6" '2C-command)
|
|
175
|
|
176
|
|
177 ;; Urgh. Autoloading list this keybinding causes two-column.elc to get
|
|
178 ;; dumped with XEmacs.
|
|
179
|
|
180 (global-set-key [f2] '2C-command)
|
0
|
181
|
4
|
182
|
|
183 (defvar 2C-minor-mode-map
|
|
184 (let ((map (make-sparse-keymap)))
|
|
185 (define-key map "1" '2C-merge)
|
|
186 (define-key map "d" '2C-dissociate)
|
|
187 (define-key map "o" '2C-associated-buffer)
|
|
188 (define-key map "\^m" '2C-newline)
|
|
189 (define-key map "|" '2C-toggle-autoscroll)
|
|
190 (define-key map "{" '2C-shrink-window-horizontally)
|
|
191 (define-key map "}" '2C-enlarge-window-horizontally)
|
|
192 map)
|
|
193 "Keymap for commands for use in two-column mode.")
|
|
194
|
0
|
195
|
4
|
196 (setq minor-mode-map-alist
|
|
197 (cons (cons '2C-mode
|
|
198 (let ((map (make-sparse-keymap)))
|
|
199 (substitute-key-definition '2C-command 2C-minor-mode-map
|
|
200 map (current-global-map))
|
|
201 (substitute-key-definition 'enlarge-window-horizontally
|
|
202 '2C-enlarge-window-horizontally
|
|
203 map (current-global-map))
|
|
204 (substitute-key-definition 'shrink-window-horizontally
|
|
205 '2C-shrink-window-horizontally
|
|
206 map (current-global-map))
|
|
207 map))
|
|
208 minor-mode-map-alist))
|
0
|
209
|
|
210 ;;;;; variable declarations ;;;;;
|
|
211
|
4
|
212 ;; Markers seem to be the only buffer-id not affected by renaming a buffer.
|
|
213 ;; This nevertheless loses when a buffer is killed. The variable-name is
|
|
214 ;; required by `describe-mode'.
|
|
215 (defvar 2C-mode nil
|
0
|
216 "Marker to the associated buffer, if non-nil.")
|
4
|
217 (make-variable-buffer-local '2C-mode)
|
|
218 (put '2C-mode 'permanent-local t)
|
|
219
|
0
|
220
|
4
|
221
|
|
222 (setq minor-mode-alist (cons '(2C-mode " 2C") minor-mode-alist))
|
|
223 (add-minor-mode '2C-other " 2C" nil nil '2C-two-columns)
|
|
224
|
0
|
225
|
|
226 ;; rearranged, so that the pertinent info will show in 40 columns
|
4
|
227 (defvar 2C-mode-line-format
|
0
|
228 '("-%*- %15b --" (-3 . "%p") "--%[(" mode-name
|
4
|
229 minor-mode-alist "%n" mode-line-process ")%]%-")
|
0
|
230 "*Value of mode-line-format for a buffer in two-column minor mode.")
|
|
231
|
4
|
232
|
|
233 (defvar 2C-other-buffer-hook 'text-mode
|
|
234 "*Hook run in new buffer when it is associated with current one.")
|
|
235
|
|
236
|
|
237 (defvar 2C-separator ""
|
0
|
238 "*A string inserted between the two columns when merging.
|
4
|
239 This gets set locally by \\[2C-split].")
|
|
240 (put '2C-separator 'permanent-local t)
|
0
|
241
|
4
|
242
|
|
243
|
|
244 (defvar 2C-window-width 40
|
0
|
245 "*The width of the first column. (Must be at least `window-min-width')
|
|
246 This value is local for every buffer that sets it.")
|
4
|
247 (make-variable-buffer-local '2C-window-width)
|
|
248 (put '2C-window-width 'permanent-local t)
|
|
249
|
0
|
250
|
4
|
251
|
|
252 (defvar 2C-beyond-fill-column 4
|
0
|
253 "*Base for calculating `fill-column' for a buffer in two-column minor mode.
|
4
|
254 The value of `fill-column' becomes `2C-window-width' for this buffer
|
0
|
255 minus this value.")
|
|
256
|
4
|
257
|
|
258
|
|
259 (defvar 2C-autoscroll t
|
|
260 "If non-nil, Emacs attempts to keep the two column's buffers aligned.")
|
|
261
|
|
262
|
|
263
|
|
264 (defvar 2C-autoscroll-start nil)
|
|
265 (make-variable-buffer-local '2C-autoscroll-start)
|
0
|
266
|
|
267 ;;;;; base functions ;;;;;
|
|
268
|
4
|
269 ;; The access method for the other buffer. This tries to remedy against
|
0
|
270 ;; lost local variables and lost buffers.
|
4
|
271 (defun 2C-other (&optional req)
|
|
272 (or (if 2C-mode
|
|
273 (or (prog1
|
|
274 (marker-buffer 2C-mode)
|
|
275 (setq mode-line-format 2C-mode-line-format))
|
|
276 ;; The associated buffer somehow got killed.
|
|
277 (progn
|
|
278 ;; The other variables may later be useful if the user
|
|
279 ;; reestablishes the association.
|
|
280 (kill-local-variable '2C-mode)
|
|
281 (kill-local-variable 'mode-line-format)
|
|
282 nil)))
|
|
283 (if req (error "You must first set two-column minor mode."))))
|
0
|
284
|
4
|
285
|
0
|
286
|
4
|
287 ;; function for setting up two-column minor mode in a buffer associated
|
|
288 ;; with the buffer pointed to by the marker other.
|
|
289 (defun 2C-mode (other)
|
|
290 "Minor mode for independently editing two columns.
|
|
291 This is set up for two associated buffers by the three commands bound
|
|
292 to \\[2C-two-columns] , \\[2C-associate-buffer] and \\[2C-split].
|
|
293 Turning on two-column mode calls the value of the variable `2C-mode-hook',
|
|
294 if that value is non-nil.
|
0
|
295
|
4
|
296 These buffers can be edited separately, for example with `fill-paragraph'.
|
|
297 If you want to disable parallel scrolling temporarily, use \\[2C-toggle-autoscroll] .
|
0
|
298
|
|
299 If you include long lines, i.e which will span both columns (eg.
|
|
300 source code), they should be in what will be the first column, with
|
|
301 the associated buffer having empty lines next to them.
|
|
302
|
4
|
303 Potential uses are writing bilingual texts, or editing the comments of a
|
|
304 source code. See the file lisp/two-column.el for detailed examples.
|
|
305
|
0
|
306 You have the following commands at your disposal:
|
|
307
|
4
|
308 \\[2C-two-columns] Rearrange screen with current buffer first
|
|
309 \\[2C-associate-buffer] Reassociate buffer after changing major mode
|
0
|
310 \\[shrink-window-horizontally], \\[enlarge-window-horizontally] Shrink, enlarge current column
|
4
|
311 \\[2C-associated-buffer] Switch to associated buffer at same point
|
|
312 \\[2C-newline] Insert newline(s) in both buffers at same point
|
|
313 \\[2C-merge] Merge both buffers
|
|
314 \\[2C-dissociate] Dissociate the two buffers
|
0
|
315
|
4
|
316 These keybindings can be customized in your ~/.emacs by `2C-mode-map',
|
|
317 `2C-minor-mode-map' and by binding `2C-command' to some prefix.
|
0
|
318
|
|
319 The appearance of the screen can be customized by the variables
|
4
|
320 `2C-window-width', `2C-beyond-fill-column', `2C-mode-line-format' and
|
|
321 `truncate-partial-width-windows'."
|
|
322 (make-local-hook 'post-command-hook)
|
|
323 (add-hook 'post-command-hook '2C-autoscroll nil t)
|
|
324 (setq fill-column (- 2C-window-width
|
|
325 2C-beyond-fill-column)
|
|
326 mode-line-format 2C-mode-line-format
|
|
327 2C-mode other)
|
|
328 (run-hooks '2C-mode-hook))
|
|
329
|
0
|
330
|
4
|
331
|
|
332 ;;;###autoload
|
|
333 (defun 2C-two-columns (&optional buffer)
|
|
334 "Split current window vertically for two-column editing.
|
|
335 When called the first time, associates a buffer with the current
|
|
336 buffer in two-column minor mode (see \\[describe-mode] ).
|
|
337 Runs `2C-other-buffer-hook' in the new buffer.
|
|
338 When called again, restores the screen layout with the current buffer
|
|
339 first and the associated buffer to it's right."
|
0
|
340 (interactive "P")
|
4
|
341 ;; first go to full width, so that we can certainly split into two windows
|
0
|
342 (if (< (window-width) (frame-width))
|
|
343 (enlarge-window 99999 t))
|
|
344 (split-window-horizontally
|
4
|
345 (max window-min-width (min 2C-window-width
|
0
|
346 (- (frame-width) window-min-width))))
|
4
|
347 (if (2C-other)
|
0
|
348 (progn
|
|
349 (other-window 1)
|
4
|
350 (switch-to-buffer (2C-other))
|
0
|
351 (other-window -1)
|
4
|
352 (if 2C-autoscroll
|
|
353 (2C-toggle-autoscroll t)))
|
0
|
354
|
4
|
355 (2C-mode (prog1 (point-marker)
|
|
356 (other-window 1)
|
|
357 (switch-to-buffer
|
|
358 (or buffer
|
|
359 (generate-new-buffer (concat "2C/" (buffer-name)))))
|
|
360 (or buffer
|
|
361 (run-hooks '2C-other-buffer-hook))))
|
|
362
|
|
363 (2C-mode (prog1 (point-marker)
|
|
364 (other-window -1)))))
|
0
|
365
|
|
366
|
|
367
|
|
368 ;;;###autoload
|
4
|
369 (defun 2C-associate-buffer ()
|
0
|
370 "Associate another buffer with this one in two-column minor mode.
|
|
371 Can also be used to associate a just previously visited file, by
|
|
372 accepting the proposed default buffer.
|
|
373
|
4
|
374 \(See \\[describe-mode] .)"
|
0
|
375 (interactive)
|
|
376 (let ((b1 (current-buffer))
|
4
|
377 (b2 (or (2C-other)
|
0
|
378 (read-buffer "Associate buffer: " (other-buffer)))))
|
|
379 (save-excursion
|
4
|
380 (setq 2C-mode nil)
|
0
|
381 (set-buffer b2)
|
4
|
382 (and (2C-other)
|
|
383 (not (eq b1 (2C-other)))
|
0
|
384 (error "Buffer already associated with buffer `%s'."
|
4
|
385 (buffer-name (2C-other))))
|
|
386 (setq b1 (and (assq '2C-window-width (buffer-local-variables))
|
|
387 2C-window-width)))
|
0
|
388 ; if other buffer has a local width, adjust here too
|
4
|
389 (if b1 (setq 2C-window-width (- (frame-width) b1)))
|
|
390 (2C-two-columns b2)))
|
|
391
|
|
392
|
0
|
393
|
|
394 ;;;###autoload
|
4
|
395 (defun 2C-split (arg)
|
|
396 "Split a two-column text at point, into two buffers in two-column minor mode.
|
|
397 Point becomes the local value of `2C-window-width'. Only lines that
|
|
398 have the ARG same preceding characters at that column get split. The
|
|
399 ARG preceding characters without any leading whitespace become the local
|
|
400 value for `2C-separator'. This way lines that continue across both
|
0
|
401 columns remain untouched in the first buffer.
|
|
402
|
4
|
403 This function can be used with a prototype line, to set up things. You
|
|
404 write the first line of each column and then split that line. E.g.:
|
0
|
405
|
4
|
406 First column's text sSs Second column's text
|
0
|
407 \\___/\\
|
|
408 / \\
|
4
|
409 5 character Separator You type M-5 \\[2C-split] with the point here.
|
0
|
410
|
4
|
411 \(See \\[describe-mode] .)"
|
|
412 (interactive "*p")
|
|
413 (and (2C-other)
|
0
|
414 (if (y-or-n-p (concat "Overwrite associated buffer `"
|
4
|
415 (buffer-name (2C-other))
|
0
|
416 "'? "))
|
|
417 (save-excursion
|
4
|
418 (set-buffer (2C-other))
|
0
|
419 (erase-buffer))
|
|
420 (signal 'quit nil)))
|
|
421 (let ((point (point))
|
|
422 ; make next-line always come back to same column
|
|
423 (goal-column (current-column))
|
|
424 ; a counter for empty lines in other buffer
|
|
425 (n (1- (count-lines (point-min) (point))))
|
|
426 chars other)
|
|
427 (save-excursion
|
|
428 (backward-char arg)
|
|
429 (setq chars (buffer-substring (point) point))
|
|
430 (skip-chars-forward " \t" point)
|
4
|
431 (make-local-variable '2C-separator)
|
|
432 (setq 2C-separator (buffer-substring (point) point)
|
|
433 2C-window-width (current-column)))
|
|
434 (2C-two-columns)
|
|
435 (setq other (2C-other))
|
|
436 ; now we're ready to actually split
|
0
|
437 (save-excursion
|
|
438 (while (not (eobp))
|
|
439 (if (not (and (= (current-column) goal-column)
|
|
440 (string= chars
|
|
441 (buffer-substring (point)
|
|
442 (save-excursion
|
|
443 (backward-char arg)
|
|
444 (point))))))
|
|
445 (setq n (1+ n))
|
|
446 (setq point (point))
|
|
447 (backward-char arg)
|
|
448 (skip-chars-backward " \t")
|
|
449 (delete-region point (point))
|
|
450 (setq point (point))
|
|
451 (insert-char ?\n n)
|
|
452 (append-to-buffer other point (progn (end-of-line)
|
|
453 (if (eobp)
|
|
454 (point)
|
|
455 (1+ (point)))))
|
|
456 (delete-region point (point))
|
|
457 (setq n 0))
|
|
458 (next-line 1)))))
|
|
459
|
4
|
460
|
|
461
|
|
462
|
|
463 (defun 2C-dissociate ()
|
0
|
464 "Turn off two-column minor mode in current and associated buffer.
|
|
465 If the associated buffer is unmodified and empty, it is killed."
|
|
466 (interactive)
|
|
467 (let ((buffer (current-buffer)))
|
|
468 (save-excursion
|
4
|
469 (and (2C-other)
|
|
470 (set-buffer (2C-other))
|
|
471 (or (not (2C-other))
|
|
472 (eq buffer (2C-other)))
|
0
|
473 (if (and (not (buffer-modified-p))
|
|
474 (eobp) (bobp))
|
|
475 (kill-buffer nil)
|
4
|
476 (kill-local-variable '2C-mode)
|
|
477 (kill-local-variable '2C-window-width)
|
|
478 (kill-local-variable '2C-separator)
|
0
|
479 (kill-local-variable 'mode-line-format)
|
|
480 (kill-local-variable 'fill-column))))
|
4
|
481 (kill-local-variable '2C-mode)
|
|
482 (kill-local-variable '2C-window-width)
|
|
483 (kill-local-variable '2C-separator)
|
0
|
484 (kill-local-variable 'mode-line-format)
|
|
485 (kill-local-variable 'fill-column)))
|
|
486
|
|
487
|
4
|
488
|
0
|
489 ;; this doesn't use yank-rectangle, so that the first column can
|
|
490 ;; contain long lines
|
4
|
491 (defun 2C-merge ()
|
0
|
492 "Merges the associated buffer with the current buffer.
|
4
|
493 They get merged at the column, which is the value of `2C-window-width',
|
|
494 i.e. usually at the vertical window separator. This separator gets
|
|
495 replaced with white space. Beyond that the value of `2C-separator' gets
|
|
496 inserted on merged lines. The two columns are thus pasted side by side,
|
|
497 in a single text. If the other buffer is not displayed to the left of
|
|
498 this one, then this one becomes the left column.
|
0
|
499
|
4
|
500 If you want `2C-separator' on empty lines in the second column,
|
0
|
501 you should put just one space in them. In the final result, you can strip
|
|
502 off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ] + $ RET RET"
|
|
503 (interactive)
|
4
|
504 (and (> (car (window-edges)) 0) ; not touching left edge of screen
|
0
|
505 (eq (window-buffer (previous-window))
|
4
|
506 (2C-other t))
|
0
|
507 (other-window -1))
|
|
508 (save-excursion
|
|
509 (let ((b1 (current-buffer))
|
4
|
510 (b2 (2C-other t))
|
0
|
511 string)
|
|
512 (goto-char (point-min))
|
|
513 (set-buffer b2)
|
|
514 (goto-char (point-min))
|
|
515 (while (not (eobp))
|
|
516 (setq string (buffer-substring (point)
|
|
517 (progn (end-of-line) (point))))
|
|
518 (or (eobp)
|
|
519 (forward-char)) ; next line
|
|
520 (set-buffer b1)
|
|
521 (if (string= string "")
|
|
522 ()
|
|
523 (end-of-line)
|
4
|
524 (indent-to-column 2C-window-width)
|
|
525 (insert 2C-separator string))
|
0
|
526 (next-line 1) ; add one if necessary
|
|
527 (set-buffer b2))))
|
|
528 (if (< (window-width) (frame-width))
|
|
529 (enlarge-window 99999 t)))
|
|
530
|
|
531 ;;;;; utility functions ;;;;;
|
|
532
|
4
|
533 (defun 2C-associated-buffer ()
|
0
|
534 "Switch to associated buffer."
|
|
535 (interactive)
|
4
|
536 (let ((line (+ (count-lines (point-min) (point))
|
|
537 (if (bolp) 1 0)))
|
|
538 (col (if (eolp) (if (bolp) 0) (current-column))))
|
|
539 (if (get-buffer-window (2C-other t))
|
|
540 (select-window (get-buffer-window (2C-other)))
|
|
541 (switch-to-buffer (2C-other)))
|
|
542 (newline (goto-line line))
|
|
543 (if col
|
|
544 (move-to-column col)
|
|
545 (end-of-line 1))))
|
|
546
|
|
547 (defun 2C-newline (arg)
|
|
548 "Insert ARG newlines in both buffers."
|
|
549 (interactive "P")
|
|
550 (save-window-excursion
|
|
551 (2C-associated-buffer)
|
|
552 (newline arg))
|
|
553 (newline arg))
|
0
|
554
|
4
|
555 (defun 2C-toggle-autoscroll (arg)
|
|
556 "Toggle autoscrolling, or set it iff prefix ARG is non-nil and positive.
|
|
557 When autoscrolling is turned on, this also realigns the two buffers."
|
|
558 (interactive "P")
|
|
559 ;(sit-for 0)
|
|
560 (setq 2C-autoscroll-start (window-start))
|
|
561 (if (setq 2C-autoscroll (if arg
|
|
562 (>= (prefix-numeric-value arg) 0)
|
|
563 (not 2C-autoscroll)))
|
|
564 (select-window
|
|
565 (prog1 (selected-window)
|
|
566 (message "Autoscrolling is on.")
|
|
567 (setq arg (count-lines (point-min) (window-start)))
|
|
568 (if (get-buffer-window (2C-other t))
|
|
569 (progn
|
|
570 (select-window (get-buffer-window (2C-other)))
|
|
571 (setq arg (- arg (count-lines (point-min) (window-start))))
|
|
572 ;; make sure that other buffer has enough lines
|
|
573 (save-excursion
|
|
574 (insert-char ?\n
|
|
575 (- arg (count-lines (window-start)
|
|
576 (goto-char (point-max)))
|
|
577 -1)))
|
|
578 (scroll-up arg)))))
|
|
579 (message "Autoscrolling is off.")))
|
|
580
|
|
581
|
0
|
582
|
4
|
583 (defun 2C-autoscroll ()
|
|
584 (if 2C-autoscroll
|
|
585 ;; catch a mouse scroll on non-selected scrollbar
|
|
586 (select-window
|
|
587 (prog1 (selected-window)
|
|
588 (and (consp last-command-char)
|
|
589 (not (eq (selected-window)
|
|
590 (car (car (cdr last-command-char)))))
|
|
591 (select-window (car (car (cdr last-command-char)))))
|
|
592 ;; In some cases scrolling causes an error, but post-command-hook
|
|
593 ;; shouldn't, and should always stay in the original window
|
|
594 (condition-case ()
|
|
595 (and (or 2C-autoscroll-start (2C-toggle-autoscroll t) nil)
|
|
596 (/= (window-start) 2C-autoscroll-start)
|
|
597 (2C-other)
|
|
598 (get-buffer-window (2C-other))
|
|
599 (let ((lines (count-lines (window-start)
|
|
600 2C-autoscroll-start)))
|
|
601 (if (< (window-start) 2C-autoscroll-start)
|
|
602 (setq lines (- lines)))
|
|
603 (setq 2C-autoscroll-start (window-start))
|
|
604 (select-window (get-buffer-window (2C-other)))
|
|
605 ;; make sure that other buffer has enough lines
|
|
606 (save-excursion
|
|
607 (insert-char
|
|
608 ?\n (- lines (count-lines (window-start)
|
|
609 (goto-char (point-max)))
|
|
610 -1)))
|
|
611 (scroll-up lines)
|
|
612 (setq 2C-autoscroll-start (window-start))))
|
|
613 (error))))))
|
0
|
614
|
4
|
615
|
0
|
616
|
4
|
617 (defun 2C-enlarge-window-horizontally (arg)
|
0
|
618 "Make current window ARG columns wider."
|
|
619 (interactive "p")
|
|
620 (enlarge-window arg t)
|
4
|
621 (and (2C-other)
|
|
622 (setq 2C-window-width (+ 2C-window-width arg))
|
|
623 (set-buffer (2C-other))
|
|
624 (setq 2C-window-width (- 2C-window-width arg))))
|
0
|
625
|
4
|
626 (defun 2C-shrink-window-horizontally (arg)
|
0
|
627 "Make current window ARG columns narrower."
|
|
628 (interactive "p")
|
4
|
629 (2C-enlarge-window-horizontally (- arg)))
|
|
630
|
|
631
|
0
|
632
|
|
633 (provide 'two-column)
|
|
634
|
|
635 ;;; two-column.el ends here
|