From a9603a18127f8a6325a92dd5505211028e504104 Mon Sep 17 00:00:00 2001 From: David Reitter Date: Sat, 1 May 2010 18:43:39 -0400 Subject: [PATCH] Sort mouse buffer menu and make work with large number of buffers Pretty-print modified symbol, prevent (but defvar) read-only symbol on non-window systems --- aquamacs/src/site-lisp/aquamacs.el | 4 ++- aquamacs/src/site-lisp/macosx/osxkeys.el | 45 +++++++++++++----------- lisp/menu-bar.el | 15 +++++--- lisp/mouse.el | 16 ++++++--- 4 files changed, 49 insertions(+), 31 deletions(-) diff --git a/aquamacs/src/site-lisp/aquamacs.el b/aquamacs/src/site-lisp/aquamacs.el index 9a16d5e9f3f3..bd08df64429f 100644 --- a/aquamacs/src/site-lisp/aquamacs.el +++ b/aquamacs/src/site-lisp/aquamacs.el @@ -955,7 +955,9 @@ yes-or-no prompts - y or n will do." (enable-recursive-minibuffers t) - (longlines-wrap-follows-window-size t) + ;; menu strings + (buffer-menu-modified-string "\u25CF") + (buffer-menu-read-only-string "(read-only)") ;; do not allow user to mess with minibuffer prompt diff --git a/aquamacs/src/site-lisp/macosx/osxkeys.el b/aquamacs/src/site-lisp/macosx/osxkeys.el index b01f25f50c51..22b587460a83 100644 --- a/aquamacs/src/site-lisp/macosx/osxkeys.el +++ b/aquamacs/src/site-lisp/macosx/osxkeys.el @@ -524,7 +524,7 @@ OS X 10.4 and up only." (if word (mac-spotlight-search word))))) - +;; (aquamacs-make-mouse-buffer-menu) (defun aquamacs-make-mouse-buffer-menu ( ) "Return a menu keymap of buffers for selection with the mouse. This switches buffers in the window that you clicked on, @@ -598,26 +598,28 @@ 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 ((km (make-sparse-keymap))) - (mapc (lambda (pair) - (define-key km (vector (intern (car pair))) - `(menu-item ,(car pair) - ,(eval - (list 'lambda () - '(interactive) + (aquamacs--keymap-from-alist subdivided-menus)) + (aquamacs--keymap-from-alist (mouse-buffer-menu-alist buffers))))) + +(defun aquamacs--keymap-from-alist (alist) + (let ((km (make-sparse-keymap))) + (mapc (lambda (pair) + (define-key km (vector (intern (car pair))) + `(menu-item ,(car pair) + ,(if (consp (cdr pair)) + (aquamacs--keymap-from-alist (cdr pair)) + (eval + (list 'lambda () + '(interactive) `(let ((one-buffer-one-frame nil)) - (switch-to-buffer ,(cdr pair))))) - ))) alist) - km - ) ) - ) - + (switch-to-buffer ,(cdr pair)))))) + ))) + (sort alist (lambda (a b) (string< (car b) + (car a))))) + km)) + + +;; (aquamacs-update-context-menus t) (defun aquamacs-get-mouse-major-mode-menu () "Pop up a mode-specific menu of mouse commands. @@ -727,6 +729,7 @@ Its content is specified in the keymap `aquamacs-context-menu-map'." (popup-menu aquamacs-context-menu-map event prefix)) +;; (aquamacs-update-context-menus t) (defun aquamacs-update-context-menus (&optional force) "Update the buffer- and mode-specific items in `aquamacs-context-menu-map' if frame or buffer has changed. @@ -739,7 +742,7 @@ Update unconditionally if optional argument FORCE is non-nil." ;; TO DO major mode might not work unless we switch buffer (define-key aquamacs-context-menu-map [mode-menu] `(menu-item ,(aquamacs-pretty-mode-name major-mode) ,mode-menu :visible t)) - (define-key aquamacs-context-menu-map [mode-menu] + (define-key aquamacs-context-menu-map [mode-menu] mouse-buffer-menu '(menu-item nil :visible nil)))) (define-key aquamacs-context-menu-map [switch-buffer] diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 8c8f9d784a6f..abb222c38694 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -1738,6 +1738,12 @@ Buffers menu is regenerated." (raise-frame frame) (select-frame frame)) + +;; FIXME: move these in common place +;; (shared with mouse.el) +(defvar buffer-menu-modified-string "*") +(defvar buffer-menu-read-only-string "%") + (defun menu-bar-update-buffers-1 (elt) (let* ((buf (car elt)) (file @@ -1752,14 +1758,15 @@ Buffers menu is regenerated." (when (and file (> (length file) 20)) (setq file (concat "..." (substring file -17)))) (cons (if buffers-menu-show-status - (let ((mod (if (buffer-modified-p buf) "\u25CF " "")) ; on NS this indicates modification. To Do: show on the left + (let ((mod (if (buffer-modified-p buf) buffer-menu-modified-string "")) ; on NS this indicates modification. To Do: show on the left ;; (icon (if (buffer-modified-p buf) "\u2666 " "")) - (ro (if (buffer-local-value 'buffer-read-only buf) "%" ""))) + (ro (if (buffer-local-value 'buffer-read-only buf) buffer-menu-read-only-string "")) + ) (if file - (format "%s %s%s -- %s" (cdr elt) mod ro file) + (format "%s %s%s \t%s" (cdr elt) mod ro file) (format "%s %s%s" (cdr elt) mod ro))) (if file - (format "%s -- %s" (cdr elt) file) + (format "%s \t%s" (cdr elt) file) (cdr elt))) buf))) diff --git a/lisp/mouse.el b/lisp/mouse.el index 08f164c6d027..6d3b10f3d595 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -1958,6 +1958,9 @@ and selects that window." window)) (switch-to-buffer buf))))) +(defvar buffer-menu-modified-string "*") +(defvar buffer-menu-read-only-string "%") + (defun mouse-buffer-menu-alist (buffers) (let (tail (maxlen 0) @@ -1981,11 +1984,14 @@ and selects that window." (cons (cons (format - (format "%%-%ds %%s%%s %%s" maxlen) + (if window-system + "%s %s%s%s %s" ; variable-width menu font! + (format "%%-%ds %%s%%s%%s %%s" maxlen)) (buffer-name elt) - (if (buffer-modified-p elt) "*" " ") + (if (buffer-modified-p elt) buffer-menu-modified-string "") (with-current-buffer elt - (if buffer-read-only "%" " ")) + (if buffer-read-only buffer-menu-read-only-string " ")) + "" (or (buffer-file-name elt) (with-current-buffer elt (if list-buffers-directory @@ -1995,8 +2001,8 @@ and selects that window." elt) head)))) (setq tail (cdr tail))) - ;; Compensate for the reversal that the above loop does. - (nreverse head))) + ;; Should be sorted to keep list stable + head)) (defun mouse-buffer-menu-split (title alist) ;; If we have lots of buffers, divide them into groups of 20