diff options
| author | Richard M. Stallman | 1993-03-15 02:00:20 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-03-15 02:00:20 +0000 |
| commit | 4095411173aff1b64aecb03bb737408e1b744120 (patch) | |
| tree | 76f20790c0a524b95127c28c12b95787c79cbd25 | |
| parent | 690eca32af1a29f95396fa38366c6196ff824b29 (diff) | |
| download | emacs-4095411173aff1b64aecb03bb737408e1b744120.tar.gz emacs-4095411173aff1b64aecb03bb737408e1b744120.zip | |
*** empty log message ***
| -rw-r--r-- | lisp/menu-bar.el | 102 |
1 files changed, 96 insertions, 6 deletions
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 8466f26a8fe..280b88158e0 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el | |||
| @@ -1,12 +1,10 @@ | |||
| 1 | (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")) | 1 | (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")) |
| 2 | (setq menu-bar-file-menu (make-sparse-keymap "File")) | ||
| 3 | (define-key global-map [menu-bar file] (cons "File" menu-bar-file-menu)) | ||
| 4 | (setq menu-bar-edit-menu (make-sparse-keymap "Edit")) | ||
| 5 | (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu)) | ||
| 6 | (setq menu-bar-buffer-menu (make-sparse-keymap "Buffers")) | ||
| 7 | (define-key global-map [menu-bar buffer] (cons "Buffers" menu-bar-buffer-menu)) | ||
| 8 | (setq menu-bar-help-menu (make-sparse-keymap "Help")) | 2 | (setq menu-bar-help-menu (make-sparse-keymap "Help")) |
| 9 | (define-key global-map [menu-bar help] (cons "Help" menu-bar-help-menu)) | 3 | (define-key global-map [menu-bar help] (cons "Help" menu-bar-help-menu)) |
| 4 | (setq menu-bar-edit-menu (make-sparse-keymap "Edit")) | ||
| 5 | (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu)) | ||
| 6 | (setq menu-bar-file-menu (make-sparse-keymap "File")) | ||
| 7 | (define-key global-map [menu-bar file] (cons "File" menu-bar-file-menu)) | ||
| 10 | 8 | ||
| 11 | (define-key menu-bar-file-menu [exit-emacs] | 9 | (define-key menu-bar-file-menu [exit-emacs] |
| 12 | '("Exit Emacs" . save-buffers-kill-emacs)) | 10 | '("Exit Emacs" . save-buffers-kill-emacs)) |
| @@ -77,7 +75,99 @@ | |||
| 77 | (and (boundp 'pending-undo-list) | 75 | (and (boundp 'pending-undo-list) |
| 78 | pending-undo-list) | 76 | pending-undo-list) |
| 79 | buffer-undo-list))) | 77 | buffer-undo-list))) |
| 78 | |||
| 79 | (define-key global-map [menu-bar buffer] '("Buffers" . mouse-buffer-menu)) | ||
| 80 | |||
| 81 | (defvar complex-buffers-menu-p nil | ||
| 82 | "*Non-nil says, offer a choice of actions after you pick a buffer. | ||
| 83 | This applies to the Buffers menu from the menu bar.") | ||
| 84 | |||
| 85 | (defvar buffers-menu-max-size 10 | ||
| 86 | "*Maximum number of entries which may appear on the Buffers menu. | ||
| 87 | If this is 10, then only the ten most-recently-selected buffers are shown. | ||
| 88 | If this is nil, then all buffers are shown. | ||
| 89 | A large number or nil slows down menu responsiveness.") | ||
| 90 | |||
| 91 | (defun mouse-buffer-menu (event) | ||
| 92 | "Pop up a menu of buffers for selection with the mouse. | ||
| 93 | This switches buffers in the window that you clicked on, | ||
| 94 | and selects that window." | ||
| 95 | (interactive "e") | ||
| 96 | (let ((buffers (buffer-list)) | ||
| 97 | menu) | ||
| 98 | ;; If requested, list only the N most recently selected buffers. | ||
| 99 | (if (and (integerp buffers-menu-max-size) | ||
| 100 | (> buffers-menu-max-size 1)) | ||
| 101 | (if (> (length buffers) buffers-menu-max-size) | ||
| 102 | (setcdr (nthcdr buffers-menu-max-size buffers) nil))) | ||
| 103 | (setq menu | ||
| 104 | (list "Buffer Menu" | ||
| 105 | (cons "Select Buffer" | ||
| 106 | (let ((tail buffers) | ||
| 107 | (maxlen 0) | ||
| 108 | head) | ||
| 109 | (while tail | ||
| 110 | (let ((elt (car tail))) | ||
| 111 | (if (not (string-match "^ " | ||
| 112 | (buffer-name elt))) | ||
| 113 | (setq head (cons | ||
| 114 | (cons | ||
| 115 | (format | ||
| 116 | "%14s %s" | ||
| 117 | (buffer-name elt) | ||
| 118 | (or (buffer-file-name elt) "")) | ||
| 119 | elt) | ||
| 120 | head))) | ||
| 121 | (and head (> (length (car (car head))) maxlen) | ||
| 122 | (setq maxlen (length (car (car head)))))) | ||
| 123 | (setq tail (cdr tail))) | ||
| 124 | (nconc (reverse head) | ||
| 125 | (list (cons (concat (make-string (- (/ maxlen 2) 8) ?\ ) | ||
| 126 | "List All Buffers") | ||
| 127 | 'list-buffers))))))) | ||
| 128 | |||
| 129 | |||
| 130 | (let ((buf (x-popup-menu (if (listp event) event | ||
| 131 | (cons '(0 0) (selected-frame))) | ||
| 132 | menu)) | ||
| 133 | (window (and (listp event) (posn-window (event-start event))))) | ||
| 134 | (if (eq buf 'list-buffers) | ||
| 135 | (list-buffers) | ||
| 136 | (if buf | ||
| 137 | (if complex-buffers-menu-p | ||
| 138 | (let ((action (x-popup-menu (if (listp event) event | ||
| 139 | (cons '(0 0) (selected-frame))) | ||
| 140 | '("Buffer Action" | ||
| 141 | ("" | ||
| 142 | ("Save Buffer" . save-buffer) | ||
| 143 | ("Kill Buffer" . kill-buffer) | ||
| 144 | ("Select Buffer" . switch-to-buffer)))))) | ||
| 145 | (if (eq action 'save-buffer) | ||
| 146 | (save-excursion | ||
| 147 | (set-buffer buf) | ||
| 148 | (save-buffer)) | ||
| 149 | (funcall action buf))) | ||
| 150 | (and (windowp window) | ||
| 151 | (select-window window)) | ||
| 152 | (switch-to-buffer buf))))))) | ||
| 80 | 153 | ||
| 154 | ;; this version is too slow | ||
| 155 | ;;;(defun format-buffers-menu-line (buffer) | ||
| 156 | ;;; "Returns a string to represent the given buffer in the Buffer menu. | ||
| 157 | ;;;nil means the buffer shouldn't be listed. You can redefine this." | ||
| 158 | ;;; (if (string-match "\\` " (buffer-name buffer)) | ||
| 159 | ;;; nil | ||
| 160 | ;;; (save-excursion | ||
| 161 | ;;; (set-buffer buffer) | ||
| 162 | ;;; (let ((size (buffer-size))) | ||
| 163 | ;;; (format "%s%s %-19s %6s %-15s %s" | ||
| 164 | ;;; (if (buffer-modified-p) "*" " ") | ||
| 165 | ;;; (if buffer-read-only "%" " ") | ||
| 166 | ;;; (buffer-name) | ||
| 167 | ;;; size | ||
| 168 | ;;; mode-name | ||
| 169 | ;;; (or (buffer-file-name) "")))))) | ||
| 170 | |||
| 81 | (let ((frames (frame-list))) | 171 | (let ((frames (frame-list))) |
| 82 | (while frames | 172 | (while frames |
| 83 | (modify-frame-parameters (car frames) '((menu-bar-lines . 1))) | 173 | (modify-frame-parameters (car frames) '((menu-bar-lines . 1))) |