Commit 87f9ec7a authored by Sam Steingold's avatar Sam Steingold
Browse files

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'.
parent 645a6aa4
...@@ -183,6 +183,8 @@ for Unicode 8.0. This includes full support for directional isolates ...@@ -183,6 +183,8 @@ for Unicode 8.0. This includes full support for directional isolates
and the Bidirectional Parentheses Algorithm (BPA) specified by these and the Bidirectional Parentheses Algorithm (BPA) specified by these
Unicode standards. 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 * Changes in Specialized Modes and Packages in Emacs 25.1
** ido ** ido
......
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> 2014-12-18 Artur Malabarba <bruce.connor.am@gmail.com>
   
* let-alist.el (let-alist): Evaluate the `alist' argument only * let-alist.el (let-alist): Evaluate the `alist' argument only
......
...@@ -1938,6 +1938,19 @@ Buffers menu is regenerated." ...@@ -1938,6 +1938,19 @@ Buffers menu is regenerated."
"Function to select the buffer chosen from the `Buffers' menu-bar menu. "Function to select the buffer chosen from the `Buffers' menu-bar menu.
It must accept a buffer as its only required argument.") 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) (defun menu-bar-update-buffers (&optional force)
;; If user discards the Buffers item, play along. ;; If user discards the Buffers item, play along.
(and (lookup-key (current-global-map) [menu-bar buffer]) (and (lookup-key (current-global-map) [menu-bar buffer])
...@@ -1973,17 +1986,7 @@ It must accept a buffer as its only required argument.") ...@@ -1973,17 +1986,7 @@ It must accept a buffer as its only required argument.")
name) name)
)) ))
alist)))) alist))))
;; Now make the actual list of items. (list (menu-bar-buffer-vector alist))))
(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))))
;; Make a Frames menu if we have more than one frame. ;; Make a Frames menu if we have more than one frame.
(when (cdr frames) (when (cdr frames)
...@@ -2311,6 +2314,25 @@ If FRAME is nil or not given, use the selected frame." ...@@ -2311,6 +2314,25 @@ If FRAME is nil or not given, use the selected frame."
(global-set-key [f10] 'menu-bar-open) (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 (defvar tty-menu-navigation-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
;; The next line is disabled because it breaks interpretation of ;; The next line is disabled because it breaks interpretation of
......
...@@ -1516,8 +1516,17 @@ This switches buffers in the window that you clicked on, ...@@ -1516,8 +1516,17 @@ This switches buffers in the window that you clicked on,
and selects that window." and selects that window."
(interactive "e") (interactive "e")
(mouse-minibuffer-check event) (mouse-minibuffer-check event)
(let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares) (let ((buf (x-popup-menu event (mouse-buffer-menu-map)))
;; Make an alist of elements that look like (MENU-ITEM . BUFFER). (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) (dolist (buf buffers)
;; Divide all buffers into buckets for various major modes. ;; Divide all buffers into buckets for various major modes.
;; Each bucket looks like (MODE NAMESTRING BUFFERS...). ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
...@@ -1581,18 +1590,10 @@ and selects that window." ...@@ -1581,18 +1590,10 @@ and selects that window."
(setq subdivided-menus (setq subdivided-menus
(cons (cons "Others" others-list) (cons (cons "Others" others-list)
subdivided-menus))))) subdivided-menus)))))
(setq menu (cons "Buffer Menu" (nreverse subdivided-menus)))) (cons "Buffer Menu" (nreverse subdivided-menus)))
(progn (cons "Buffer Menu"
(setq alist (mouse-buffer-menu-alist buffers)) (mouse-buffer-menu-split "Select Buffer"
(setq menu (cons "Buffer Menu" (mouse-buffer-menu-alist buffers))))))
(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)))))
(defun mouse-buffer-menu-alist (buffers) (defun mouse-buffer-menu-alist (buffers)
(let (tail (let (tail
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment