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