diff options
| author | Glenn Morris | 2012-04-16 16:13:38 -0400 |
|---|---|---|
| committer | Glenn Morris | 2012-04-16 16:13:38 -0400 |
| commit | 1197ecfa84c35f9497a340845595e7e1040e455d (patch) | |
| tree | f246fc117c2ca2a8afc784e2bf35864718d3b377 | |
| parent | f45f90f33151dc74ef541cba4fe87565215382a0 (diff) | |
| download | emacs-1197ecfa84c35f9497a340845595e7e1040e455d.tar.gz emacs-1197ecfa84c35f9497a340845595e7e1040e455d.zip | |
two-column.el small cleanup
* lisp/textmodes/two-column.el: Move custom options to the start.
(frame-width): Remove compat definition.
(2C-associate-buffer, 2C-dissociate):
Use with-current-buffer rather than save-excursion.
(2C-dissociate): Force a mode-line update.
(2C-autoscroll): Use ignore-errors.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/textmodes/two-column.el | 204 |
2 files changed, 88 insertions, 123 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 801a5e74804..906adf26971 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -4,6 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | 2012-04-16 Glenn Morris <rgm@gnu.org> | 5 | 2012-04-16 Glenn Morris <rgm@gnu.org> |
| 6 | 6 | ||
| 7 | * textmodes/two-column.el: Move custom options to the start. | ||
| 8 | (frame-width): Remove compat definition. | ||
| 9 | (2C-associate-buffer, 2C-dissociate): | ||
| 10 | Use with-current-buffer rather than save-excursion. | ||
| 11 | (2C-dissociate): Force a mode-line update. | ||
| 12 | (2C-autoscroll): Use ignore-errors. | ||
| 13 | |||
| 7 | * emacs-lisp/eieio-opt.el (describe-class, describe-generic): | 14 | * emacs-lisp/eieio-opt.el (describe-class, describe-generic): |
| 8 | Autoload trivia. | 15 | Autoload trivia. |
| 9 | 16 | ||
diff --git a/lisp/textmodes/two-column.el b/lisp/textmodes/two-column.el index 40cbbc59292..8a4fe4f87fd 100644 --- a/lisp/textmodes/two-column.el +++ b/lisp/textmodes/two-column.el | |||
| @@ -124,15 +124,51 @@ | |||
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | ;;; Code: | 126 | ;;; Code: |
| 127 | 127 | (defgroup two-column nil | |
| 128 | "Minor mode for editing of two-column text." | ||
| 129 | :prefix "2C-" | ||
| 130 | :group 'frames) | ||
| 131 | |||
| 132 | (defcustom 2C-mode-line-format | ||
| 133 | '("-%*- %15b --" (-3 . "%p") "--%[(" mode-name | ||
| 134 | minor-mode-alist "%n" mode-line-process ")%]%-") | ||
| 135 | "Value of `mode-line-format' for a buffer in two-column minor mode." | ||
| 136 | :type 'sexp | ||
| 137 | :group 'two-column) | ||
| 138 | |||
| 139 | (defcustom 2C-other-buffer-hook 'text-mode | ||
| 140 | "Hook run in new buffer when it is associated with current one." | ||
| 141 | :type 'function | ||
| 142 | :group 'two-column) | ||
| 128 | 143 | ||
| 129 | ;; Lucid patch | 144 | (defcustom 2C-separator "" |
| 130 | (or (fboundp 'frame-width) | 145 | "A string inserted between the two columns when merging. |
| 131 | (fset 'frame-width 'screen-width)) | 146 | This gets set locally by \\[2C-split]." |
| 147 | :type 'string | ||
| 148 | :group 'two-column) | ||
| 149 | (put '2C-separator 'permanent-local t) | ||
| 150 | |||
| 151 | (defcustom 2C-window-width 40 | ||
| 152 | "The width of the first column. (Must be at least `window-min-width'.) | ||
| 153 | This value is local for every buffer that sets it." | ||
| 154 | :type 'integer | ||
| 155 | :group 'two-column) | ||
| 156 | (make-variable-buffer-local '2C-window-width) | ||
| 157 | (put '2C-window-width 'permanent-local t) | ||
| 132 | 158 | ||
| 159 | (defcustom 2C-beyond-fill-column 4 | ||
| 160 | "Base for calculating `fill-column' for a buffer in two-column minor mode. | ||
| 161 | The value of `fill-column' becomes `2C-window-width' for this buffer | ||
| 162 | minus this value." | ||
| 163 | :type 'integer | ||
| 164 | :group 'two-column) | ||
| 133 | 165 | ||
| 134 | ;;;;; Set up keymap ;;;;; | 166 | (defcustom 2C-autoscroll t |
| 167 | "If non-nil, Emacs attempts to keep the two column's buffers aligned." | ||
| 168 | :type 'boolean | ||
| 169 | :group 'two-column) | ||
| 135 | 170 | ||
| 171 | |||
| 136 | (defvar 2C-mode-map | 172 | (defvar 2C-mode-map |
| 137 | (let ((map (make-sparse-keymap))) | 173 | (let ((map (make-sparse-keymap))) |
| 138 | (define-key map "2" '2C-two-columns) | 174 | (define-key map "2" '2C-two-columns) |
| @@ -142,8 +178,6 @@ | |||
| 142 | map) | 178 | map) |
| 143 | "Keymap for commands for setting up two-column mode.") | 179 | "Keymap for commands for setting up two-column mode.") |
| 144 | 180 | ||
| 145 | |||
| 146 | |||
| 147 | ;;;###autoload (autoload '2C-command "two-column" () t 'keymap) | 181 | ;;;###autoload (autoload '2C-command "two-column" () t 'keymap) |
| 148 | (fset '2C-command 2C-mode-map) | 182 | (fset '2C-command 2C-mode-map) |
| 149 | 183 | ||
| @@ -154,7 +188,6 @@ | |||
| 154 | 188 | ||
| 155 | ;;;###autoload (global-set-key [f2] '2C-command) | 189 | ;;;###autoload (global-set-key [f2] '2C-command) |
| 156 | 190 | ||
| 157 | |||
| 158 | (defvar 2C-minor-mode-map | 191 | (defvar 2C-minor-mode-map |
| 159 | (let ((map (make-sparse-keymap))) | 192 | (let ((map (make-sparse-keymap))) |
| 160 | (define-key map "1" '2C-merge) | 193 | (define-key map "1" '2C-merge) |
| @@ -167,7 +200,6 @@ | |||
| 167 | map) | 200 | map) |
| 168 | "Keymap for commands for use in two-column mode.") | 201 | "Keymap for commands for use in two-column mode.") |
| 169 | 202 | ||
| 170 | |||
| 171 | (setq minor-mode-map-alist | 203 | (setq minor-mode-map-alist |
| 172 | (cons (cons '2C-mode | 204 | (cons (cons '2C-mode |
| 173 | (let ((map (make-sparse-keymap))) | 205 | (let ((map (make-sparse-keymap))) |
| @@ -181,15 +213,8 @@ | |||
| 181 | map (current-global-map)) | 213 | map (current-global-map)) |
| 182 | map)) | 214 | map)) |
| 183 | minor-mode-map-alist)) | 215 | minor-mode-map-alist)) |
| 184 | |||
| 185 | ;;;;; variable declarations ;;;;; | ||
| 186 | |||
| 187 | (defgroup two-column nil | ||
| 188 | "Minor mode for editing of two-column text." | ||
| 189 | :prefix "2C-" | ||
| 190 | :group 'frames) | ||
| 191 | |||
| 192 | 216 | ||
| 217 | |||
| 193 | ;; Markers seem to be the only buffer-id not affected by renaming a buffer. | 218 | ;; Markers seem to be the only buffer-id not affected by renaming a buffer. |
| 194 | ;; This nevertheless loses when a buffer is killed. The variable-name is | 219 | ;; This nevertheless loses when a buffer is killed. The variable-name is |
| 195 | ;; required by `describe-mode'. | 220 | ;; required by `describe-mode'. |
| @@ -198,62 +223,8 @@ | |||
| 198 | (make-variable-buffer-local '2C-mode) | 223 | (make-variable-buffer-local '2C-mode) |
| 199 | (put '2C-mode 'permanent-local t) | 224 | (put '2C-mode 'permanent-local t) |
| 200 | 225 | ||
| 201 | |||
| 202 | |||
| 203 | (setq minor-mode-alist (cons '(2C-mode " 2C") minor-mode-alist)) | 226 | (setq minor-mode-alist (cons '(2C-mode " 2C") minor-mode-alist)) |
| 204 | 227 | ||
| 205 | |||
| 206 | |||
| 207 | ;; rearranged, so that the pertinent info will show in 40 columns | ||
| 208 | (defcustom 2C-mode-line-format | ||
| 209 | '("-%*- %15b --" (-3 . "%p") "--%[(" mode-name | ||
| 210 | minor-mode-alist "%n" mode-line-process ")%]%-") | ||
| 211 | "Value of `mode-line-format' for a buffer in two-column minor mode." | ||
| 212 | :type 'sexp | ||
| 213 | :group 'two-column) | ||
| 214 | |||
| 215 | |||
| 216 | (defcustom 2C-other-buffer-hook 'text-mode | ||
| 217 | "Hook run in new buffer when it is associated with current one." | ||
| 218 | :type 'function | ||
| 219 | :group 'two-column) | ||
| 220 | |||
| 221 | |||
| 222 | (defcustom 2C-separator "" | ||
| 223 | "A string inserted between the two columns when merging. | ||
| 224 | This gets set locally by \\[2C-split]." | ||
| 225 | :type 'string | ||
| 226 | :group 'two-column) | ||
| 227 | (put '2C-separator 'permanent-local t) | ||
| 228 | |||
| 229 | |||
| 230 | |||
| 231 | (defcustom 2C-window-width 40 | ||
| 232 | "The width of the first column. (Must be at least `window-min-width') | ||
| 233 | This value is local for every buffer that sets it." | ||
| 234 | :type 'integer | ||
| 235 | :group 'two-column) | ||
| 236 | (make-variable-buffer-local '2C-window-width) | ||
| 237 | (put '2C-window-width 'permanent-local t) | ||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | (defcustom 2C-beyond-fill-column 4 | ||
| 242 | "Base for calculating `fill-column' for a buffer in two-column minor mode. | ||
| 243 | The value of `fill-column' becomes `2C-window-width' for this buffer | ||
| 244 | minus this value." | ||
| 245 | :type 'integer | ||
| 246 | :group 'two-column) | ||
| 247 | |||
| 248 | |||
| 249 | |||
| 250 | (defcustom 2C-autoscroll t | ||
| 251 | "If non-nil, Emacs attempts to keep the two column's buffers aligned." | ||
| 252 | :type 'boolean | ||
| 253 | :group 'two-column) | ||
| 254 | |||
| 255 | |||
| 256 | |||
| 257 | (defvar 2C-autoscroll-start nil) | 228 | (defvar 2C-autoscroll-start nil) |
| 258 | (make-variable-buffer-local '2C-autoscroll-start) | 229 | (make-variable-buffer-local '2C-autoscroll-start) |
| 259 | 230 | ||
| @@ -276,7 +247,6 @@ minus this value." | |||
| 276 | (if req (error "You must first set two-column minor mode")))) | 247 | (if req (error "You must first set two-column minor mode")))) |
| 277 | 248 | ||
| 278 | 249 | ||
| 279 | |||
| 280 | ;; function for setting up two-column minor mode in a buffer associated | 250 | ;; function for setting up two-column minor mode in a buffer associated |
| 281 | ;; with the buffer pointed to by the marker other. | 251 | ;; with the buffer pointed to by the marker other. |
| 282 | (defun 2C-mode (other) | 252 | (defun 2C-mode (other) |
| @@ -320,7 +290,6 @@ The appearance of the screen can be customized by the variables | |||
| 320 | (run-hooks '2C-mode-hook)) | 290 | (run-hooks '2C-mode-hook)) |
| 321 | 291 | ||
| 322 | 292 | ||
| 323 | |||
| 324 | ;;;###autoload | 293 | ;;;###autoload |
| 325 | (defun 2C-two-columns (&optional buffer) | 294 | (defun 2C-two-columns (&optional buffer) |
| 326 | "Split current window vertically for two-column editing. | 295 | "Split current window vertically for two-column editing. |
| @@ -356,7 +325,6 @@ first and the associated buffer to its right." | |||
| 356 | (other-window -1))))) | 325 | (other-window -1))))) |
| 357 | 326 | ||
| 358 | 327 | ||
| 359 | |||
| 360 | ;;;###autoload | 328 | ;;;###autoload |
| 361 | (defun 2C-associate-buffer () | 329 | (defun 2C-associate-buffer () |
| 362 | "Associate another buffer with this one in two-column minor mode. | 330 | "Associate another buffer with this one in two-column minor mode. |
| @@ -368,9 +336,8 @@ accepting the proposed default buffer. | |||
| 368 | (let ((b1 (current-buffer)) | 336 | (let ((b1 (current-buffer)) |
| 369 | (b2 (or (2C-other) | 337 | (b2 (or (2C-other) |
| 370 | (read-buffer "Associate buffer: " (other-buffer))))) | 338 | (read-buffer "Associate buffer: " (other-buffer))))) |
| 371 | (save-excursion | 339 | (setq 2C-mode nil) |
| 372 | (setq 2C-mode nil) | 340 | (with-current-buffer b2 |
| 373 | (set-buffer b2) | ||
| 374 | (and (2C-other) | 341 | (and (2C-other) |
| 375 | (not (eq b1 (2C-other))) | 342 | (not (eq b1 (2C-other))) |
| 376 | (error "Buffer already associated with buffer `%s'" | 343 | (error "Buffer already associated with buffer `%s'" |
| @@ -382,7 +349,6 @@ accepting the proposed default buffer. | |||
| 382 | (2C-two-columns b2))) | 349 | (2C-two-columns b2))) |
| 383 | 350 | ||
| 384 | 351 | ||
| 385 | |||
| 386 | ;;;###autoload | 352 | ;;;###autoload |
| 387 | (defun 2C-split (arg) | 353 | (defun 2C-split (arg) |
| 388 | "Split a two-column text at point, into two buffers in two-column minor mode. | 354 | "Split a two-column text at point, into two buffers in two-column minor mode. |
| @@ -454,32 +420,28 @@ First column's text sSs Second column's text | |||
| 454 | (move-to-column column))))) | 420 | (move-to-column column))))) |
| 455 | 421 | ||
| 456 | 422 | ||
| 457 | |||
| 458 | |||
| 459 | (defun 2C-dissociate () | 423 | (defun 2C-dissociate () |
| 460 | "Turn off two-column minor mode in current and associated buffer. | 424 | "Turn off two-column minor mode in current and associated buffer. |
| 461 | If the associated buffer is unmodified and empty, it is killed." | 425 | If the associated buffer is unmodified and empty, it is killed." |
| 462 | (interactive) | 426 | (interactive) |
| 463 | (let ((buffer (current-buffer))) | 427 | (let ((buffer (current-buffer)) |
| 464 | (save-excursion | 428 | (other (2C-other))) |
| 465 | (and (2C-other) | 429 | (if other |
| 466 | (set-buffer (2C-other)) | 430 | (with-current-buffer other |
| 467 | (or (not (2C-other)) | 431 | (when (or (not (2C-other)) (eq buffer (2C-other))) |
| 468 | (eq buffer (2C-other))) | 432 | (if (and (not (buffer-modified-p)) (zerop (buffer-size))) |
| 469 | (if (and (not (buffer-modified-p)) | 433 | (kill-buffer) |
| 470 | (eobp) (bobp)) | 434 | (kill-local-variable '2C-mode) |
| 471 | (kill-buffer nil) | 435 | (kill-local-variable '2C-window-width) |
| 472 | (kill-local-variable '2C-mode) | 436 | (kill-local-variable '2C-separator) |
| 473 | (kill-local-variable '2C-window-width) | 437 | (kill-local-variable 'mode-line-format) |
| 474 | (kill-local-variable '2C-separator) | 438 | (kill-local-variable 'fill-column)))))) |
| 475 | (kill-local-variable 'mode-line-format) | 439 | (kill-local-variable '2C-mode) |
| 476 | (kill-local-variable 'fill-column)))) | 440 | (kill-local-variable '2C-window-width) |
| 477 | (kill-local-variable '2C-mode) | 441 | (kill-local-variable '2C-separator) |
| 478 | (kill-local-variable '2C-window-width) | 442 | (kill-local-variable 'mode-line-format) |
| 479 | (kill-local-variable '2C-separator) | 443 | (kill-local-variable 'fill-column) |
| 480 | (kill-local-variable 'mode-line-format) | 444 | (force-mode-line-update)) |
| 481 | (kill-local-variable 'fill-column))) | ||
| 482 | |||
| 483 | 445 | ||
| 484 | 446 | ||
| 485 | ;; this doesn't use yank-rectangle, so that the first column can | 447 | ;; this doesn't use yank-rectangle, so that the first column can |
| @@ -578,7 +540,6 @@ on, this also realigns the two buffers." | |||
| 578 | (message "Autoscrolling is off."))) | 540 | (message "Autoscrolling is off."))) |
| 579 | 541 | ||
| 580 | 542 | ||
| 581 | |||
| 582 | (defun 2C-autoscroll () | 543 | (defun 2C-autoscroll () |
| 583 | (if 2C-autoscroll | 544 | (if 2C-autoscroll |
| 584 | ;; catch a mouse scroll on non-selected scrollbar | 545 | ;; catch a mouse scroll on non-selected scrollbar |
| @@ -590,27 +551,25 @@ on, this also realigns the two buffers." | |||
| 590 | (select-window (car (car (cdr last-command-event))))) | 551 | (select-window (car (car (cdr last-command-event))))) |
| 591 | ;; In some cases scrolling causes an error, but post-command-hook | 552 | ;; In some cases scrolling causes an error, but post-command-hook |
| 592 | ;; shouldn't, and should always stay in the original window | 553 | ;; shouldn't, and should always stay in the original window |
| 593 | (condition-case () | 554 | (ignore-errors |
| 594 | (and (or 2C-autoscroll-start (2C-toggle-autoscroll t) nil) | 555 | (and (or 2C-autoscroll-start (2C-toggle-autoscroll t) nil) |
| 595 | (/= (window-start) 2C-autoscroll-start) | 556 | (/= (window-start) 2C-autoscroll-start) |
| 596 | (2C-other) | 557 | (2C-other) |
| 597 | (get-buffer-window (2C-other)) | 558 | (get-buffer-window (2C-other)) |
| 598 | (let ((lines (count-lines (window-start) | 559 | (let ((lines (count-lines (window-start) |
| 599 | 2C-autoscroll-start))) | 560 | 2C-autoscroll-start))) |
| 600 | (if (< (window-start) 2C-autoscroll-start) | 561 | (if (< (window-start) 2C-autoscroll-start) |
| 601 | (setq lines (- lines))) | 562 | (setq lines (- lines))) |
| 602 | (setq 2C-autoscroll-start (window-start)) | 563 | (setq 2C-autoscroll-start (window-start)) |
| 603 | (select-window (get-buffer-window (2C-other))) | 564 | (select-window (get-buffer-window (2C-other))) |
| 604 | ;; make sure that other buffer has enough lines | 565 | ;; make sure that other buffer has enough lines |
| 605 | (save-excursion | 566 | (save-excursion |
| 606 | (insert-char | 567 | (insert-char |
| 607 | ?\n (- lines (count-lines (window-start) | 568 | ?\n (- lines (count-lines (window-start) |
| 608 | (goto-char (point-max))) | 569 | (goto-char (point-max))) |
| 609 | -1))) | 570 | -1))) |
| 610 | (scroll-up lines) | 571 | (scroll-up lines) |
| 611 | (setq 2C-autoscroll-start (window-start)))) | 572 | (setq 2C-autoscroll-start (window-start))))))))) |
| 612 | (error)))))) | ||
| 613 | |||
| 614 | 573 | ||
| 615 | 574 | ||
| 616 | (defun 2C-enlarge-window-horizontally (arg) | 575 | (defun 2C-enlarge-window-horizontally (arg) |
| @@ -628,7 +587,6 @@ on, this also realigns the two buffers." | |||
| 628 | (2C-enlarge-window-horizontally (- arg))) | 587 | (2C-enlarge-window-horizontally (- arg))) |
| 629 | 588 | ||
| 630 | 589 | ||
| 631 | |||
| 632 | (provide 'two-column) | 590 | (provide 'two-column) |
| 633 | 591 | ||
| 634 | ;;; two-column.el ends here | 592 | ;;; two-column.el ends here |