Skip to content

Commit

Permalink
Sort mouse buffer menu and make work with large number of buffers
Browse files Browse the repository at this point in the history
Pretty-print modified symbol, prevent (but defvar) read-only symbol on non-window systems
  • Loading branch information
davidswelt committed May 1, 2010
1 parent 445bd24 commit a9603a1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
4 changes: 3 additions & 1 deletion aquamacs/src/site-lisp/aquamacs.el
Expand Up @@ -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

Expand Down
45 changes: 24 additions & 21 deletions aquamacs/src/site-lisp/macosx/osxkeys.el
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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]
Expand Down
15 changes: 11 additions & 4 deletions lisp/menu-bar.el
Expand Up @@ -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
Expand All @@ -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)))

Expand Down
16 changes: 11 additions & 5 deletions lisp/mouse.el
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a9603a1

Please sign in to comment.