comparison lisp/textmodes/two-column.el @ 12739:ae2e8daffa31

(2C-toggle-autoscroll, 2C-autoscroll): Only (sit-for 0) once for smoother scrolling. (2C-associated-buffer): go to same line and column. (2C-newline): new function. (2C-other): optional arg to signal missing other buffer.
author Karl Heuer <kwzh@gnu.org>
date Tue, 01 Aug 1995 22:42:28 +0000
parents 5dc02bbeb4be
children 7fd541abf2af
comparison
equal deleted inserted replaced
12738:d06973e701f8 12739:ae2e8daffa31
28 ;; Vi devus ricevinti kopion de la GNU You should have received a copy of 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 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 30 ;; GNU Emacs; vidu la dosieron COPYING. with GNU Emacs; see the file
31 ;; Alikaze skribu al la COPYING. If not, write to the 31 ;; Alikaze skribu al la COPYING. If not, write to the
32 32
33 ;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 33 ;; Free Software Foundation, 59 Temple Place - Suite 330
34 ;; Boston, MA 02111-1307, USA.
34 35
35 36
36 ;;; Komentario: Commentary: 37 ;;; Komentario: Commentary:
37 38
38 ;; Tiu programaro ebligas vin redakti This package gives you the ability 39 ;; Tiu programaro ebligas vin redakti This package gives you the ability
173 (defvar 2C-minor-mode-map 174 (defvar 2C-minor-mode-map
174 (let ((map (make-sparse-keymap))) 175 (let ((map (make-sparse-keymap)))
175 (define-key map "1" '2C-merge) 176 (define-key map "1" '2C-merge)
176 (define-key map "d" '2C-dissociate) 177 (define-key map "d" '2C-dissociate)
177 (define-key map "o" '2C-associated-buffer) 178 (define-key map "o" '2C-associated-buffer)
179 (define-key map "\^m" '2C-newline)
178 (define-key map "|" '2C-toggle-autoscroll) 180 (define-key map "|" '2C-toggle-autoscroll)
179 map) 181 map)
180 "Keymap for commands for use in two-column mode.") 182 "Keymap for commands for use in two-column mode.")
181 183
182 184
236 minus this value.") 238 minus this value.")
237 239
238 240
239 241
240 (defvar 2C-autoscroll t 242 (defvar 2C-autoscroll t
241 "If this is non-nil, Emacs attempts to keep the two buffers aligned.") 243 "If non-nil, Emacs attempts to keep the two column's buffers aligned.")
242 244
243 245
244 246
245 (defvar 2C-autoscroll-start nil) 247 (defvar 2C-autoscroll-start nil)
246 (make-variable-buffer-local '2C-autoscroll-start) 248 (make-variable-buffer-local '2C-autoscroll-start)
247 249
248 ;;;;; base functions ;;;;; 250 ;;;;; base functions ;;;;;
249 251
250 ;; The access method for the other buffer. This tries to remedy against 252 ;; The access method for the other buffer. This tries to remedy against
251 ;; lost local variables and lost buffers. 253 ;; lost local variables and lost buffers.
252 (defun 2C-other () 254 (defun 2C-other (&optional req)
253 (if 2C-mode 255 (or (if 2C-mode
254 (or (prog1 256 (or (prog1
255 (marker-buffer 2C-mode) 257 (marker-buffer 2C-mode)
256 (setq mode-line-format 2C-mode-line-format)) 258 (setq mode-line-format 2C-mode-line-format))
257 ;; The associated buffer somehow got killed. 259 ;; The associated buffer somehow got killed.
258 (progn 260 (progn
259 ;; The other variables may later be useful if the user 261 ;; The other variables may later be useful if the user
260 ;; reestablishes the association. 262 ;; reestablishes the association.
261 (kill-local-variable '2C-mode) 263 (kill-local-variable '2C-mode)
262 (kill-local-variable 'mode-line-format) 264 (kill-local-variable 'mode-line-format)
263 nil)))) 265 nil)))
266 (if req (error "You must first set two-column minor mode."))))
264 267
265 268
266 269
267 ;; function for setting up two-column minor mode in a buffer associated 270 ;; function for setting up two-column minor mode in a buffer associated
268 ;; with the buffer pointed to by the marker other. 271 ;; with the buffer pointed to by the marker other.
286 You have the following commands at your disposal: 289 You have the following commands at your disposal:
287 290
288 \\[2C-two-columns] Rearrange screen with current buffer first 291 \\[2C-two-columns] Rearrange screen with current buffer first
289 \\[2C-associate-buffer] Reassociate buffer after changing major mode 292 \\[2C-associate-buffer] Reassociate buffer after changing major mode
290 \\[shrink-window-horizontally], \\[enlarge-window-horizontally] Shrink, enlarge current column 293 \\[shrink-window-horizontally], \\[enlarge-window-horizontally] Shrink, enlarge current column
291 \\[2C-associated-buffer] Switch to associated buffer 294 \\[2C-associated-buffer] Switch to associated buffer at same point
295 \\[2C-newline] Insert newline(s) in both buffers at same point
292 \\[2C-merge] Merge both buffers 296 \\[2C-merge] Merge both buffers
293 \\[2C-dissociate] Dissociate the two buffers 297 \\[2C-dissociate] Dissociate the two buffers
294 298
295 These keybindings can be customized in your ~/.emacs by `2C-mode-map', 299 These keybindings can be customized in your ~/.emacs by `2C-mode-map',
296 `2C-minor-mode-map' and by binding `2C-command' to some prefix. 300 `2C-minor-mode-map' and by binding `2C-command' to some prefix.
333 337
334 (2C-mode (prog1 (point-marker) 338 (2C-mode (prog1 (point-marker)
335 (other-window 1) 339 (other-window 1)
336 (switch-to-buffer 340 (switch-to-buffer
337 (or buffer 341 (or buffer
338 (generate-new-buffer 342 (generate-new-buffer (concat "2C/" (buffer-name)))))
339 (concat "2C/" (buffer-name)))))
340 (or buffer 343 (or buffer
341 (run-hooks '2C-other-buffer-hook)))) 344 (run-hooks '2C-other-buffer-hook))))
342 345
343 (2C-mode (prog1 (point-marker) 346 (2C-mode (prog1 (point-marker)
344 (other-window -1))))) 347 (other-window -1)))))
478 this one, then this one becomes the left column. 481 this one, then this one becomes the left column.
479 482
480 If you want `2C-separator' on empty lines in the second column, 483 If you want `2C-separator' on empty lines in the second column,
481 you should put just one space in them. In the final result, you can strip 484 you should put just one space in them. In the final result, you can strip
482 off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ] + $ RET RET" 485 off trailing spaces with \\[beginning-of-buffer] \\[replace-regexp] [ SPC TAB ] + $ RET RET"
483
484 (interactive) 486 (interactive)
485 (or (2C-other)
486 (error "You must first set two-column minor mode."))
487 (and (> (car (window-edges)) 0) ; not touching left edge of screen 487 (and (> (car (window-edges)) 0) ; not touching left edge of screen
488 (eq (window-buffer (previous-window)) 488 (eq (window-buffer (previous-window))
489 (2C-other)) 489 (2C-other t))
490 (other-window -1)) 490 (other-window -1))
491 (save-excursion 491 (save-excursion
492 (let ((b1 (current-buffer)) 492 (let ((b1 (current-buffer))
493 (b2 (2C-other)) 493 (b2 (2C-other t))
494 string) 494 string)
495 (goto-char (point-min)) 495 (goto-char (point-min))
496 (set-buffer b2) 496 (set-buffer b2)
497 (goto-char (point-min)) 497 (goto-char (point-min))
498 (while (not (eobp)) 498 (while (not (eobp))
514 ;;;;; utility functions ;;;;; 514 ;;;;; utility functions ;;;;;
515 515
516 (defun 2C-associated-buffer () 516 (defun 2C-associated-buffer ()
517 "Switch to associated buffer." 517 "Switch to associated buffer."
518 (interactive) 518 (interactive)
519 (or (2C-other) 519 (let ((line (+ (count-lines (point-min) (point))
520 (error "You must set two-column minor mode.")) 520 (if (bolp) 1 0)))
521 (if (get-buffer-window (2C-other)) 521 (col (if (eolp) (if (bolp) 0) (current-column))))
522 (select-window (get-buffer-window (2C-other))) 522 (if (get-buffer-window (2C-other t))
523 (switch-to-buffer (2C-other)))) 523 (select-window (get-buffer-window (2C-other)))
524 524 (switch-to-buffer (2C-other)))
525 525 (newline (goto-line line))
526 (if col
527 (move-to-column col)
528 (end-of-line 1))))
529
530 (defun 2C-newline (arg)
531 "Insert ARG newlines in both buffers."
532 (interactive "P")
533 (save-window-excursion
534 (2C-associated-buffer)
535 (newline arg))
536 (newline arg))
526 537
527 (defun 2C-toggle-autoscroll (arg) 538 (defun 2C-toggle-autoscroll (arg)
528 "Toggle autoscrolling, or set it iff prefix ARG is non-nil and positive. 539 "Toggle autoscrolling, or set it iff prefix ARG is non-nil and positive.
529 When autoscrolling is turned on, this also realigns the two buffers." 540 When autoscrolling is turned on, this also realigns the two buffers."
530 (interactive "P") 541 (interactive "P")
542 ;(sit-for 0)
531 (setq 2C-autoscroll-start (window-start)) 543 (setq 2C-autoscroll-start (window-start))
532 (if (setq 2C-autoscroll (if arg 544 (if (setq 2C-autoscroll (if arg
533 (>= (prefix-numeric-value arg) 0) 545 (>= (prefix-numeric-value arg) 0)
534 (not 2C-autoscroll))) 546 (not 2C-autoscroll)))
535 (select-window 547 (select-window
536 (prog1 (selected-window) 548 (prog1 (selected-window)
537 (message "Autoscrolling is on.") 549 (message "Autoscrolling is on.")
538 (or (2C-other)
539 (error "You must set two-column minor mode."))
540 (setq arg (count-lines (point-min) (window-start))) 550 (setq arg (count-lines (point-min) (window-start)))
541 (if (get-buffer-window (2C-other)) 551 (if (get-buffer-window (2C-other t))
542 (progn 552 (progn
543 (select-window (get-buffer-window (2C-other))) 553 (select-window (get-buffer-window (2C-other)))
544 (setq arg (- arg (count-lines (point-min) (window-start)))) 554 (setq arg (- arg (count-lines (point-min) (window-start))))
545 ;; make sure that other buffer has enough lines 555 ;; make sure that other buffer has enough lines
546 (save-excursion 556 (save-excursion