diff options
| author | Sam Steingold | 2014-12-18 16:41:34 -0500 |
|---|---|---|
| committer | Sam Steingold | 2014-12-18 16:41:34 -0500 |
| commit | 87f9ec7afb1180d6dc1ef65134f59cddddda1d68 (patch) | |
| tree | b66ef6542d663e4115665bbd0362333c35e62d09 | |
| parent | 645a6aa4a5ee66659133f57ebeb5638bdc43beaa (diff) | |
| download | emacs-87f9ec7afb1180d6dc1ef65134f59cddddda1d68.tar.gz emacs-87f9ec7afb1180d6dc1ef65134f59cddddda1d68.zip | |
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'.
| -rw-r--r-- | etc/NEWS | 2 | ||||
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/menu-bar.el | 44 | ||||
| -rw-r--r-- | lisp/mouse.el | 29 |
4 files changed, 64 insertions, 25 deletions
| @@ -183,6 +183,8 @@ for Unicode 8.0. This includes full support for directional isolates | |||
| 183 | and the Bidirectional Parentheses Algorithm (BPA) specified by these | 183 | and the Bidirectional Parentheses Algorithm (BPA) specified by these |
| 184 | Unicode standards. | 184 | Unicode standards. |
| 185 | 185 | ||
| 186 | ** You can access `mouse-buffer-menu' (C-down-mouse-1) using C-f10. | ||
| 187 | |||
| 186 | 188 | ||
| 187 | * Changes in Specialized Modes and Packages in Emacs 25.1 | 189 | * Changes in Specialized Modes and Packages in Emacs 25.1 |
| 188 | ** ido | 190 | ** ido |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9828b845368..b50d5844b58 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2014-12-18 Sam Steingold <sds@gnu.org> | ||
| 2 | |||
| 3 | Keyboard interface (C-f10) to `mouse-buffer-menu' (C-down-mouse-1). | ||
| 4 | * mouse.el (mouse-buffer-menu-map): Extract from `mouse-buffer-menu'. | ||
| 5 | (mouse-buffer-menu): Use `mouse-buffer-menu-map'. | ||
| 6 | * menu-bar.el (menu-bar-buffer-vector): Extract from | ||
| 7 | `menu-bar-update-buffers'. | ||
| 8 | (menu-bar-update-buffers): Use `menu-bar-buffer-vector'. | ||
| 9 | (buffer-menu-open): New user command, bound globally to C-f10, | ||
| 10 | provides a keyboard interface to `mouse-buffer-menu' (C-down-mouse-1). | ||
| 11 | (mouse-buffer-menu-keymap): Use `menu-bar-buffer-vector' to | ||
| 12 | convert the value returned by `mouse-buffer-menu-map' to a list | ||
| 13 | acceptable to `popup-menu' for `buffer-menu-open'. | ||
| 14 | |||
| 1 | 2014-12-18 Artur Malabarba <bruce.connor.am@gmail.com> | 15 | 2014-12-18 Artur Malabarba <bruce.connor.am@gmail.com> |
| 2 | 16 | ||
| 3 | * let-alist.el (let-alist): Evaluate the `alist' argument only | 17 | * let-alist.el (let-alist): Evaluate the `alist' argument only |
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 12fb192c355..8f33641a746 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el | |||
| @@ -1938,6 +1938,19 @@ Buffers menu is regenerated." | |||
| 1938 | "Function to select the buffer chosen from the `Buffers' menu-bar menu. | 1938 | "Function to select the buffer chosen from the `Buffers' menu-bar menu. |
| 1939 | It must accept a buffer as its only required argument.") | 1939 | It must accept a buffer as its only required argument.") |
| 1940 | 1940 | ||
| 1941 | (defun menu-bar-buffer-vector (alist) | ||
| 1942 | ;; turn ((name . buffer) ...) into a menu | ||
| 1943 | (let ((buffers-vec (make-vector (length alist) nil)) | ||
| 1944 | (i (length alist))) | ||
| 1945 | (dolist (pair alist) | ||
| 1946 | (setq i (1- i)) | ||
| 1947 | (aset buffers-vec i | ||
| 1948 | (cons (car pair) | ||
| 1949 | `(lambda () | ||
| 1950 | (interactive) | ||
| 1951 | (funcall menu-bar-select-buffer-function ,(cdr pair)))))) | ||
| 1952 | buffers-vec)) | ||
| 1953 | |||
| 1941 | (defun menu-bar-update-buffers (&optional force) | 1954 | (defun menu-bar-update-buffers (&optional force) |
| 1942 | ;; If user discards the Buffers item, play along. | 1955 | ;; If user discards the Buffers item, play along. |
| 1943 | (and (lookup-key (current-global-map) [menu-bar buffer]) | 1956 | (and (lookup-key (current-global-map) [menu-bar buffer]) |
| @@ -1973,17 +1986,7 @@ It must accept a buffer as its only required argument.") | |||
| 1973 | name) | 1986 | name) |
| 1974 | )) | 1987 | )) |
| 1975 | alist)))) | 1988 | alist)))) |
| 1976 | ;; Now make the actual list of items. | 1989 | (list (menu-bar-buffer-vector alist)))) |
| 1977 | (let ((buffers-vec (make-vector (length alist) nil)) | ||
| 1978 | (i (length alist))) | ||
| 1979 | (dolist (pair alist) | ||
| 1980 | (setq i (1- i)) | ||
| 1981 | (aset buffers-vec i | ||
| 1982 | (cons (car pair) | ||
| 1983 | `(lambda () | ||
| 1984 | (interactive) | ||
| 1985 | (funcall menu-bar-select-buffer-function ,(cdr pair)))))) | ||
| 1986 | (list buffers-vec)))) | ||
| 1987 | 1990 | ||
| 1988 | ;; Make a Frames menu if we have more than one frame. | 1991 | ;; Make a Frames menu if we have more than one frame. |
| 1989 | (when (cdr frames) | 1992 | (when (cdr frames) |
| @@ -2311,6 +2314,25 @@ If FRAME is nil or not given, use the selected frame." | |||
| 2311 | 2314 | ||
| 2312 | (global-set-key [f10] 'menu-bar-open) | 2315 | (global-set-key [f10] 'menu-bar-open) |
| 2313 | 2316 | ||
| 2317 | (defun buffer-menu-open () | ||
| 2318 | "Start key navigation of the buffer menu. | ||
| 2319 | This is the keyboard interface to \\[mouse-buffer-menu]." | ||
| 2320 | (interactive) | ||
| 2321 | (popup-menu (mouse-buffer-menu-keymap) | ||
| 2322 | (posn-at-x-y 0 0 nil t))) | ||
| 2323 | |||
| 2324 | (global-set-key [C-f10] 'buffer-menu-open) | ||
| 2325 | |||
| 2326 | (defun mouse-buffer-menu-keymap () | ||
| 2327 | (let* ((menu (mouse-buffer-menu-map)) | ||
| 2328 | (km (make-sparse-keymap (pop menu)))) | ||
| 2329 | (dolist (item (nreverse menu)) | ||
| 2330 | (let* ((name (pop item))) | ||
| 2331 | (define-key km (vector (intern name)) | ||
| 2332 | (list name 'keymap name | ||
| 2333 | (menu-bar-buffer-vector item))))) | ||
| 2334 | km)) | ||
| 2335 | |||
| 2314 | (defvar tty-menu-navigation-map | 2336 | (defvar tty-menu-navigation-map |
| 2315 | (let ((map (make-sparse-keymap))) | 2337 | (let ((map (make-sparse-keymap))) |
| 2316 | ;; The next line is disabled because it breaks interpretation of | 2338 | ;; The next line is disabled because it breaks interpretation of |
diff --git a/lisp/mouse.el b/lisp/mouse.el index 800db63aff6..6e86bc06c1a 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -1516,8 +1516,17 @@ This switches buffers in the window that you clicked on, | |||
| 1516 | and selects that window." | 1516 | and selects that window." |
| 1517 | (interactive "e") | 1517 | (interactive "e") |
| 1518 | (mouse-minibuffer-check event) | 1518 | (mouse-minibuffer-check event) |
| 1519 | (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares) | 1519 | (let ((buf (x-popup-menu event (mouse-buffer-menu-map))) |
| 1520 | ;; Make an alist of elements that look like (MENU-ITEM . BUFFER). | 1520 | (window (posn-window (event-start event)))) |
| 1521 | (when buf | ||
| 1522 | (select-window | ||
| 1523 | (if (framep window) (frame-selected-window window) | ||
| 1524 | window)) | ||
| 1525 | (switch-to-buffer buf)))) | ||
| 1526 | |||
| 1527 | (defun mouse-buffer-menu-map () | ||
| 1528 | ;; Make an alist of elements that look like (MENU-ITEM . BUFFER). | ||
| 1529 | (let ((buffers (buffer-list)) split-by-major-mode sum-of-squares) | ||
| 1521 | (dolist (buf buffers) | 1530 | (dolist (buf buffers) |
| 1522 | ;; Divide all buffers into buckets for various major modes. | 1531 | ;; Divide all buffers into buckets for various major modes. |
| 1523 | ;; Each bucket looks like (MODE NAMESTRING BUFFERS...). | 1532 | ;; Each bucket looks like (MODE NAMESTRING BUFFERS...). |
| @@ -1581,18 +1590,10 @@ and selects that window." | |||
| 1581 | (setq subdivided-menus | 1590 | (setq subdivided-menus |
| 1582 | (cons (cons "Others" others-list) | 1591 | (cons (cons "Others" others-list) |
| 1583 | subdivided-menus))))) | 1592 | subdivided-menus))))) |
| 1584 | (setq menu (cons "Buffer Menu" (nreverse subdivided-menus)))) | 1593 | (cons "Buffer Menu" (nreverse subdivided-menus))) |
| 1585 | (progn | 1594 | (cons "Buffer Menu" |
| 1586 | (setq alist (mouse-buffer-menu-alist buffers)) | 1595 | (mouse-buffer-menu-split "Select Buffer" |
| 1587 | (setq menu (cons "Buffer Menu" | 1596 | (mouse-buffer-menu-alist buffers)))))) |
| 1588 | (mouse-buffer-menu-split "Select Buffer" alist))))) | ||
| 1589 | (let ((buf (x-popup-menu event menu)) | ||
| 1590 | (window (posn-window (event-start event)))) | ||
| 1591 | (when buf | ||
| 1592 | (select-window | ||
| 1593 | (if (framep window) (frame-selected-window window) | ||
| 1594 | window)) | ||
| 1595 | (switch-to-buffer buf))))) | ||
| 1596 | 1597 | ||
| 1597 | (defun mouse-buffer-menu-alist (buffers) | 1598 | (defun mouse-buffer-menu-alist (buffers) |
| 1598 | (let (tail | 1599 | (let (tail |