1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-27 10:54:40 +00:00

Keyboard interface (C-f10) to `mouse-buffer-menu' (C-down-mouse-1).

* lisp/mouse.el (mouse-buffer-menu-map): Extract from `mouse-buffer-menu'.
(mouse-buffer-menu): Use `mouse-buffer-menu-map'.
* lisp/menu-bar.el (menu-bar-buffer-vector): Extract from
`menu-bar-update-buffers'.
(menu-bar-update-buffers): Use `menu-bar-buffer-vector'.
(buffer-menu-open): New user command, bound globally to C-f10,
provides a keyboard interface to `mouse-buffer-menu' (C-down-mouse-1).
(mouse-buffer-menu-keymap): Use `menu-bar-buffer-vector' to
convert the value returned by `mouse-buffer-menu-map' to a list
acceptable to `popup-menu' for `buffer-menu-open'.
This commit is contained in:
Sam Steingold 2014-12-18 16:41:34 -05:00
parent 645a6aa4a5
commit 87f9ec7afb
4 changed files with 64 additions and 25 deletions

View File

@ -183,6 +183,8 @@ for Unicode 8.0. This includes full support for directional isolates
and the Bidirectional Parentheses Algorithm (BPA) specified by these
Unicode standards.
** You can access `mouse-buffer-menu' (C-down-mouse-1) using C-f10.
* Changes in Specialized Modes and Packages in Emacs 25.1
** ido

View File

@ -1,3 +1,17 @@
2014-12-18 Sam Steingold <sds@gnu.org>
Keyboard interface (C-f10) to `mouse-buffer-menu' (C-down-mouse-1).
* mouse.el (mouse-buffer-menu-map): Extract from `mouse-buffer-menu'.
(mouse-buffer-menu): Use `mouse-buffer-menu-map'.
* menu-bar.el (menu-bar-buffer-vector): Extract from
`menu-bar-update-buffers'.
(menu-bar-update-buffers): Use `menu-bar-buffer-vector'.
(buffer-menu-open): New user command, bound globally to C-f10,
provides a keyboard interface to `mouse-buffer-menu' (C-down-mouse-1).
(mouse-buffer-menu-keymap): Use `menu-bar-buffer-vector' to
convert the value returned by `mouse-buffer-menu-map' to a list
acceptable to `popup-menu' for `buffer-menu-open'.
2014-12-18 Artur Malabarba <bruce.connor.am@gmail.com>
* let-alist.el (let-alist): Evaluate the `alist' argument only

View File

@ -1938,6 +1938,19 @@ Buffers menu is regenerated."
"Function to select the buffer chosen from the `Buffers' menu-bar menu.
It must accept a buffer as its only required argument.")
(defun menu-bar-buffer-vector (alist)
;; turn ((name . buffer) ...) into a menu
(let ((buffers-vec (make-vector (length alist) nil))
(i (length alist)))
(dolist (pair alist)
(setq i (1- i))
(aset buffers-vec i
(cons (car pair)
`(lambda ()
(interactive)
(funcall menu-bar-select-buffer-function ,(cdr pair))))))
buffers-vec))
(defun menu-bar-update-buffers (&optional force)
;; If user discards the Buffers item, play along.
(and (lookup-key (current-global-map) [menu-bar buffer])
@ -1973,17 +1986,7 @@ It must accept a buffer as its only required argument.")
name)
))
alist))))
;; Now make the actual list of items.
(let ((buffers-vec (make-vector (length alist) nil))
(i (length alist)))
(dolist (pair alist)
(setq i (1- i))
(aset buffers-vec i
(cons (car pair)
`(lambda ()
(interactive)
(funcall menu-bar-select-buffer-function ,(cdr pair))))))
(list buffers-vec))))
(list (menu-bar-buffer-vector alist))))
;; Make a Frames menu if we have more than one frame.
(when (cdr frames)
@ -2311,6 +2314,25 @@ If FRAME is nil or not given, use the selected frame."
(global-set-key [f10] 'menu-bar-open)
(defun buffer-menu-open ()
"Start key navigation of the buffer menu.
This is the keyboard interface to \\[mouse-buffer-menu]."
(interactive)
(popup-menu (mouse-buffer-menu-keymap)
(posn-at-x-y 0 0 nil t)))
(global-set-key [C-f10] 'buffer-menu-open)
(defun mouse-buffer-menu-keymap ()
(let* ((menu (mouse-buffer-menu-map))
(km (make-sparse-keymap (pop menu))))
(dolist (item (nreverse menu))
(let* ((name (pop item)))
(define-key km (vector (intern name))
(list name 'keymap name
(menu-bar-buffer-vector item)))))
km))
(defvar tty-menu-navigation-map
(let ((map (make-sparse-keymap)))
;; The next line is disabled because it breaks interpretation of

View File

@ -1516,8 +1516,17 @@ This switches buffers in the window that you clicked on,
and selects that window."
(interactive "e")
(mouse-minibuffer-check event)
(let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
(let ((buf (x-popup-menu event (mouse-buffer-menu-map)))
(window (posn-window (event-start event))))
(when buf
(select-window
(if (framep window) (frame-selected-window window)
window))
(switch-to-buffer buf))))
(defun mouse-buffer-menu-map ()
;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
(let ((buffers (buffer-list)) split-by-major-mode sum-of-squares)
(dolist (buf buffers)
;; Divide all buffers into buckets for various major modes.
;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
@ -1581,18 +1590,10 @@ and selects that window."
(setq subdivided-menus
(cons (cons "Others" others-list)
subdivided-menus)))))
(setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
(progn
(setq alist (mouse-buffer-menu-alist buffers))
(setq menu (cons "Buffer Menu"
(mouse-buffer-menu-split "Select Buffer" alist)))))
(let ((buf (x-popup-menu event menu))
(window (posn-window (event-start event))))
(when buf
(select-window
(if (framep window) (frame-selected-window window)
window))
(switch-to-buffer buf)))))
(cons "Buffer Menu" (nreverse subdivided-menus)))
(cons "Buffer Menu"
(mouse-buffer-menu-split "Select Buffer"
(mouse-buffer-menu-alist buffers))))))
(defun mouse-buffer-menu-alist (buffers)
(let (tail