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