1 |
;;; tmm.el --- text mode access to menu-bar |
;;; tmm.el --- text mode access to menu-bar |
2 |
|
|
3 |
;; Copyright (C) 1994, 1995, 1996, 2000, 2001 |
;; Copyright (C) 1994, 1995, 1996, 2000, 2001, 2002 |
4 |
;; Free Software Foundation, Inc. |
;; Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Author: Ilya Zakharevich <ilya@math.mps.ohio-state.edu> |
;; Author: Ilya Zakharevich <ilya@math.mps.ohio-state.edu> |
7 |
;; Maintainer: FSF |
;; Maintainer: FSF |
8 |
|
;; Keywords: convenience |
9 |
|
|
10 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
11 |
|
|
26 |
|
|
27 |
;;; Commentary: |
;;; Commentary: |
28 |
|
|
29 |
;; To use this package add |
;; This package provides text mode access to the menu bar. |
|
|
|
|
;; (autoload 'tmm-menubar 'tmm "Text mode substitute for menubar" t) |
|
|
;; (global-set-key [f10] 'tmm-menubar) |
|
|
;; to your .emacs file. You can also add your own access to different |
|
|
;; menus available in Window System Emacs modeling definition after |
|
|
;; tmm-menubar. |
|
30 |
|
|
31 |
;;; Code: |
;;; Code: |
32 |
|
|
96 |
(tmm-menubar (car (posn-x-y (event-start event))))) |
(tmm-menubar (car (posn-x-y (event-start event))))) |
97 |
|
|
98 |
(defcustom tmm-mid-prompt "==>" |
(defcustom tmm-mid-prompt "==>" |
99 |
"*String to insert between shortcut and menu item. |
"*String to insert between shortcut and menu item. |
100 |
If nil, there will be no shortcuts. It should not consist only of spaces, |
If nil, there will be no shortcuts. It should not consist only of spaces, |
101 |
or else the correct item might not be found in the `*Completions*' buffer." |
or else the correct item might not be found in the `*Completions*' buffer." |
102 |
:type 'string |
:type 'string |
105 |
(defvar tmm-mb-map nil |
(defvar tmm-mb-map nil |
106 |
"A place to store minibuffer map.") |
"A place to store minibuffer map.") |
107 |
|
|
108 |
(defcustom tmm-completion-prompt |
(defcustom tmm-completion-prompt |
109 |
"Press PageUp Key to reach this buffer from the minibuffer. |
"Press PageUp Key to reach this buffer from the minibuffer. |
110 |
Alternatively, you can use Up/Down keys (or your History keys) to change |
Alternatively, you can use Up/Down keys (or your History keys) to change |
111 |
the item in the minibuffer, and press RET when you are done, or press the |
the item in the minibuffer, and press RET when you are done, or press the |
112 |
marked letters to pick up your choice. Type C-g or ESC ESC ESC to cancel. |
marked letters to pick up your choice. Type C-g or ESC ESC ESC to cancel. |
113 |
" |
" |
114 |
"*Help text to insert on the top of the completion buffer. |
"*Help text to insert on the top of the completion buffer. |
118 |
:group 'tmm) |
:group 'tmm) |
119 |
|
|
120 |
(defcustom tmm-shortcut-style '(downcase upcase) |
(defcustom tmm-shortcut-style '(downcase upcase) |
121 |
"*What letters to use as menu shortcuts. |
"*What letters to use as menu shortcuts. |
122 |
Must be either one of the symbols `downcase' or `upcase', |
Must be either one of the symbols `downcase' or `upcase', |
123 |
or else a list of the two in the order you prefer." |
or else a list of the two in the order you prefer." |
124 |
:type '(choice (const downcase) |
:type '(choice (const downcase) |
125 |
(const upcase) |
(const upcase) |
128 |
|
|
129 |
(defcustom tmm-shortcut-words 2 |
(defcustom tmm-shortcut-words 2 |
130 |
"*How many successive words to try for shortcuts, nil means all. |
"*How many successive words to try for shortcuts, nil means all. |
131 |
If you use only one of `downcase' or `upcase' for `tmm-shortcut-style', |
If you use only one of `downcase' or `upcase' for `tmm-shortcut-style', |
132 |
specify nil for this variable." |
specify nil for this variable." |
133 |
:type '(choice integer (const nil)) |
:type '(choice integer (const nil)) |
134 |
:group 'tmm) |
:group 'tmm) |
229 |
;; We just did the inner level of a -popup menu. |
;; We just did the inner level of a -popup menu. |
230 |
choice) |
choice) |
231 |
;; We just did the outer level. Do the inner level now. |
;; We just did the outer level. Do the inner level now. |
232 |
(not-menu (tmm-prompt choice t)) |
(not-menu (tmm-prompt choice t)) |
233 |
;; We just handled a menu keymap and found another keymap. |
;; We just handled a menu keymap and found another keymap. |
234 |
((keymapp choice) |
((keymapp choice) |
235 |
(if (symbolp choice) |
(if (symbolp choice) |
260 |
(defsubst tmm-add-one-shortcut (elt) |
(defsubst tmm-add-one-shortcut (elt) |
261 |
;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts |
;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts |
262 |
(let* ((str (car elt)) |
(let* ((str (car elt)) |
263 |
(paren (string-match "(" str)) |
(paren (string-match "(" str)) |
264 |
(pos 0) (word 0) char) |
(pos 0) (word 0) char) |
265 |
(catch 'done ; ??? is this slow? |
(catch 'done ; ??? is this slow? |
266 |
(while (and (or (not tmm-shortcut-words) ; no limit on words |
(while (and (or (not tmm-shortcut-words) ; no limit on words |
269 |
(not (and paren (> pos paren)))) ; don't go past "(binding.." |
(not (and paren (> pos paren)))) ; don't go past "(binding.." |
270 |
(if (or (= pos 0) |
(if (or (= pos 0) |
271 |
(/= (aref str (1- pos)) ?.)) ; avoid file extensions |
(/= (aref str (1- pos)) ?.)) ; avoid file extensions |
272 |
(let ((shortcut-style |
(let ((shortcut-style |
273 |
(if (listp tmm-shortcut-style) ; convert to list |
(if (listp tmm-shortcut-style) ; convert to list |
274 |
tmm-shortcut-style |
tmm-shortcut-style |
275 |
(list tmm-shortcut-style)))) |
(list tmm-shortcut-style)))) |
325 |
(let ((win (selected-window))) |
(let ((win (selected-window))) |
326 |
(setq tmm-old-mb-map (tmm-define-keys t)) |
(setq tmm-old-mb-map (tmm-define-keys t)) |
327 |
;; Get window and hide it for electric mode to get correct size |
;; Get window and hide it for electric mode to get correct size |
328 |
(save-window-excursion |
(save-window-excursion |
329 |
(let ((completions |
(let ((completions |
330 |
(mapcar 'car minibuffer-completion-table))) |
(mapcar 'car minibuffer-completion-table))) |
331 |
(or tmm-completion-prompt |
(or tmm-completion-prompt |
370 |
(delete-region (minibuffer-prompt-end) (point-max)) |
(delete-region (minibuffer-prompt-end) (point-max)) |
371 |
(mapc (lambda (elt) |
(mapc (lambda (elt) |
372 |
(if (string= |
(if (string= |
373 |
(substring (car elt) 0 |
(substring (car elt) 0 |
374 |
(min (1+ (length tmm-mid-prompt)) |
(min (1+ (length tmm-mid-prompt)) |
375 |
(length (car elt)))) |
(length (car elt)))) |
376 |
(concat (char-to-string c) tmm-mid-prompt)) |
(concat (char-to-string c) tmm-mid-prompt)) |
388 |
(search-forward tmm-c-prompt) |
(search-forward tmm-c-prompt) |
389 |
(search-backward tmm-c-prompt)) |
(search-backward tmm-c-prompt)) |
390 |
|
|
391 |
(defun tmm-get-keymap (elt &optional in-x-menu) |
(defun tmm-get-keymap (elt &optional in-x-menu) |
392 |
"Prepends (DOCSTRING EVENT BINDING) to free variable `tmm-km-list'. |
"Prepends (DOCSTRING EVENT BINDING) to free variable `tmm-km-list'. |
393 |
The values are deduced from the argument ELT, that should be an |
The values are deduced from the argument ELT, that should be an |
394 |
element of keymap, an `x-popup-menu' argument, or an element of |
element of keymap, an `x-popup-menu' argument, or an element of |
395 |
`x-popup-menu' argument (when IN-X-MENU is not-nil). |
`x-popup-menu' argument (when IN-X-MENU is not-nil). |
396 |
This function adds the element only if it is not already present. |
This function adds the element only if it is not already present. |
397 |
It uses the free variable `tmm-table-undef' to keep undefined keys." |
It uses the free variable `tmm-table-undef' to keep undefined keys." |
398 |
(let (km str cache plist filter (event (car elt))) |
(let (km str cache plist filter visible (event (car elt))) |
399 |
(setq elt (cdr elt)) |
(setq elt (cdr elt)) |
400 |
(if (eq elt 'undefined) |
(if (eq elt 'undefined) |
401 |
(setq tmm-table-undef (cons (cons event nil) tmm-table-undef)) |
(setq tmm-table-undef (cons (cons event nil) tmm-table-undef)) |
433 |
(setq filter (plist-get plist :filter)) |
(setq filter (plist-get plist :filter)) |
434 |
(if filter |
(if filter |
435 |
(setq km (funcall filter km))) |
(setq km (funcall filter km))) |
436 |
|
(setq visible (plist-get plist :visible)) |
437 |
|
(if visible |
438 |
|
(setq km (and (eval visible) km))) |
439 |
(and str |
(and str |
440 |
(consp (nth 3 elt)) |
(consp (nth 3 elt)) |
441 |
(stringp (cdr (nth 3 elt))) ; keyseq cache |
(stringp (cdr (nth 3 elt))) ; keyseq cache |
487 |
(progn |
(progn |
488 |
;; Otherwise, it is a prefix, so make a list of the subcommands. |
;; Otherwise, it is a prefix, so make a list of the subcommands. |
489 |
;; Make a list of all the bindings in all the keymaps. |
;; Make a list of all the bindings in all the keymaps. |
490 |
(setq allbind (mapcar 'cdr (minor-mode-key-binding keyseq))) |
(setq allbind (mapcar 'cdr (minor-mode-key-binding keyseq))) |
491 |
(setq allbind (cons (local-key-binding keyseq) allbind)) |
(setq allbind (cons (local-key-binding keyseq) allbind)) |
492 |
(setq allbind (cons (global-key-binding keyseq) allbind)) |
(setq allbind (cons (global-key-binding keyseq) allbind)) |
493 |
;; Merge all the elements of ALLBIND into one keymap. |
;; Merge all the elements of ALLBIND into one keymap. |