From: Chong Yidong Date: Sun, 13 May 2012 14:23:45 +0000 (+0800) Subject: Adapt Electric Buffer Menu to recent Buffer Menu changes. X-Git-Tag: emacs-24.2.90~471^2~98 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0ae03b6aae534c1a47f7246e791138b41203b036;p=emacs.git Adapt Electric Buffer Menu to recent Buffer Menu changes. * lisp/ebuff-menu.el (electric-buffer-list): Put electric buffer menu command descriptions in this docstring, instead of the docstring of electric-buffer-menu-mode. Code cleanups. (electric-buffer-menu-mode): Use define-derived-mode. Rename from Electric-buffer-menu-mode. (electric-buffer-update-highlight): Minor code cleanup. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-format) (tabulated-list-entries, tabulated-list-padding) (tabulated-list-sort-key): Make permanent-local. Fixes: debbugs:11455 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1bde354a551..557e8eb2e48 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,17 @@ +2012-05-13 Chong Yidong + + * emacs-lisp/tabulated-list.el (tabulated-list-format) + (tabulated-list-entries, tabulated-list-padding) + (tabulated-list-sort-key): Make permanent-local. + + * ebuff-menu.el: Adapt to Buffer Menu changes (Bug#11455). + (electric-buffer-list): Put electric buffer menu + command descriptions in this docstring, instead of the docstring + of electric-buffer-menu-mode. Code cleanups. + (electric-buffer-menu-mode): Use define-derived-mode. Rename from + Electric-buffer-menu-mode. + (electric-buffer-update-highlight): Minor code cleanup. + 2012-05-13 Michael Albinus * net/dbus.el (dbus-call-method): Restore events not from D-Bus. diff --git a/lisp/ebuff-menu.el b/lisp/ebuff-menu.el index 50a75c1aa57..e973f45bc44 100644 --- a/lisp/ebuff-menu.el +++ b/lisp/ebuff-menu.el @@ -31,9 +31,6 @@ (require 'electric) -;; this depends on the format of list-buffers (from src/buffer.c) and -;; on stuff in lisp/buff-menu.el - (defvar electric-buffer-menu-mode-map (let ((map (make-keymap))) (fillarray (car (cdr map)) 'Electric-buffer-menu-undefined) @@ -91,25 +88,33 @@ (put 'Helper-describe-bindings :advertised-binding "?") (defvar electric-buffer-menu-mode-hook nil - "Normal hook run by `electric-buffer-list'.") + "Normal hook run by `electric-buffer-menu-mode'.") ;;;###autoload (defun electric-buffer-list (arg) - "Pop up a buffer describing the set of Emacs buffers. -Vaguely like ITS lunar select buffer; combining typeoutoid buffer -listing with menuoid buffer selection. - -If the very next character typed is a space then the buffer list -window disappears. Otherwise, one may move around in the buffer list -window, marking buffers to be selected, saved or deleted. - -To exit and select a new buffer, type a space when the cursor is on -the appropriate line of the buffer-list window. Other commands are -much like those of `Buffer-menu-mode'. + "Pop up the Buffer Menu in an \"electric\" window. +If you type SPC or RET (`Electric-buffer-menu-select'), that +selects the buffer at point and quits the \"electric\" window. +Otherwise, you can move around in the Buffer Menu, marking +buffers to be selected, saved or deleted; these other commands +are much like those of `Buffer-menu-mode'. Run hooks in `electric-buffer-menu-mode-hook' on entry. -\\{electric-buffer-menu-mode-map}" +\\ +\\[keyboard-quit] or \\[Electric-buffer-menu-quit] -- exit buffer menu, returning to previous window and buffer + configuration. If the very first character typed is a space, it + also has this effect. +\\[Electric-buffer-menu-select] -- select buffer of line point is on. + Also show buffers marked with m in other windows, + deletes buffers marked with \"D\", and saves those marked with \"S\". +\\[Buffer-menu-mark] -- mark buffer to be displayed. +\\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. +\\[Buffer-menu-save] -- mark that buffer to be saved. +\\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted. +\\[Buffer-menu-unmark] -- remove all kinds of marks from current line. +\\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done. +\\[Buffer-menu-backup-unmark] -- back up a line and remove marks." (interactive "P") (let (select buffer) (save-window-excursion @@ -118,15 +123,15 @@ Run hooks in `electric-buffer-menu-mode-hook' on entry. (unwind-protect (progn (set-buffer buffer) - (Electric-buffer-menu-mode) + (electric-buffer-menu-mode) + (goto-char (point-min)) + (if (search-forward "\n." nil t) + (forward-char -1)) (electric-buffer-update-highlight) (setq select (catch 'electric-buffer-menu-select - (message "<<< Press Return to bury the buffer list >>>") - (if (eq (setq unread-command-events (list (read-event))) - ?\s) - (progn (setq unread-command-events nil) - (throw 'electric-buffer-menu-select nil))) + (message "<<< Type SPC or RET to bury the buffer list >>>") + (setq unread-command-events (list (read-event))) (let ((start-point (point)) (first (progn (goto-char (point-min)) (unless Buffer-menu-use-header-line @@ -150,15 +155,16 @@ Run hooks in `electric-buffer-menu-mode-hook' on entry. (Buffer-menu-mode) (bury-buffer) ;Get rid of window, if dedicated. (message ""))) - (if select - (progn (set-buffer buffer) - (let ((opoint (point-marker))) - (Buffer-menu-execute) - (goto-char (point-min)) - (if (prog1 (search-forward "\n>" nil t) - (goto-char opoint) (set-marker opoint nil)) - (Buffer-menu-select) - (switch-to-buffer (Buffer-menu-buffer t)))))))) + (when select + (set-buffer buffer) + (let ((opoint (point-marker))) + (Buffer-menu-execute) + (goto-char (point-min)) + (if (prog1 (search-forward "\n>" nil t) + (goto-char opoint) + (set-marker opoint nil)) + (Buffer-menu-select) + (switch-to-buffer (Buffer-menu-buffer t))))))) (defun electric-buffer-menu-looper (state condition) (cond ((and condition @@ -179,50 +185,27 @@ Run hooks in `electric-buffer-menu-mode-hook' on entry. (defvar Helper-return-blurb) -(put 'Electric-buffer-menu-mode 'mode-class 'special) -(defun Electric-buffer-menu-mode () - "Major mode for editing a list of buffers. -Each line describes one of the buffers in Emacs. -Letters do not insert themselves; instead, they are commands. -\\ -\\[keyboard-quit] or \\[Electric-buffer-menu-quit] -- exit buffer menu, returning to previous window and buffer - configuration. If the very first character typed is a space, it - also has this effect. -\\[Electric-buffer-menu-select] -- select buffer of line point is on. - Also show buffers marked with m in other windows, - deletes buffers marked with \"D\", and saves those marked with \"S\". -\\[Buffer-menu-mark] -- mark buffer to be displayed. -\\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. -\\[Buffer-menu-save] -- mark that buffer to be saved. -\\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted. -\\[Buffer-menu-unmark] -- remove all kinds of marks from current line. -\\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done. -\\[Buffer-menu-backup-unmark] -- back up a line and remove marks. +(define-derived-mode electric-buffer-menu-mode Buffer-menu-mode + "Electric Buffer Menu" + "Toggle Electric Buffer Menu mode in this buffer. +With a prefix argument ARG, enable Long Lines mode if ARG is +positive, and disable it otherwise. If called from Lisp, enable +the mode if ARG is omitted or nil. -\\{electric-buffer-menu-mode-map} - -Entry to this mode via command `electric-buffer-list' calls the value of -`electric-buffer-menu-mode-hook'." - (let ((saved header-line-format)) - (kill-all-local-variables) - (setq header-line-format saved)) - (use-local-map electric-buffer-menu-mode-map) - (setq mode-name "Electric Buffer Menu") +Electric Buffer Menu mode is a minor mode which is automatically +enabled and disabled by the \\[electric-buffer-list] command. +See the documentation of `electric-buffer-list' for details." (setq mode-line-buffer-identification "Electric Buffer List") - (make-local-variable 'Helper-return-blurb) - (setq Helper-return-blurb "return to buffer editing") - (setq truncate-lines t) - (setq buffer-read-only t) - (setq major-mode 'Electric-buffer-menu-mode) - (goto-char (point-min)) - (if (search-forward "\n." nil t) (forward-char -1)) - (run-mode-hooks 'electric-buffer-menu-mode-hook)) + (set (make-local-variable 'Helper-return-blurb) + "return to buffer editing")) + +(define-obsolete-function-alias 'Electric-buffer-menu-mode + 'electric-buffer-menu-mode "24.2") ;; generally the same as Buffer-menu-mode-map ;; (except we don't indirect to global-map) (put 'Electric-buffer-menu-undefined 'suppress-keymap t) - (defun Electric-buffer-menu-exit () (interactive) (setq unread-command-events (listify-key-sequence (this-command-keys))) @@ -274,13 +257,13 @@ Return to Electric Buffer Menu when done." (sit-for 4)))) (defvar electric-buffer-overlay nil) + (defun electric-buffer-update-highlight () - (when (eq major-mode 'Electric-buffer-menu-mode) + (when (derived-mode-p 'electric-buffer-menu-mode) ;; Make sure we have an overlay to use. (or electric-buffer-overlay - (progn - (make-local-variable 'electric-buffer-overlay) - (setq electric-buffer-overlay (make-overlay (point) (point))))) + (set (make-local-variable 'electric-buffer-overlay) + (make-overlay (point) (point)))) (move-overlay electric-buffer-overlay (line-beginning-position) (line-end-position)) diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index e56fea58553..a56a7619ea9 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -35,6 +35,11 @@ ;;; Code: +;; The reason `tabulated-list-format' and other variables are +;; permanent-local is to make it convenient to switch to a different +;; major mode, switch back, and have the original Tabulated List data +;; still valid. See, for example, ebuff-menu.el. + (defvar tabulated-list-format nil "The format of the current Tabulated List mode buffer. This should be a vector of elements (NAME WIDTH SORT . PROPS), @@ -56,6 +61,7 @@ where: - `:pad-right': Number of additional padding spaces to the right of the column (defaults to 1 if omitted).") (make-variable-buffer-local 'tabulated-list-format) +(put 'tabulated-list-format 'permanent-local t) (defvar tabulated-list-use-header-line t "Whether the Tabulated List buffer should use a header line.") @@ -80,12 +86,14 @@ where: If `tabulated-list-entries' is a function, it is called with no arguments and must return a list of the above form.") (make-variable-buffer-local 'tabulated-list-entries) +(put 'tabulated-list-entries 'permanent-local t) (defvar tabulated-list-padding 0 "Number of characters preceding each Tabulated List mode entry. By default, lines are padded with spaces, but you can use the function `tabulated-list-put-tag' to change this.") (make-variable-buffer-local 'tabulated-list-padding) +(put 'tabulated-list-padding 'permanent-local t) (defvar tabulated-list-revert-hook nil "Hook run before reverting a Tabulated List buffer. @@ -107,6 +115,7 @@ NAME is a string matching one of the column names in `tabulated-list-format' then specifies how to sort). FLIP, if non-nil, means to invert the resulting sort.") (make-variable-buffer-local 'tabulated-list-sort-key) +(put 'tabulated-list-sort-key 'permanent-local t) (defsubst tabulated-list-get-id (&optional pos) "Return the entry ID of the Tabulated List entry at POS.