Mercurial > emacs
comparison lisp/mouse.el @ 92046:3831642b30d0
* mouse.el (minor-mode-menu-from-indicator): Create a menu with a
"Turn off" and a "Help" entry when the minor mode has no menu.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Thu, 21 Feb 2008 09:15:32 +0000 |
parents | 14af2d089808 |
children | 425b4f72a3dc |
comparison
equal
deleted
inserted
replaced
92045:eeb9265e0ea5 | 92046:3831642b30d0 |
---|---|
150 (setq last-command-event (car (last event))) | 150 (setq last-command-event (car (last event))) |
151 ;; mouse-major-mode-menu was using `command-execute' instead. | 151 ;; mouse-major-mode-menu was using `command-execute' instead. |
152 (call-interactively cmd)))) | 152 (call-interactively cmd)))) |
153 | 153 |
154 (defun minor-mode-menu-from-indicator (indicator) | 154 (defun minor-mode-menu-from-indicator (indicator) |
155 "Show menu, if any, for minor mode specified by INDICATOR. | 155 "Show menu for minor mode specified by INDICATOR. |
156 Interactively, INDICATOR is read using completion." | 156 Interactively, INDICATOR is read using completion. |
157 (interactive (list (completing-read "Minor mode indicator: " | 157 If there is no menu defined for the minor mode, then create one with |
158 (describe-minor-mode-completion-table-for-indicator)))) | 158 items `Turn Off' and `Help'." |
159 (interactive | |
160 (list (completing-read | |
161 "Minor mode indicator: " | |
162 (describe-minor-mode-completion-table-for-indicator)))) | |
159 (let ((minor-mode (lookup-minor-mode-from-indicator indicator))) | 163 (let ((minor-mode (lookup-minor-mode-from-indicator indicator))) |
160 (if minor-mode | 164 (unless minor-mode (error "Cannot find minor mode for `%s'" indicator)) |
161 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist))) | 165 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist))) |
162 (menu (and (keymapp map) (lookup-key map [menu-bar])))) | 166 (menu (and (keymapp map) (lookup-key map [menu-bar])))) |
163 (if menu | 167 (unless menu |
164 (popup-menu menu) | 168 (setq menu |
165 (message "No menu for minor mode `%s'" minor-mode))) | 169 `(keymap |
166 (error "Cannot find minor mode for `%s'" indicator)))) | 170 (,(intern indicator) ,indicator |
171 keymap | |
172 (turn-off menu-item "Turn Off minor mode" | |
173 (lambda () | |
174 (interactive) | |
175 (,minor-mode -1) | |
176 (message ,(format "`%S' turned OFF" minor-mode)))) | |
177 (help menu-item "Help for minor mode" | |
178 (lambda () (interactive) | |
179 (describe-function | |
180 ',minor-mode))))))) | |
181 (popup-menu menu)))) | |
167 | 182 |
168 (defun mouse-minor-mode-menu (event) | 183 (defun mouse-minor-mode-menu (event) |
169 "Show minor-mode menu for EVENT on minor modes area of the mode line." | 184 "Show minor-mode menu for EVENT on minor modes area of the mode line." |
170 (interactive "@e") | 185 (interactive "@e") |
171 (let ((indicator (car (nth 4 (car (cdr event)))))) | 186 (let ((indicator (car (nth 4 (car (cdr event)))))) |