* 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'.
and the Bidirectional Parentheses Algorithm (BPA) specified by these
Unicode standards.
+** You can access `mouse-buffer-menu' (C-down-mouse-1) using C-f10.
+
\f
* Changes in Specialized Modes and Packages in Emacs 25.1
** 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>
* let-alist.el (let-alist): Evaluate the `alist' argument only
"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])
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)
(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
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...).
(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