diff options
| author | Stefan Monnier | 2007-07-10 17:47:32 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-07-10 17:47:32 +0000 |
| commit | 7dcef48dd27e6d41b1d9cfab9d33160a15f4fe55 (patch) | |
| tree | 643f0e4cf70d736d4f2e93bbf321c94bd4d58028 | |
| parent | d3883360012de25fbf4654deb0a37a0919ab830a (diff) | |
| download | emacs-7dcef48dd27e6d41b1d9cfab9d33160a15f4fe55.tar.gz emacs-7dcef48dd27e6d41b1d9cfab9d33160a15f4fe55.zip | |
Don't change the global map from the follow-mode-map defvar, but from the
toplevel. Use easy-menu to unify the Emacs and XEmacs code.
(turn-on-follow-mode, turn-off-follow-mode): Remove interactive spec
since `follow-mode' should be used instead for that.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/follow.el | 168 |
2 files changed, 50 insertions, 124 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0c85aa3bfcb..babcb63d9c8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2007-07-10 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2007-07-10 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * follow.el: Don't change the global map from the follow-mode-map | ||
| 4 | defvar, but from the toplevel. Use easy-menu to unify the Emacs and | ||
| 5 | XEmacs code. | ||
| 6 | (turn-on-follow-mode, turn-off-follow-mode): Remove interactive spec | ||
| 7 | since `follow-mode' should be used instead for that. | ||
| 8 | |||
| 3 | * emacs-lisp/easymenu.el (easy-menu-binding): New function. | 9 | * emacs-lisp/easymenu.el (easy-menu-binding): New function. |
| 4 | (easy-menu-do-define): Use it. | 10 | (easy-menu-do-define): Use it. |
| 5 | (easy-menu-do-add-item): Inline into easy-menu-add-item and then remove. | 11 | (easy-menu-do-add-item): Inline into easy-menu-add-item and then remove. |
diff --git a/lisp/follow.el b/lisp/follow.el index 048db9bf11a..15d263d300d 100644 --- a/lisp/follow.el +++ b/lisp/follow.el | |||
| @@ -336,123 +336,45 @@ After that, changing the prefix key requires manipulating keymaps." | |||
| 336 | ;; the look and feel of Follow mode.) | 336 | ;; the look and feel of Follow mode.) |
| 337 | (define-key mainmap [remap end-of-buffer] 'follow-end-of-buffer) | 337 | (define-key mainmap [remap end-of-buffer] 'follow-end-of-buffer) |
| 338 | 338 | ||
| 339 | ;; | ||
| 340 | ;; The menu. | ||
| 341 | ;; | ||
| 342 | |||
| 343 | (if (not (featurep 'xemacs)) | ||
| 344 | |||
| 345 | ;; | ||
| 346 | ;; Emacs | ||
| 347 | ;; | ||
| 348 | (let ((menumap (funcall (symbol-function 'make-sparse-keymap) | ||
| 349 | "Follow")) | ||
| 350 | (count 0) | ||
| 351 | id) | ||
| 352 | (mapcar | ||
| 353 | (function | ||
| 354 | (lambda (item) | ||
| 355 | (setq id | ||
| 356 | (or (cdr item) | ||
| 357 | (progn | ||
| 358 | (setq count (+ count 1)) | ||
| 359 | (intern (format "separator-%d" count))))) | ||
| 360 | (define-key menumap (vector id) item) | ||
| 361 | (or (eq id 'follow-mode) | ||
| 362 | (put id 'menu-enable 'follow-mode)))) | ||
| 363 | ;; In reverse order: | ||
| 364 | '(("Toggle Follow mode" . follow-mode) | ||
| 365 | ("--") | ||
| 366 | ("Recenter" . follow-recenter) | ||
| 367 | ("--") | ||
| 368 | ("Previous Window" . follow-previous-window) | ||
| 369 | ("Next Windows" . follow-next-window) | ||
| 370 | ("Last Window" . follow-last-window) | ||
| 371 | ("First Window" . follow-first-window) | ||
| 372 | ("--") | ||
| 373 | ("Switch To Buffer (all windows)" | ||
| 374 | . follow-switch-to-buffer-all) | ||
| 375 | ("Switch To Buffer" . follow-switch-to-buffer) | ||
| 376 | ("--") | ||
| 377 | ("Delete Other Windows and Split" | ||
| 378 | . follow-delete-other-windows-and-split) | ||
| 379 | ("--") | ||
| 380 | ("Scroll Down" . follow-scroll-down) | ||
| 381 | ("Scroll Up" . follow-scroll-up))) | ||
| 382 | |||
| 383 | ;; If there is a `tools' menu, we use it. However, we can't add a | ||
| 384 | ;; minor-mode specific item to it (it's broken), so we make the | ||
| 385 | ;; contents ghosted when not in use, and add ourselves to the | ||
| 386 | ;; global map. If no `tools' menu is present, just make a | ||
| 387 | ;; top-level menu visible when the mode is activated. | ||
| 388 | |||
| 389 | (let ((tools-map (lookup-key (current-global-map) [menu-bar tools])) | ||
| 390 | (last nil)) | ||
| 391 | (if (sequencep tools-map) | ||
| 392 | (progn | ||
| 393 | ;; Find the last entry in the menu and store it in `last'. | ||
| 394 | (mapcar (function | ||
| 395 | (lambda (x) | ||
| 396 | (setq last (or (cdr-safe | ||
| 397 | (cdr-safe | ||
| 398 | (cdr-safe x))) | ||
| 399 | last)))) | ||
| 400 | tools-map) | ||
| 401 | (if last | ||
| 402 | (progn | ||
| 403 | (funcall (symbol-function 'define-key-after) | ||
| 404 | tools-map [separator-follow] '("--") last) | ||
| 405 | (funcall (symbol-function 'define-key-after) | ||
| 406 | tools-map [follow] (cons "Follow" menumap) | ||
| 407 | 'separator-follow)) | ||
| 408 | ;; Didn't find the last item, Adding to the top of | ||
| 409 | ;; tools. (This will probably never happend...) | ||
| 410 | (define-key (current-global-map) [menu-bar tools follow] | ||
| 411 | (cons "Follow" menumap)))) | ||
| 412 | ;; No tools menu, add "Follow" to the menubar. | ||
| 413 | (define-key mainmap [menu-bar follow] | ||
| 414 | (cons "Follow" menumap))))) | ||
| 415 | |||
| 416 | ;; | ||
| 417 | ;; XEmacs. | ||
| 418 | ;; | ||
| 419 | |||
| 420 | ;; place the menu in the `Tools' menu. | ||
| 421 | (let ((menu '("Follow" | ||
| 422 | :filter follow-menu-filter | ||
| 423 | ["Scroll Up" follow-scroll-up t] | ||
| 424 | ["Scroll Down" follow-scroll-down t] | ||
| 425 | ["Delete Other Windows and Split" | ||
| 426 | follow-delete-other-windows-and-split t] | ||
| 427 | ["Switch To Buffer" follow-switch-to-buffer t] | ||
| 428 | ["Switch To Buffer (all windows)" | ||
| 429 | follow-switch-to-buffer-all t] | ||
| 430 | ["First Window" follow-first-window t] | ||
| 431 | ["Last Window" follow-last-window t] | ||
| 432 | ["Next Windows" follow-next-window t] | ||
| 433 | ["Previous Window" follow-previous-window t] | ||
| 434 | ["Recenter" follow-recenter t] | ||
| 435 | ["Deactivate" follow-mode t]))) | ||
| 436 | |||
| 437 | ;; Why not just `(set-buffer-menubar current-menubar)'? The | ||
| 438 | ;; question is a very good question. The reason is that under | ||
| 439 | ;; Emacs, neither `set-buffer-menubar' nor | ||
| 440 | ;; `current-menubar' is defined, hence the byte-compiler will | ||
| 441 | ;; warn. | ||
| 442 | (funcall (symbol-function 'set-buffer-menubar) | ||
| 443 | (symbol-value 'current-menubar)) | ||
| 444 | (funcall (symbol-function 'add-submenu) '("Tools") menu)) | ||
| 445 | |||
| 446 | ;; When the mode is not activated, only one item is visible: | ||
| 447 | ;; "Activate". | ||
| 448 | (defun follow-menu-filter (menu) | ||
| 449 | (if follow-mode | ||
| 450 | menu | ||
| 451 | '(["Activate " follow-mode t])))) | ||
| 452 | |||
| 453 | mainmap) | 339 | mainmap) |
| 454 | "Minor mode keymap for Follow mode.") | 340 | "Minor mode keymap for Follow mode.") |
| 455 | 341 | ||
| 342 | ;; When the mode is not activated, only one item is visible to activate | ||
| 343 | ;; the mode. | ||
| 344 | (defun follow-menu-filter (menu) | ||
| 345 | (if (bound-and-true-p 'follow-mode) | ||
| 346 | menu | ||
| 347 | '(["Follow mode " follow-mode | ||
| 348 | :style toggle :selected follow-mode]))) | ||
| 349 | |||
| 350 | ;; If there is a `tools' menu, we use it. However, we can't add a | ||
| 351 | ;; minor-mode specific item to it (it's broken), so we make the | ||
| 352 | ;; contents ghosted when not in use, and add ourselves to the | ||
| 353 | ;; global map. | ||
| 354 | (easy-menu-add-item nil '("Tools") | ||
| 355 | '("Follow" | ||
| 356 | ;; The Emacs code used to just grey out operations when follow-mode was | ||
| 357 | ;; not enabled, whereas the XEmacs code used to remove it altogether. | ||
| 358 | ;; Not sure which is preferable, but clearly the preference should not | ||
| 359 | ;; depend on the flavor. | ||
| 360 | :filter follow-menu-filter | ||
| 361 | ["Scroll Up" follow-scroll-up follow-mode] | ||
| 362 | ["Scroll Down" follow-scroll-down follow-mode] | ||
| 363 | "--" | ||
| 364 | ["Delete Other Windows and Split" follow-delete-other-windows-and-split follow-mode] | ||
| 365 | "--" | ||
| 366 | ["Switch To Buffer" follow-switch-to-buffer follow-mode] | ||
| 367 | ["Switch To Buffer (all windows)" follow-switch-to-buffer-all follow-mode] | ||
| 368 | "--" | ||
| 369 | ["First Window" follow-first-window follow-mode] | ||
| 370 | ["Last Window" follow-last-window follow-mode] | ||
| 371 | ["Next Window" follow-next-window follow-mode] | ||
| 372 | ["Previous Window" follow-previous-window follow-mode] | ||
| 373 | "--" | ||
| 374 | ["Recenter" follow-recenter follow-mode] | ||
| 375 | "--" | ||
| 376 | ["Follow mode" follow-mode :style toggle :selected follow-mode])) | ||
| 377 | |||
| 456 | ;;}}} | 378 | ;;}}} |
| 457 | 379 | ||
| 458 | (defcustom follow-mode-line-text " Follow" | 380 | (defcustom follow-mode-line-text " Follow" |
| @@ -553,14 +475,12 @@ Used by `follow-window-size-change'.") | |||
| 553 | ;;;###autoload | 475 | ;;;###autoload |
| 554 | (defun turn-on-follow-mode () | 476 | (defun turn-on-follow-mode () |
| 555 | "Turn on Follow mode. Please see the function `follow-mode'." | 477 | "Turn on Follow mode. Please see the function `follow-mode'." |
| 556 | (interactive) | ||
| 557 | (follow-mode 1)) | 478 | (follow-mode 1)) |
| 558 | 479 | ||
| 559 | 480 | ||
| 560 | ;;;###autoload | 481 | ;;;###autoload |
| 561 | (defun turn-off-follow-mode () | 482 | (defun turn-off-follow-mode () |
| 562 | "Turn off Follow mode. Please see the function `follow-mode'." | 483 | "Turn off Follow mode. Please see the function `follow-mode'." |
| 563 | (interactive) | ||
| 564 | (follow-mode -1)) | 484 | (follow-mode -1)) |
| 565 | 485 | ||
| 566 | (put 'follow-mode 'permanent-local t) | 486 | (put 'follow-mode 'permanent-local t) |
| @@ -2084,8 +2004,8 @@ report this using the `report-emacs-bug' function." | |||
| 2084 | 2004 | ||
| 2085 | (defun follow-window-size-change (frame) | 2005 | (defun follow-window-size-change (frame) |
| 2086 | "Redraw all windows in FRAME, when in Follow mode." | 2006 | "Redraw all windows in FRAME, when in Follow mode." |
| 2087 | ;; Below, we call `post-command-hook'. This makes sure that we | 2007 | ;; Below, we call `post-command-hook'. This makes sure that we |
| 2088 | ;; doesn't start a mutally recursive endless loop. | 2008 | ;; don't start a mutually recursive endless loop. |
| 2089 | (if follow-inside-post-command-hook | 2009 | (if follow-inside-post-command-hook |
| 2090 | nil | 2010 | nil |
| 2091 | (let ((buffers '()) | 2011 | (let ((buffers '()) |
| @@ -2109,12 +2029,12 @@ report this using the `report-emacs-bug' function." | |||
| 2109 | (setq windows (follow-all-followers win)) | 2029 | (setq windows (follow-all-followers win)) |
| 2110 | (if (memq orig-window windows) | 2030 | (if (memq orig-window windows) |
| 2111 | (progn | 2031 | (progn |
| 2112 | ;; Make sure we're redrawing around the | 2032 | ;; Make sure we're redrawing around the |
| 2113 | ;; selected window. | 2033 | ;; selected window. |
| 2114 | ;; | 2034 | ;; |
| 2115 | ;; We must be really careful not to do this | 2035 | ;; We must be really careful not to do this |
| 2116 | ;; when we are (indirectly) called by | 2036 | ;; when we are (indirectly) called by |
| 2117 | ;; `post-command-hook'. | 2037 | ;; `post-command-hook'. |
| 2118 | (select-window orig-window) | 2038 | (select-window orig-window) |
| 2119 | (follow-post-command-hook) | 2039 | (follow-post-command-hook) |
| 2120 | (setq orig-window (selected-window))) | 2040 | (setq orig-window (selected-window))) |