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