Symbols renamed to be like mode-line indicator.
Supposed to now also work for Lucid. (2C-mode-map): New name for `tc-mode-map'. Additionally bound to [f2]. (2C-minor-mode-map) New variable. (2C-mode): New name for `tc-other'. (2C-mode-line-format): New name for `tc-mode-line-format'. (2C-other-buffer-hook): New variable. (2C-separator): New name for `tc-separator'. (2C-window-width): New name for `tc-window-width'. (2C-beyond-fill-column): New name for `tc-beyond-fill-column'. (2C-autoscroll, 2C-autoscroll-start): New variables. (2C-other): New name for `tc-other'. (2C-mode): New name for `tc-mode', `tc-two-columns'. (2C-two-columns): New function. (2C-associate-buffer): New name for `tc-associate-buffer'. (2C-split): New name for `tc-split'. (2C-dissociate): New name for `tc-dissociate'. (2C-merge): New name for `tc-merge'. (2C-associated-buffer): New name for `tc-associated-buffer'. (2C-toggle-autoscroll, 2C-autoscroll): New functions. (tc-scroll-line, tc-scroll-up, tc-scroll-down, tc-recenter): Deleted functions.
This commit is contained in:
parent
133693bc90
commit
e6b7241010
1 changed files with 402 additions and 397 deletions
|
@ -1,407 +1,401 @@
|
||||||
;;; two-column.el --- minor mode for editing of two-column text
|
;;; two-column.el --- minor mode for editing of two-column text
|
||||||
|
|
||||||
;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
|
;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||||
|
|
||||||
;; Author: Daniel Pfeiffer <pfeiffer@cix.cict.fr>
|
;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
|
||||||
;; Adapted-By: ESR
|
;; Adapted-By: ESR, Daniel Pfeiffer
|
||||||
|
|
||||||
;; This file is part of GNU Emacs.
|
;; Esperanto: English:
|
||||||
|
|
||||||
;; GNU Emacs is free software; you can redistribute it and/or modify
|
;; ^Ci dosiero estas ero de GNU Emacs. This file is part of GNU Emacs.
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 2, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
|
|
||||||
;; GNU Emacs is distributed in the hope that it will be useful,
|
;; GNU Emacs estas libera programaro; GNU Emacs is free software; you can
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
;; vi povas disdoni ^gin kaj/a^u modifi redistribute it and/or modify it
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
;; ^gin sub la kondi^coj de la GNU under the terms of the GNU General
|
||||||
;; GNU General Public License for more details.
|
;; ^Generala Publika Licenco kiel pub- Public License as published by the
|
||||||
|
;; likigita far la Liberprogramara Fon- Free Software Foundation; either
|
||||||
|
;; da^jo; a^u eldono 2a, a^u (la^u via version 2, or (at your option) any
|
||||||
|
;; elekto) ajna posta eldono. later version.
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
;; GNU Emacs estas disdonata en la GNU Emacs is distributed in the hope
|
||||||
;; along with GNU Emacs; see the file COPYING. If not, write to
|
;; espero ke ^gi estos utila, sed SEN that it will be useful, but WITHOUT
|
||||||
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
;; IA GARANTIO; sen e^c la implicita ANY WARRANTY; without even the
|
||||||
|
;; garantio de VENDEBLECO a^u PRETECO implied warranty of MERCHANTABILITY
|
||||||
|
;; POR DETERMINITA CELO. Vidu la GNU or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
;; ^Generala Publika Licenco por plenaj See the GNU General Public License
|
||||||
|
;; detaloj. for more details.
|
||||||
|
|
||||||
;;; Commentary:
|
;; Vi devus ricevinti kopion de la GNU You should have received a copy of
|
||||||
|
;; ^Generala Publika Licenco kune kun the GNU General Public License along
|
||||||
|
;; GNU Emacs; vidu la dosieron COPYING. with GNU Emacs; see the file
|
||||||
|
;; Alikaze skribu al la COPYING. If not, write to the
|
||||||
|
|
||||||
;; This package gives you the ability to edit text in a two-column format.
|
;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
;; --8<---- two-column.el ----8<--------8<--------8<--------8<--------8<-------
|
|
||||||
;; Esperanto: English:
|
|
||||||
|
|
||||||
;; Minora modalo por samtempa dukolumna Minor mode for simultaneous
|
|
||||||
;; tajpado two-column editing
|
|
||||||
|
|
||||||
;; Tiu minora modalo ebligas al vi This minor mode allows you to
|
|
||||||
;; tajpi sendepende en du apudaj independently edit two adjacent
|
|
||||||
;; bufroj. Vi havas tri eblecojn por buffers. You have three ways to
|
|
||||||
;; eki ^gin. ^Ciu donas al vi start it up. Each gives you a
|
|
||||||
;; horizontale disigatan fenestron, horizontally split window similar to
|
|
||||||
;; simila al fina apareco de via the final outcome of your text:
|
|
||||||
;; teksto:
|
|
||||||
|
|
||||||
;; C-x 6 2 asocias novan bufron nomatan associates a new buffer called
|
|
||||||
;; same, sed kun 2C/ anta^u. the same, but with 2C/
|
|
||||||
;; prepended.
|
|
||||||
|
|
||||||
;; C-x 6 b asocias alian bufron. Vi povas associates another buffer.
|
|
||||||
;; anka^u asocii dataron, se vi This can be used to associate a
|
|
||||||
;; ^jus anta^ue faris C-x C-f. file if you just did C-x C-f.
|
|
||||||
|
|
||||||
;; C-x 6 u disigas jam dukolumnan tekston unmerges a two-column text into
|
|
||||||
;; en du bufroj ekde la nuna two buffers from the current
|
|
||||||
;; linio, kaj je la nuna kolumno. line and at the current column.
|
|
||||||
;; La anta^uaj signoj (ofte The preceding characters (often
|
|
||||||
;; tabeligilo a^u |) estas la tab or |) are the column
|
|
||||||
;; kolumna disiganto. Linioj kiuj separator. Lines that don't
|
|
||||||
;; ne enhavas ilin ne estas have them won't be separated.
|
|
||||||
;; disigitaj. Kiel la kvara kaj Like the fourth and fifth line
|
|
||||||
;; la kvina linio se vi disigas if you unmerge this file from
|
|
||||||
;; ^ci dataron ekde la unua angla the first english word.
|
|
||||||
;; vorto.
|
|
||||||
|
|
||||||
;; Je ^cia flanko estas bufro, kiu On each side is a buffer that knows
|
|
||||||
;; konas la alian. Kun la ordonoj C-x about the other. With the commands
|
|
||||||
;; 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
|
|
||||||
;; povas suben- a^u supreniri unu you can simultaneously scroll up or
|
|
||||||
;; ekranon, kaj subeniri linion, down by a screenfull and by a line
|
|
||||||
;; samtempe en la du bufroj. Al la alia in both buffers. Empty lines are
|
|
||||||
;; bufro estas aldonataj linioj se added to the other buffer if
|
|
||||||
;; necesas, por ke vi vidu la saman necessary, so that you see the same
|
|
||||||
;; parton. Per C-x 6 C-l vi povas part. With C-x 6 C-l you can
|
|
||||||
;; recentrigi la linion. Kiam vi nur recenter the line. When you only
|
|
||||||
;; plu havas unu el la du bufroj have one of the two buffers onscreen
|
|
||||||
;; surekrane vi revidos la alian per you can get the other back with C-x
|
|
||||||
;; denove C-x 6 2. 6 2 once more.
|
|
||||||
|
|
||||||
;; Se vi volas meti longajn liniojn If you include long lines, i.e which
|
|
||||||
;; (ekz. programerojn) en la kunigotan will span both columns (eg. source
|
|
||||||
;; tekston, ili devas esti en la code), they should be in what will
|
|
||||||
;; estonte unua kolumno. La alia devas be the first column, with the
|
|
||||||
;; havi malplenajn linion apud ili. associated buffer having empty lines
|
|
||||||
;; next to them.
|
|
||||||
|
|
||||||
;; Averto: en Emacs kiam vi ^san^gas la Attention: in Emacs when you change
|
|
||||||
;; ma^joran modalon, la minoraj modaloj the major mode, the minor modes are
|
|
||||||
;; estas anka^u elmemorigitaj. Tiu- also purged from memory. In that
|
|
||||||
;; okaze vi devas religi la du bufrojn case you must reassociate the two
|
|
||||||
;; per iu C-x 6-ordono, ekz. C-x 6 b. buffers with any C-x 6-command, e.g.
|
|
||||||
;; C-x 6 b.
|
|
||||||
|
|
||||||
;; Kiam vi estos kontenta de la When you have edited both buffers to
|
|
||||||
;; rezulto, vi kunmetos la du kolumnojn your content, you merge them with
|
|
||||||
;; per C-x 6 1. Se vi poste vidas C-x 6 1. If you then see a problem,
|
|
||||||
;; problemon, vi neniigu la kunmeton you undo the merge with C-x u and
|
|
||||||
;; per C-x u kaj plue modifu la du continue to edit the two buffers.
|
|
||||||
;; bufrojn. Kiam vi ne plu volas tajpi When you no longer want to edit in
|
|
||||||
;; dukolumne, vi eliru el la minora two columns, you turn off the minor
|
|
||||||
;; modalo per C-x 6 k. mode with C-x 6 k.
|
|
||||||
|
|
||||||
|
|
||||||
;; An^stata^u tri `autoload' kaj tri | Instead of three `autoload' and
|
;;; Komentario: Commentary:
|
||||||
;; `global-set-key' vi povas uzi la | three `global-set-key' you can use
|
|
||||||
;; jenon en via dataro ~/.emacs, por | the following in your file
|
|
||||||
;; memstare ^sar^gi la modalon: | ~/.emacs, to automatically load
|
|
||||||
;; | the mode:
|
|
||||||
|
|
||||||
;; (global-set-key "\C-x6"
|
;; Tiu programaro ebligas vin redakti This package gives you the ability
|
||||||
;; '(lambda () (interactive)
|
;; dukolumnan tekston. to edit text in a two-column format.
|
||||||
;; (load-library "two-column")
|
|
||||||
;; (call-interactively
|
|
||||||
;; (cdr (assq (read-char) tc-mode-map)))))
|
|
||||||
|
|
||||||
;; Se vi ^satus havi la dukolumnajn | If you'd like to have the
|
|
||||||
;; ordonojn je funkciklavo <f2>, vi | two-column commands on function
|
|
||||||
;; povas uzi la jenon en via dataro | key <f2>, you can use the
|
|
||||||
;; ~/.emacs: | following in your file ~/.emacs:
|
|
||||||
|
|
||||||
;; (global-set-key [f2] (function
|
;; Vi havas tri eblecojn por eki tiun You have three ways to start up this
|
||||||
;; (lambda ()
|
;; mal^cefan modalon. ^Ciu donas al vi minor mode. Each gives you a
|
||||||
;; (interactive)
|
;; horizontale disigatan fenestron, si- horizontally split window similar to
|
||||||
;; (load-library "two-column")
|
;; milan al fina apareco de via teksto: the final outcome of your text:
|
||||||
;; (global-set-key [f2] tc-mode-map)
|
|
||||||
;; (call-interactively
|
|
||||||
;; (cdr (assq (read-char) tc-mode-map))))))
|
;; f2 2 asocias novan bufron nomatan associates a new buffer called
|
||||||
|
;; C-x 6 2 same, sed kun 2C/ anta^u. the same, but with 2C/
|
||||||
|
;; prepended.
|
||||||
|
|
||||||
|
;; f2 b asocias alian bufron. Vi povas associates another buffer.
|
||||||
|
;; C-x 6 b anka^u asocii dataron, se vi This can be used to associate a
|
||||||
|
;; ^jus anta^ue faris C-x C-f. file if you just did C-x C-f.
|
||||||
|
|
||||||
|
;; f2 s disigas jam dukolumnan tekston splits a two-column text into
|
||||||
|
;; C-x 6 s en du bufroj ekde la nuna two buffers from the current
|
||||||
|
;; linio, kaj je la nuna kolumno. line and at the current column.
|
||||||
|
;; La anta^uaj signoj (ofte The preceding characters (often
|
||||||
|
;; tabeligilo a^u |) estas la tab or |) are the column
|
||||||
|
;; kolumna disiganto. Linioj kiuj separator. Lines that don't
|
||||||
|
;; ne enhavas ilin ne estas have them won't be separated.
|
||||||
|
;; disigitaj. Kiel la kvara kaj Like the fourth and fifth line
|
||||||
|
;; la kvina linio se vi disigas if you split this file from
|
||||||
|
;; ^ci dataron ekde la unua angla the first english word.
|
||||||
|
;; vorto.
|
||||||
|
|
||||||
|
;; Se vi volas meti longajn liniojn If you include long lines, i.e which
|
||||||
|
;; (ekz. programerojn) en la kunigotan will span both columns (eg. source
|
||||||
|
;; tekston, ili devas esti en la code), they should be in what will
|
||||||
|
;; estonte unua kolumno. La alia devas be the first column, with the
|
||||||
|
;; havi vakajn linion apud ili. associated buffer having empty lines
|
||||||
|
;; next to them.
|
||||||
|
|
||||||
|
;; Averto: en Emacs kiam vi ^san^gas la Attention: in Emacs when you change
|
||||||
|
;; ^cefan modalon, la mal^cefaj modaloj the major mode, the minor modes are
|
||||||
|
;; estas anka^u elmemorigitaj. Tiu- also purged from memory. In that
|
||||||
|
;; okaze vi devas religi la du bufrojn case you must reassociate the two
|
||||||
|
;; per iu C-x 6-ordono, ekz. C-x 6 b. buffers with any C-x 6-command, e.g.
|
||||||
|
;; C-x 6 b.
|
||||||
|
|
||||||
|
;; Kiam vi estos kontenta de la When you have edited both buffers to
|
||||||
|
;; rezulto, vi kunmetos la du kolumnojn your content, you merge them with
|
||||||
|
;; per C-x 6 1. Se vi poste vidas C-x 6 1. If you then see a problem,
|
||||||
|
;; problemon, vi neniigu la kunmeton you undo the merge with C-x u and
|
||||||
|
;; per C-x u kaj plue modifu la du continue to edit the two buffers.
|
||||||
|
;; bufrojn. Kiam vi ne plu volas tajpi When you no longer want to edit in
|
||||||
|
;; dukolumne, vi eliru el la mal^cefa two columns, you turn off the minor
|
||||||
|
;; modalo per C-x 6 d. mode with C-x 6 d.
|
||||||
|
|
||||||
|
|
||||||
|
;; Aldone al dukolumna redaktado, ek- In addition to two-column editing of
|
||||||
|
;; zemple por skribi dulingvan tekston text, for example for writing a
|
||||||
|
;; flank-al-flanke kiel ^ci tiu, aliaj bilingual text side-by-side as shown
|
||||||
|
;; interesaj uzoj trovitas por tiu mal- here, other interesting uses have
|
||||||
|
;; ^cefa modalo: been found for this minor mode:
|
||||||
|
|
||||||
|
;; Vi povas disigi la kolumnojn per {+} You can separate the columns with
|
||||||
|
;; ajna pla^ca ^ceno starigante {+} any string that pleases you, by
|
||||||
|
;; `2C-separator'. Ekzemple "{+} " {+} setting `2C-separator'. For example
|
||||||
|
;; por amuzi^gi. f2 s a^u C-x 6 s {+} "{+} " if you'd like to have fun.
|
||||||
|
;; traktas tiujn kun prefiksa {+} f2 s or C-x 6 s handles these with a
|
||||||
|
;; argumento kiu signifas la longon {+} prefix argument that means the
|
||||||
|
;; de tia ^ceno. {+} desired length of such a string.
|
||||||
|
|
||||||
|
|
||||||
|
;; Programistoj eble ^satus la eblecon Programmers might like the ability
|
||||||
|
;; forspliti la komentarian kolumnon de to split off the comment column of a
|
||||||
|
;; dosiero kiel la sekvanta. Vi povas file that looks like the following.
|
||||||
|
;; rearan^gigi la paragrafon. La pro- You can fill-paragraph the comment.
|
||||||
|
;; blemo estas ke koda^jo tuj lar- The problem is, code quickly gets
|
||||||
|
;; ^gi^gas, tiel ke vi bezonas pli rather wide, so you need to use a
|
||||||
|
;; mallar^gan komentarian kolumnon. narrower comment column. Code lines
|
||||||
|
;; Koda^jaj linioj tra `comment-column' that reach beyond `comment-column'
|
||||||
|
;; ne problemas, krom ke vi ne vidos are no problem, except that you
|
||||||
|
;; iliajn finojn dum redaktado. won't see their end during editing.
|
||||||
|
|
||||||
|
|
||||||
;; In addition to two-column editing of text, for example for writing a
|
|
||||||
;; bilingual text side-by-side as shown below in the file's prolog, other
|
|
||||||
;; interesting uses have been found for this minor mode:
|
|
||||||
;;
|
|
||||||
;;
|
|
||||||
;; You can separate the columns with {+} C-x 6 u or <f2> u if you prefer
|
|
||||||
;; any string that pleases you, by {+} handles these with a prefix argument
|
|
||||||
;; setting tc-separator. For {+} that enables you to declare the
|
|
||||||
;; example "{+} " if you like to {+} desired length of such a string.
|
|
||||||
;; amuse yourself.
|
|
||||||
;;
|
|
||||||
;;
|
|
||||||
;; keyword You can write any text corresponding to a
|
|
||||||
;; given keyword in a filled paragraph next to
|
|
||||||
;; it. Note that the width of the first column
|
|
||||||
;; may be less than window-min-width in the
|
|
||||||
;; result, but will be displayed at that width.
|
|
||||||
;;
|
|
||||||
;; another This is not a three- or multi-column mode.
|
|
||||||
;; The example in the file's prolog required
|
|
||||||
;; working on two columns and then treating the
|
|
||||||
;; result as one column in order to add the
|
|
||||||
;; third.
|
|
||||||
;;
|
|
||||||
;;
|
|
||||||
;; Programmers might like the ability to split off the comment column of
|
|
||||||
;; a file that looks like the following. The advantage is that with
|
|
||||||
;; (setq fill-prefix "-- ") you can run M-q (fill-paragraph) on the
|
|
||||||
;; comment. The problem is, code quickly gets rather wide, so you need
|
|
||||||
;; to use a narrower comment column, which is less interesting, unless
|
|
||||||
;; you have a 132-column screen. Code lines that reach beyond
|
|
||||||
;; comment-column are no problem, except that you won't always see their
|
|
||||||
;; end during editing.
|
|
||||||
;;
|
|
||||||
;; BEGIN -- This is just some meaningless
|
;; BEGIN -- This is just some meaningless
|
||||||
;; FOR i IN 1..10 LOOP -- code in Ada, that runs foobar
|
;; FOR i IN 1..10 LOOP -- code in Ada, that runs foobar
|
||||||
;; foobar( i ); -- once for each argument from one
|
;; foobar( i ); -- once for each argument from one
|
||||||
;; END LOOP; -- to ten, and then we're already
|
;; END LOOP; -- to ten, and then we're already
|
||||||
;; END; -- through with it.
|
;; END; -- through with it.
|
||||||
;;
|
|
||||||
;; Better yet, you can put the point before "This", type M-3 C-x 6 u
|
;; Pli bone ankora^u, vi povas pozici- Better yet, you can put the point
|
||||||
;; which makes "-- " the separator between a no-comments Ada buffer, and
|
;; i^gi anta^u "This", tajpi M-3 f2 s before "This", type M-3 f2 s
|
||||||
;; a plain text comment buffer. When you put them back together, every
|
;; kiu igas "-- " la separigilon inter which makes "-- " the separator
|
||||||
;; non-empty line of the 2nd column will again be preceded by "-- ".
|
;; senkomentaria Ada bufro kaj nur- between a no-comments Ada buffer,
|
||||||
;;
|
;; teksta komentaria bufro. Kiam vi and a plain text comment buffer.
|
||||||
;;
|
;; denove kuni^gos ilin, ^ciu nevaka When you put them back together,
|
||||||
;; The <f2> function key hack (which is one of the rare times when
|
;; linio de l' dua kolumno denove every non-empty line of the 2nd
|
||||||
;; function keys are mnemonic) at the end of the file's prolog requires
|
;; anta^uhavos "-- ". column will again be preceded by
|
||||||
;; that the lisp/term/*.el for your terminal use the standard
|
;; "-- ".
|
||||||
;; conventions. Too bad that some don't (at least not in version 18.55).
|
|
||||||
;; The Sun one is hopelessly non-standard, and vt2[024]0 somehow forgot
|
|
||||||
;; to define <f1> thru <f5>. (It defines <pf1> thru <pf4> instead, but
|
|
||||||
;; that is not what we need on an X terminal.) If you want to use those,
|
|
||||||
;; you'll need another hack something like:
|
|
||||||
;;
|
|
||||||
;; (if (string= (system-name) "cix")
|
|
||||||
;; (progn
|
|
||||||
;; (load-library "term/vt200.el")
|
|
||||||
;; (define-key CSI-map "12~" (cons function-keymap ?\^b)))
|
|
||||||
;; (global-unset-key "\e[")
|
|
||||||
;; (define-key esc-map "[225z" (cons function-keymap ?\^b)))
|
|
||||||
;;
|
|
||||||
;; where "cix" is the non-sun machine I use. Actually I use the same X
|
|
||||||
;; terminal to connect to both machines, and I want to keep my ~/.emacs
|
|
||||||
;; identical on both. Bother, the two Emacses don't recognize the same
|
|
||||||
;; keys and assign different sequences to those they do! I sure hope all
|
|
||||||
;; this nonsense will stop with version 19 (or preferably soon) where I'd
|
|
||||||
;; like to be able to say (define-key some-map '<f2> some-cmd), and see
|
|
||||||
;; <f2> rather than some unintelligible ESC-sequence in command key
|
|
||||||
;; sequences.
|
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
|
||||||
|
;; Lucid patch
|
||||||
|
(or (fboundp 'frame-width)
|
||||||
|
(fset 'frame-width 'screen-width))
|
||||||
|
|
||||||
|
|
||||||
;;;;; Set up keymap ;;;;;
|
;;;;; Set up keymap ;;;;;
|
||||||
|
|
||||||
;;;###autoload
|
(defvar 2C-mode-map
|
||||||
(defvar tc-mode-map nil
|
(let ((map (make-sparse-keymap)))
|
||||||
"Keymap for commands for two-column mode.")
|
(define-key map "2" '2C-two-columns)
|
||||||
|
(define-key map [f2] '2C-two-columns)
|
||||||
|
(define-key map "b" '2C-associate-buffer)
|
||||||
|
(define-key map "s" '2C-split)
|
||||||
|
(define-key map "{" 'shrink-window-horizontally)
|
||||||
|
(define-key map "}" 'enlarge-window-horizontally)
|
||||||
|
map)
|
||||||
|
"Keymap for commands for setting up two-column mode.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;;;###autoload (autoload '2C-command "two-column" () t 'keymap)
|
||||||
|
(fset '2C-command 2C-mode-map)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(if tc-mode-map
|
;; This one is for historical reasons and simple keyboards, it is not
|
||||||
()
|
;; at all mnemonic. All usual sequences containing 2 were used, and
|
||||||
(setq tc-mode-map (make-sparse-keymap))
|
;; f2 could not be set up in a standard way under Emacs 18.
|
||||||
(define-key tc-mode-map "1" 'tc-merge)
|
(global-set-key "\C-x6" '2C-command)
|
||||||
(define-key tc-mode-map "2" 'tc-two-columns)
|
|
||||||
(define-key tc-mode-map "b" 'tc-associate-buffer)
|
|
||||||
(define-key tc-mode-map "d" 'tc-dissociate)
|
|
||||||
(define-key tc-mode-map "\C-l" 'tc-recenter)
|
|
||||||
(define-key tc-mode-map "o" 'tc-associated-buffer)
|
|
||||||
(define-key tc-mode-map "s" 'tc-split)
|
|
||||||
(define-key tc-mode-map "{" 'shrink-window-horizontally)
|
|
||||||
(define-key tc-mode-map "}" 'enlarge-window-horizontally)
|
|
||||||
(define-key tc-mode-map " " 'tc-scroll-up)
|
|
||||||
(define-key tc-mode-map "\^?" 'tc-scroll-down)
|
|
||||||
(define-key tc-mode-map "\C-m" 'tc-scroll-line))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(global-set-key "\C-x6" tc-mode-map)
|
(global-set-key [f2] '2C-command)
|
||||||
|
|
||||||
|
|
||||||
|
(defvar 2C-minor-mode-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(define-key map "1" '2C-merge)
|
||||||
|
(define-key map "d" '2C-dissociate)
|
||||||
|
(define-key map "o" '2C-associated-buffer)
|
||||||
|
(define-key map "|" '2C-toggle-autoscroll)
|
||||||
|
map)
|
||||||
|
"Keymap for commands for use in two-column mode.")
|
||||||
|
|
||||||
|
|
||||||
|
(setq minor-mode-map-alist
|
||||||
|
(cons (cons '2C-mode
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(substitute-key-definition '2C-command 2C-minor-mode-map
|
||||||
|
map (current-global-map))
|
||||||
|
map))
|
||||||
|
minor-mode-map-alist))
|
||||||
|
|
||||||
;;;;; variable declarations ;;;;;
|
;;;;; variable declarations ;;;;;
|
||||||
|
|
||||||
;; markers seem to be the only buffer-id not affected by renaming
|
;; Markers seem to be the only buffer-id not affected by renaming a buffer.
|
||||||
;; a buffer. This nevertheless loses when a buffer is killed.
|
;; This nevertheless loses when a buffer is killed. The variable-name is
|
||||||
(defvar tc-other nil
|
;; required by `describe-mode'.
|
||||||
|
(defvar 2C-mode nil
|
||||||
"Marker to the associated buffer, if non-nil.")
|
"Marker to the associated buffer, if non-nil.")
|
||||||
(make-variable-buffer-local 'tc-other)
|
(make-variable-buffer-local '2C-mode)
|
||||||
(put 'tc-other 'permanent-local t)
|
(put '2C-mode 'permanent-local t)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(setq minor-mode-alist (cons '(2C-mode " 2C") minor-mode-alist))
|
||||||
|
|
||||||
|
|
||||||
(setq minor-mode-alist (cons '(tc-other " 2C") minor-mode-alist))
|
|
||||||
|
|
||||||
;; rearranged, so that the pertinent info will show in 40 columns
|
;; rearranged, so that the pertinent info will show in 40 columns
|
||||||
(defvar tc-mode-line-format
|
(defvar 2C-mode-line-format
|
||||||
'("-%*- %15b --" (-3 . "%p") "--%[(" mode-name
|
'("-%*- %15b --" (-3 . "%p") "--%[(" mode-name
|
||||||
minor-mode-alist mode-line-process "%n" ")%]%-")
|
minor-mode-alist "%n" mode-line-process ")%]%-")
|
||||||
"*Value of mode-line-format for a buffer in two-column minor mode.")
|
"*Value of mode-line-format for a buffer in two-column minor mode.")
|
||||||
|
|
||||||
(defvar tc-separator ""
|
|
||||||
"*A string inserted between the two columns when merging.
|
|
||||||
This gets set locally by \\[tc-split].")
|
|
||||||
(put 'tc-separator 'permanent-local t)
|
|
||||||
|
|
||||||
(defvar tc-window-width 40
|
(defvar 2C-other-buffer-hook 'text-mode
|
||||||
|
"*Hook run in new buffer when it is associated with current one.")
|
||||||
|
|
||||||
|
|
||||||
|
(defvar 2C-separator ""
|
||||||
|
"*A string inserted between the two columns when merging.
|
||||||
|
This gets set locally by \\[2C-split].")
|
||||||
|
(put '2C-separator 'permanent-local t)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defvar 2C-window-width 40
|
||||||
"*The width of the first column. (Must be at least `window-min-width')
|
"*The width of the first column. (Must be at least `window-min-width')
|
||||||
This value is local for every buffer that sets it.")
|
This value is local for every buffer that sets it.")
|
||||||
(make-variable-buffer-local 'tc-window-width)
|
(make-variable-buffer-local '2C-window-width)
|
||||||
(put 'tc-window-width 'permanent-local t)
|
(put '2C-window-width 'permanent-local t)
|
||||||
|
|
||||||
(defvar tc-beyond-fill-column 4
|
|
||||||
|
|
||||||
|
(defvar 2C-beyond-fill-column 4
|
||||||
"*Base for calculating `fill-column' for a buffer in two-column minor mode.
|
"*Base for calculating `fill-column' for a buffer in two-column minor mode.
|
||||||
The value of `fill-column' becomes `tc-window-width' for this buffer
|
The value of `fill-column' becomes `2C-window-width' for this buffer
|
||||||
minus this value.")
|
minus this value.")
|
||||||
|
|
||||||
(defvar tc-mode-hook nil
|
|
||||||
"Function called, if non-nil, whenever turning on two-column minor mode.
|
|
||||||
It can get called by \\[tc-two-columns] (tc-two-columns), \\[tc-split] (tc-split)
|
(defvar 2C-autoscroll t
|
||||||
and \\[tc-associate-buffer] (tc-associate-buffer), on both buffers.")
|
"If this is non-nil, Emacs attempts to keep the two buffers aligned.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defvar 2C-autoscroll-start nil)
|
||||||
|
(make-variable-buffer-local '2C-autoscroll-start)
|
||||||
|
|
||||||
;;;;; base functions ;;;;;
|
;;;;; base functions ;;;;;
|
||||||
|
|
||||||
;; the access method for the other buffer. this tries to remedy against
|
;; The access method for the other buffer. This tries to remedy against
|
||||||
;; lost local variables and lost buffers.
|
;; lost local variables and lost buffers.
|
||||||
(defun tc-other ()
|
(defun 2C-other ()
|
||||||
(if tc-other
|
(if 2C-mode
|
||||||
(or (prog1
|
(or (prog1
|
||||||
(marker-buffer tc-other)
|
(marker-buffer 2C-mode)
|
||||||
(setq mode-line-format tc-mode-line-format ))
|
(setq mode-line-format 2C-mode-line-format))
|
||||||
; The associated buffer somehow got killed.
|
;; The associated buffer somehow got killed.
|
||||||
(progn
|
(progn
|
||||||
; The other variables may later be useful if the user
|
;; The other variables may later be useful if the user
|
||||||
; reestablishes the association.
|
;; reestablishes the association.
|
||||||
(kill-local-variable 'tc-other)
|
(kill-local-variable '2C-mode)
|
||||||
(kill-local-variable 'mode-line-format)
|
(kill-local-variable 'mode-line-format)
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun tc-two-columns (&optional buffer)
|
|
||||||
"Split current window vertically for two-column editing.
|
|
||||||
|
|
||||||
When called the first time, associates a buffer with the current
|
|
||||||
buffer. Both buffers are put in two-column minor mode and
|
|
||||||
tc-mode-hook gets called on both. These buffers remember
|
|
||||||
about one another, even when renamed.
|
|
||||||
|
|
||||||
When called again, restores the screen layout with the current buffer
|
;; function for setting up two-column minor mode in a buffer associated
|
||||||
first and the associated buffer to it's right.
|
;; with the buffer pointed to by the marker other.
|
||||||
|
(defun 2C-mode (other)
|
||||||
|
"Minor mode for independently editing two columns.
|
||||||
|
This is set up for two associated buffers by the three commands bound
|
||||||
|
to \\[2C-two-columns] , \\[2C-associate-buffer] and \\[2C-split].
|
||||||
|
Turning on two-column mode calls the value of the variable `2C-mode-hook',
|
||||||
|
if that value is non-nil.
|
||||||
|
|
||||||
|
These buffers can be edited separately, for example with `fill-paragraph'.
|
||||||
|
If you want to disable parallel scrolling temporarily, use \\[2C-toggle-autoscroll] .
|
||||||
|
|
||||||
If you include long lines, i.e which will span both columns (eg.
|
If you include long lines, i.e which will span both columns (eg.
|
||||||
source code), they should be in what will be the first column, with
|
source code), they should be in what will be the first column, with
|
||||||
the associated buffer having empty lines next to them.
|
the associated buffer having empty lines next to them.
|
||||||
|
|
||||||
|
Potential uses are writing bilingual texts, or editing the comments of a
|
||||||
|
source code. See the file lisp/two-column.el for detailed examples.
|
||||||
|
|
||||||
You have the following commands at your disposal:
|
You have the following commands at your disposal:
|
||||||
|
|
||||||
\\[tc-two-columns] Rearrange screen
|
\\[2C-two-columns] Rearrange screen with current buffer first
|
||||||
\\[tc-associate-buffer] Reassociate buffer after changing major mode
|
\\[2C-associate-buffer] Reassociate buffer after changing major mode
|
||||||
\\[tc-scroll-up] Scroll both buffers up by a screenfull
|
|
||||||
\\[tc-scroll-down] Scroll both buffers down by a screenful
|
|
||||||
\\[tc-scroll-line] Scroll both buffers up by one or more lines
|
|
||||||
\\[tc-recenter] Recenter and realign other buffer
|
|
||||||
\\[shrink-window-horizontally], \\[enlarge-window-horizontally] Shrink, enlarge current column
|
\\[shrink-window-horizontally], \\[enlarge-window-horizontally] Shrink, enlarge current column
|
||||||
\\[tc-associated-buffer] Switch to associated buffer
|
\\[2C-associated-buffer] Switch to associated buffer
|
||||||
\\[tc-merge] Merge both buffers
|
\\[2C-merge] Merge both buffers
|
||||||
|
\\[2C-dissociate] Dissociate the two buffers
|
||||||
|
|
||||||
These keybindings can be customized in your ~/.emacs by `tc-prefix'
|
These keybindings can be customized in your ~/.emacs by `2C-mode-map',
|
||||||
and `tc-mode-map'.
|
`2C-minor-mode-map' and by binding `2C-command' to some prefix.
|
||||||
|
|
||||||
The appearance of the screen can be customized by the variables
|
The appearance of the screen can be customized by the variables
|
||||||
`tc-window-width', `tc-beyond-fill-column',
|
`2C-window-width', `2C-beyond-fill-column', `2C-mode-line-format' and
|
||||||
`tc-mode-line-format' and `truncate-partial-width-windows'."
|
`truncate-partial-width-windows'."
|
||||||
|
(make-variable-buffer-local 'post-command-hook)
|
||||||
|
(setq fill-column (- 2C-window-width
|
||||||
|
2C-beyond-fill-column)
|
||||||
|
post-command-hook '2C-autoscroll
|
||||||
|
mode-line-format 2C-mode-line-format
|
||||||
|
2C-mode other)
|
||||||
|
(run-hooks '2C-mode-hook))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun 2C-two-columns (&optional buffer)
|
||||||
|
"Split current window vertically for two-column editing.
|
||||||
|
When called the first time, associates a buffer with the current
|
||||||
|
buffer in two-column minor mode (see \\[describe-mode] ).
|
||||||
|
Runs `2C-other-buffer-hook' in the new buffer.
|
||||||
|
When called again, restores the screen layout with the current buffer
|
||||||
|
first and the associated buffer to it's right."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
; first go to full width, so that we can certainly split into
|
;; first go to full width, so that we can certainly split into two windows
|
||||||
; two windows
|
|
||||||
(if (< (window-width) (frame-width))
|
(if (< (window-width) (frame-width))
|
||||||
(enlarge-window 99999 t))
|
(enlarge-window 99999 t))
|
||||||
(split-window-horizontally
|
(split-window-horizontally
|
||||||
(max window-min-width (min tc-window-width
|
(max window-min-width (min 2C-window-width
|
||||||
(- (frame-width) window-min-width))))
|
(- (frame-width) window-min-width))))
|
||||||
(if (tc-other)
|
(if (2C-other)
|
||||||
(progn
|
(progn
|
||||||
(other-window 1)
|
(other-window 1)
|
||||||
(switch-to-buffer (tc-other))
|
(switch-to-buffer (2C-other))
|
||||||
(other-window -1)
|
(other-window -1)
|
||||||
; align buffers if necessary
|
(if 2C-autoscroll
|
||||||
(tc-scroll-line 0))
|
(2C-toggle-autoscroll t)))
|
||||||
|
|
||||||
|
(2C-mode (prog1 (point-marker)
|
||||||
|
(other-window 1)
|
||||||
|
(switch-to-buffer
|
||||||
|
(or buffer
|
||||||
|
(generate-new-buffer
|
||||||
|
(concat "2C/" (buffer-name)))))
|
||||||
|
(or buffer
|
||||||
|
(run-hooks '2C-other-buffer-hook))))
|
||||||
|
|
||||||
|
(2C-mode (prog1 (point-marker)
|
||||||
|
(other-window -1)))))
|
||||||
|
|
||||||
; set up minor mode linking two buffers
|
|
||||||
(setq fill-column (- tc-window-width
|
|
||||||
tc-beyond-fill-column)
|
|
||||||
mode-line-format tc-mode-line-format)
|
|
||||||
(run-hooks tc-mode-hook)
|
|
||||||
(let ((other (point-marker)))
|
|
||||||
(other-window 1)
|
|
||||||
(switch-to-buffer
|
|
||||||
(or buffer
|
|
||||||
(generate-new-buffer
|
|
||||||
(concat "2C/" (buffer-name)))))
|
|
||||||
(or buffer
|
|
||||||
(text-mode))
|
|
||||||
(setq fill-column (- tc-window-width
|
|
||||||
tc-beyond-fill-column)
|
|
||||||
mode-line-format tc-mode-line-format
|
|
||||||
tc-other other
|
|
||||||
other (point-marker))
|
|
||||||
(run-hooks tc-mode-hook)
|
|
||||||
(other-window -1)
|
|
||||||
(setq tc-other other))))
|
|
||||||
|
|
||||||
(defalias 'tc-mode 'tc-two-columns)
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun tc-associate-buffer ()
|
(defun 2C-associate-buffer ()
|
||||||
"Associate another buffer with this one in two-column minor mode.
|
"Associate another buffer with this one in two-column minor mode.
|
||||||
Can also be used to associate a just previously visited file, by
|
Can also be used to associate a just previously visited file, by
|
||||||
accepting the proposed default buffer.
|
accepting the proposed default buffer.
|
||||||
|
|
||||||
See \\[tc-two-columns] and `lisp/two-column.el' for further details."
|
\(See \\[describe-mode] .)"
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((b1 (current-buffer))
|
(let ((b1 (current-buffer))
|
||||||
(b2 (or (tc-other)
|
(b2 (or (2C-other)
|
||||||
(read-buffer "Associate buffer: " (other-buffer)))))
|
(read-buffer "Associate buffer: " (other-buffer)))))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(setq tc-other nil)
|
(setq 2C-mode nil)
|
||||||
(set-buffer b2)
|
(set-buffer b2)
|
||||||
(and (tc-other)
|
(and (2C-other)
|
||||||
(not (eq b1 (tc-other)))
|
(not (eq b1 (2C-other)))
|
||||||
(error "Buffer already associated with buffer `%s'."
|
(error "Buffer already associated with buffer `%s'."
|
||||||
(buffer-name (tc-other))))
|
(buffer-name (2C-other))))
|
||||||
(setq b1 (and (assq 'tc-window-width (buffer-local-variables))
|
(setq b1 (and (assq '2C-window-width (buffer-local-variables))
|
||||||
tc-window-width)))
|
2C-window-width)))
|
||||||
; if other buffer has a local width, adjust here too
|
; if other buffer has a local width, adjust here too
|
||||||
(if b1 (setq tc-window-width (- (frame-width) b1)))
|
(if b1 (setq 2C-window-width (- (frame-width) b1)))
|
||||||
(tc-two-columns b2)))
|
(2C-two-columns b2)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun tc-split (arg)
|
(defun 2C-split (arg)
|
||||||
"Unmerge a two-column text into two buffers in two-column minor mode.
|
"Split a two-column text at point, into two buffers in two-column minor mode.
|
||||||
The text is unmerged at the cursor's column which becomes the local
|
Point becomes the local value of `2C-window-width'. Only lines that
|
||||||
value of `tc-window-width'. Only lines that have the ARG same
|
have the ARG same preceding characters at that column get split. The
|
||||||
preceding characters at that column get split. The ARG preceding
|
ARG preceding characters without any leading whitespace become the local
|
||||||
characters without any leading whitespace become the local value for
|
value for `2C-separator'. This way lines that continue across both
|
||||||
`tc-separator'. This way lines that continue across both
|
|
||||||
columns remain untouched in the first buffer.
|
columns remain untouched in the first buffer.
|
||||||
|
|
||||||
This function can be used with a prototype line, to set up things as
|
This function can be used with a prototype line, to set up things. You
|
||||||
you like them. You write the first line of each column with the
|
write the first line of each column and then split that line. E.g.:
|
||||||
separator you like and then unmerge that line. E.g.:
|
|
||||||
|
|
||||||
First column's text sSs Second columns text
|
First column's text sSs Second column's text
|
||||||
\\___/\\
|
\\___/\\
|
||||||
/ \\
|
/ \\
|
||||||
5 character Separator You type M-5 \\[tc-split] with the point here
|
5 character Separator You type M-5 \\[2C-split] with the point here.
|
||||||
|
|
||||||
See \\[tc-two-columns] and `lisp/two-column.el' for further details."
|
\(See \\[describe-mode] .)"
|
||||||
(interactive "p")
|
(interactive "*p")
|
||||||
(and (tc-other)
|
(and (2C-other)
|
||||||
(if (y-or-n-p (concat "Overwrite associated buffer `"
|
(if (y-or-n-p (concat "Overwrite associated buffer `"
|
||||||
(buffer-name (tc-other))
|
(buffer-name (2C-other))
|
||||||
"'? "))
|
"'? "))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(set-buffer (tc-other))
|
(set-buffer (2C-other))
|
||||||
(erase-buffer))
|
(erase-buffer))
|
||||||
(signal 'quit nil)))
|
(signal 'quit nil)))
|
||||||
(let ((point (point))
|
(let ((point (point))
|
||||||
|
@ -414,12 +408,12 @@ See \\[tc-two-columns] and `lisp/two-column.el' for further details."
|
||||||
(backward-char arg)
|
(backward-char arg)
|
||||||
(setq chars (buffer-substring (point) point))
|
(setq chars (buffer-substring (point) point))
|
||||||
(skip-chars-forward " \t" point)
|
(skip-chars-forward " \t" point)
|
||||||
(make-local-variable 'tc-separator)
|
(make-local-variable '2C-separator)
|
||||||
(setq tc-separator (buffer-substring (point) point)
|
(setq 2C-separator (buffer-substring (point) point)
|
||||||
tc-window-width (current-column)))
|
2C-window-width (current-column)))
|
||||||
(tc-two-columns)
|
(2C-two-columns)
|
||||||
(setq other (tc-other))
|
(setq other (2C-other))
|
||||||
; now we're ready to actually unmerge
|
; now we're ready to actually split
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(if (not (and (= (current-column) goal-column)
|
(if (not (and (= (current-column) goal-column)
|
||||||
|
@ -443,59 +437,60 @@ See \\[tc-two-columns] and `lisp/two-column.el' for further details."
|
||||||
(setq n 0))
|
(setq n 0))
|
||||||
(next-line 1)))))
|
(next-line 1)))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun tc-dissociate ()
|
|
||||||
|
|
||||||
|
(defun 2C-dissociate ()
|
||||||
"Turn off two-column minor mode in current and associated buffer.
|
"Turn off two-column minor mode in current and associated buffer.
|
||||||
If the associated buffer is unmodified and empty, it is killed."
|
If the associated buffer is unmodified and empty, it is killed."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((buffer (current-buffer)))
|
(let ((buffer (current-buffer)))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(and (tc-other)
|
(and (2C-other)
|
||||||
(set-buffer (tc-other))
|
(set-buffer (2C-other))
|
||||||
(or (not (tc-other))
|
(or (not (2C-other))
|
||||||
(eq buffer (tc-other)))
|
(eq buffer (2C-other)))
|
||||||
(if (and (not (buffer-modified-p))
|
(if (and (not (buffer-modified-p))
|
||||||
(eobp) (bobp))
|
(eobp) (bobp))
|
||||||
(kill-buffer nil)
|
(kill-buffer nil)
|
||||||
(kill-local-variable 'tc-other)
|
(kill-local-variable '2C-mode)
|
||||||
(kill-local-variable 'tc-window-width)
|
(kill-local-variable '2C-window-width)
|
||||||
(kill-local-variable 'tc-separator)
|
(kill-local-variable '2C-separator)
|
||||||
(kill-local-variable 'mode-line-format)
|
(kill-local-variable 'mode-line-format)
|
||||||
(kill-local-variable 'fill-column))))
|
(kill-local-variable 'fill-column))))
|
||||||
(kill-local-variable 'tc-other)
|
(kill-local-variable '2C-mode)
|
||||||
(kill-local-variable 'tc-window-width)
|
(kill-local-variable '2C-window-width)
|
||||||
(kill-local-variable 'tc-separator)
|
(kill-local-variable '2C-separator)
|
||||||
(kill-local-variable 'mode-line-format)
|
(kill-local-variable 'mode-line-format)
|
||||||
(kill-local-variable 'fill-column)))
|
(kill-local-variable 'fill-column)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; this doesn't use yank-rectangle, so that the first column can
|
;; this doesn't use yank-rectangle, so that the first column can
|
||||||
;; contain long lines
|
;; contain long lines
|
||||||
;;;###autoload
|
(defun 2C-merge ()
|
||||||
(defun tc-merge ()
|
|
||||||
"Merges the associated buffer with the current buffer.
|
"Merges the associated buffer with the current buffer.
|
||||||
They get merged at the column, which is the value of
|
They get merged at the column, which is the value of `2C-window-width',
|
||||||
`tc-window-width', i.e. usually at the vertical window
|
i.e. usually at the vertical window separator. This separator gets
|
||||||
separator. This separator gets replaced with white space. Beyond
|
replaced with white space. Beyond that the value of `2C-separator' gets
|
||||||
that the value of gets inserted on merged lines. The two columns are
|
inserted on merged lines. The two columns are thus pasted side by side,
|
||||||
thus pasted side by side, in a single text. If the other buffer is
|
in a single text. If the other buffer is not displayed to the left of
|
||||||
not displayed to the left of this one, then this one becomes the left
|
this one, then this one becomes the left column.
|
||||||
column.
|
|
||||||
|
|
||||||
If you want `tc-separator' on empty lines in the second column,
|
If you want `2C-separator' on empty lines in the second column,
|
||||||
you should put just one space in them. In the final result, you can strip
|
you should put just one space in them. In the final result, you can strip
|
||||||
off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ] + $ RET RET"
|
off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ] + $ RET RET"
|
||||||
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(or (tc-other)
|
(or (2C-other)
|
||||||
(error "You must first set two-column minor mode."))
|
(error "You must first set two-column minor mode."))
|
||||||
(and (> (car (window-edges)) 0) ; not touching left edge of screen
|
(and (> (car (window-edges)) 0) ; not touching left edge of screen
|
||||||
(eq (window-buffer (previous-window))
|
(eq (window-buffer (previous-window))
|
||||||
(tc-other))
|
(2C-other))
|
||||||
(other-window -1))
|
(other-window -1))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((b1 (current-buffer))
|
(let ((b1 (current-buffer))
|
||||||
(b2 (tc-other))
|
(b2 (2C-other))
|
||||||
string)
|
string)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(set-buffer b2)
|
(set-buffer b2)
|
||||||
|
@ -509,8 +504,8 @@ off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ]
|
||||||
(if (string= string "")
|
(if (string= string "")
|
||||||
()
|
()
|
||||||
(end-of-line)
|
(end-of-line)
|
||||||
(indent-to-column tc-window-width)
|
(indent-to-column 2C-window-width)
|
||||||
(insert tc-separator string))
|
(insert 2C-separator string))
|
||||||
(next-line 1) ; add one if necessary
|
(next-line 1) ; add one if necessary
|
||||||
(set-buffer b2))))
|
(set-buffer b2))))
|
||||||
(if (< (window-width) (frame-width))
|
(if (< (window-width) (frame-width))
|
||||||
|
@ -518,86 +513,96 @@ off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ]
|
||||||
|
|
||||||
;;;;; utility functions ;;;;;
|
;;;;; utility functions ;;;;;
|
||||||
|
|
||||||
;;;###autoload
|
(defun 2C-associated-buffer ()
|
||||||
(defun tc-associated-buffer ()
|
|
||||||
"Switch to associated buffer."
|
"Switch to associated buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(or (tc-other)
|
(or (2C-other)
|
||||||
(error "You must set two-column minor mode."))
|
(error "You must set two-column minor mode."))
|
||||||
(if (get-buffer-window (tc-other))
|
(if (get-buffer-window (2C-other))
|
||||||
(select-window (get-buffer-window (tc-other)))
|
(select-window (get-buffer-window (2C-other)))
|
||||||
(switch-to-buffer (tc-other))))
|
(switch-to-buffer (2C-other))))
|
||||||
|
|
||||||
;; It would be desirable to intercept anything that causes the current
|
|
||||||
;; window to scroll. Maybe a `scroll-hook'?
|
|
||||||
;;;###autoload
|
|
||||||
(defun tc-scroll-line (arg)
|
|
||||||
"Scroll current window upward by ARG lines.
|
|
||||||
The associated window gets scrolled to the same line."
|
|
||||||
(interactive "p")
|
|
||||||
(or (tc-other)
|
|
||||||
(error "You must set two-column minor mode."))
|
|
||||||
; scroll-up has a bug on arg 0 at end of buffer
|
|
||||||
(or (zerop arg)
|
|
||||||
(scroll-up arg))
|
|
||||||
(setq arg (count-lines (point-min) (window-start)))
|
|
||||||
; too bad that pre 18.57 Emacs makes save-window-excursion restore
|
|
||||||
; the point. When it becomes extinct, we can simplify this.
|
|
||||||
(if (get-buffer-window (tc-other))
|
|
||||||
(let ((window (selected-window)))
|
|
||||||
(select-window (get-buffer-window (tc-other)))
|
|
||||||
(setq arg (- arg (count-lines (point-min) (window-start))))
|
|
||||||
; make sure that other buffer has enough lines
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-max))
|
|
||||||
(insert-char ?\n
|
|
||||||
(- arg (count-lines (window-start) (point-max)) -1)))
|
|
||||||
(or (zerop arg)
|
|
||||||
(scroll-up arg))
|
|
||||||
(select-window window))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun tc-scroll-up (arg)
|
|
||||||
"Scroll current window upward by ARG screens.
|
|
||||||
The associated window gets scrolled to the same line."
|
|
||||||
(interactive "p")
|
|
||||||
(tc-scroll-line (* arg (- (window-height)
|
|
||||||
next-screen-context-lines 1))))
|
|
||||||
|
|
||||||
;;;###autoload
|
(defun 2C-toggle-autoscroll (arg)
|
||||||
(defun tc-scroll-down (arg)
|
"Toggle autoscrolling, or set it iff prefix ARG is non-nil and positive.
|
||||||
"Scroll current window downward by ARG screens.
|
When autoscrolling is turned on, this also realigns the two buffers."
|
||||||
The associated window gets scrolled to the same line."
|
|
||||||
(interactive "p")
|
|
||||||
(tc-scroll-line (* arg (- next-screen-context-lines
|
|
||||||
(window-height) -1))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun tc-recenter (arg)
|
|
||||||
"Center point in window. With ARG, put point on line ARG.
|
|
||||||
This counts from bottom if ARG is negative. The associated window
|
|
||||||
gets scrolled to the same line."
|
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(setq arg (and arg (prefix-numeric-value arg)))
|
(setq 2C-autoscroll-start (window-start))
|
||||||
(tc-scroll-line (- (count-lines (window-start) (point))
|
(if (setq 2C-autoscroll (if arg
|
||||||
(cond ((null arg) (/ (window-height) 2))
|
(>= (prefix-numeric-value arg) 0)
|
||||||
((< arg 0) (+ (window-height) arg))
|
(not 2C-autoscroll)))
|
||||||
( arg)))))
|
(select-window
|
||||||
|
(prog1 (selected-window)
|
||||||
|
(message "Autoscrolling is on.")
|
||||||
|
(or (2C-other)
|
||||||
|
(error "You must set two-column minor mode."))
|
||||||
|
(setq arg (count-lines (point-min) (window-start)))
|
||||||
|
(if (get-buffer-window (2C-other))
|
||||||
|
(progn
|
||||||
|
(select-window (get-buffer-window (2C-other)))
|
||||||
|
(setq arg (- arg (count-lines (point-min) (window-start))))
|
||||||
|
;; make sure that other buffer has enough lines
|
||||||
|
(save-excursion
|
||||||
|
(insert-char ?\n
|
||||||
|
(- arg (count-lines (window-start)
|
||||||
|
(goto-char (point-max)))
|
||||||
|
-1)))
|
||||||
|
(scroll-up arg)))))
|
||||||
|
(message "Autoscrolling is off.")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defun 2C-autoscroll ()
|
||||||
|
(if 2C-autoscroll
|
||||||
|
;; catch a mouse scroll on non-selected scrollbar
|
||||||
|
(select-window
|
||||||
|
(prog1 (selected-window)
|
||||||
|
(and (consp last-command-char)
|
||||||
|
(not (eq (selected-window)
|
||||||
|
(car (car (cdr last-command-char)))))
|
||||||
|
(select-window (car (car (cdr last-command-char)))))
|
||||||
|
;; In some cases scrolling causes an error, but post-command-hook
|
||||||
|
;; shouldn't, and should always stay in the original window
|
||||||
|
(condition-case ()
|
||||||
|
(and (or 2C-autoscroll-start (2C-toggle-autoscroll t) nil)
|
||||||
|
(/= (window-start) 2C-autoscroll-start)
|
||||||
|
(2C-other)
|
||||||
|
(get-buffer-window (2C-other))
|
||||||
|
(let ((lines (count-lines (window-start)
|
||||||
|
2C-autoscroll-start)))
|
||||||
|
(if (< (window-start) 2C-autoscroll-start)
|
||||||
|
(setq lines (- lines)))
|
||||||
|
(setq 2C-autoscroll-start (window-start))
|
||||||
|
(select-window (get-buffer-window (2C-other)))
|
||||||
|
;; make sure that other buffer has enough lines
|
||||||
|
(save-excursion
|
||||||
|
(insert-char
|
||||||
|
?\n (- lines (count-lines (window-start)
|
||||||
|
(goto-char (point-max)))
|
||||||
|
-1)))
|
||||||
|
(scroll-up lines)
|
||||||
|
(setq 2C-autoscroll-start (window-start))))
|
||||||
|
(error))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun enlarge-window-horizontally (arg)
|
(defun enlarge-window-horizontally (arg)
|
||||||
"Make current window ARG columns wider."
|
"Make current window ARG columns wider."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(enlarge-window arg t)
|
(enlarge-window arg t)
|
||||||
(and (tc-other)
|
(and (2C-other)
|
||||||
(setq tc-window-width (+ tc-window-width arg))
|
(setq 2C-window-width (+ 2C-window-width arg))
|
||||||
(set-buffer (tc-other))
|
(set-buffer (2C-other))
|
||||||
(setq tc-window-width (- tc-window-width arg))))
|
(setq 2C-window-width (- 2C-window-width arg))))
|
||||||
|
|
||||||
(defun shrink-window-horizontally (arg)
|
(defun shrink-window-horizontally (arg)
|
||||||
"Make current window ARG columns narrower."
|
"Make current window ARG columns narrower."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(enlarge-window-horizontally (- arg)))
|
(enlarge-window-horizontally (- arg)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'two-column)
|
(provide 'two-column)
|
||||||
|
|
||||||
;;; two-column.el ends here
|
;;; two-column.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue