Mercurial > emacs
annotate lisp/tmm.el @ 13448:89f89cadc30d
(update_line): Avoid indexing into obody by -1.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 10 Nov 1995 06:38:23 +0000 |
parents | 84acc3adcd63 |
children | edc4a329403e |
rev | line source |
---|---|
13337 | 1 ;;; tmm.el --- text mode access to menu-bar |
10955 | 2 |
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Ilya Zakharevich <ilya@math.mps.ohio-state.edu> | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
6 ;; Maintainer: FSF |
10955 | 7 |
10956 | 8 ;; This file is part of GNU Emacs. |
10955 | 9 |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Commentary ============================================================ | |
25 | |
26 ;;; To use this package add | |
27 | |
28 ;;; (autoload 'tmm-menubar 'tmm "Text mode substitute for menubar" t) | |
29 ;;; (global-set-key [f10] 'tmm-menubar) | |
30 | |
31 ;;; to your .emacs file. You can also add your own access to different | |
32 ;;; menus available in Window System Emacs modelling definition after | |
33 ;;; tmm-menubar. | |
34 | |
35 (require 'electric) | |
36 | |
37 ;;; The following will be localized, added only to pacify the compiler. | |
38 (defvar tmm-short-cuts) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
39 (defvar tmm-old-mb-map nil) |
10955 | 40 (defvar tmm-old-comp-map) |
41 (defvar tmm-c-prompt) | |
42 (defvar tmm-km-list) | |
43 (defvar tmm-table-undef) | |
44 | |
12960
6db607a7b62d
Fix typo in global-map define.
Richard M. Stallman <rms@gnu.org>
parents:
12763
diff
changeset
|
45 ;;;###autoload (define-key global-map "\M-`" 'tmm-menubar) |
12763
b8e986069a58
Don't alter bindings in minibuffer-local-must-match-map
Richard M. Stallman <rms@gnu.org>
parents:
10956
diff
changeset
|
46 |
10955 | 47 ;;;###autoload |
48 (defun tmm-menubar () | |
49 "Text-mode emulation of looking and choosing from a menubar. | |
50 See the documentation for `tmm-prompt'." | |
51 (interactive) | |
52 (run-hooks 'menu-bar-update-hook) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
53 ;; Obey menu-bar-final-items; put those items last. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
54 (let ((menu-bar (tmm-get-keybind [menu-bar]))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
55 (let ((list menu-bar-final-items)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
56 (while list |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
57 (let ((item (car list))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
58 ;; ITEM is the name of an item that we want to put last. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
59 ;; Find it in MENU-BAR and move it to the end. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
60 (let ((this-one (assq item menu-bar))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
61 (setq menu-bar (append (delq this-one menu-bar) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
62 (list this-one))))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
63 (setq list (cdr list)))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
64 (tmm-prompt menu-bar))) |
10955 | 65 |
66 (defvar tmm-mid-prompt "==>" | |
67 "String to insert between shortcut and menu item or nil.") | |
68 | |
69 (defvar tmm-mb-map nil | |
70 "A place to store minibuffer map.") | |
71 | |
72 (defvar tmm-completion-prompt | |
73 "Press PageUp Key to reach this buffer from the minibuffer. | |
74 Alternatively, you can use Up/Down keys (or your History keys) to change | |
75 the item in the minibuffer, and press RET when you are done, or press the | |
12763
b8e986069a58
Don't alter bindings in minibuffer-local-must-match-map
Richard M. Stallman <rms@gnu.org>
parents:
10956
diff
changeset
|
76 marked letters to pick up your choice. Type ESC ESC to cancel. |
10955 | 77 " |
78 "What insert on top of completion buffer.") | |
79 | |
80 ;;;###autoload | |
81 (defun tmm-prompt (bind &optional in-popup) | |
82 "Text-mode emulation of calling the bindings in keymap. | |
83 Creates a text-mode menu of possible choices. You can access the elements | |
84 in the menu: | |
85 *) Either via history mechanism from minibuffer; | |
86 *) Or via completion-buffer that is automatically shown. | |
87 The last alternative is currently a hack, you cannot use mouse reliably. | |
88 If the optional argument IN-POPUP is set, is argument-compatible with | |
89 `x-popup-menu', otherwise the argument BIND should be a cdr of sparse keymap." | |
90 (if in-popup (if bind (setq bind in-popup) (x-popup-menu nil in-popup))) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
91 (let (gl-str tmm-km-list out history history-len tmm-table-undef tmm-c-prompt |
10955 | 92 tmm-old-mb-map tmm-old-comp-map tmm-short-cuts) |
93 (run-hooks 'activate-menubar-hook) | |
94 (mapcar (function (lambda (elt) | |
95 (if (stringp elt) | |
96 (setq gl-str elt) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
97 (and (listp elt) (tmm-get-keymap elt in-popup))))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
98 bind) |
10955 | 99 (and tmm-km-list |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
100 (progn |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
101 (if tmm-mid-prompt |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
102 (setq tmm-km-list (tmm-add-shortcuts tmm-km-list)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
103 t) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
104 (setq history (reverse (mapcar 'car tmm-km-list))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
105 (setq history-len (length history)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
106 (setq history (append history history history history)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
107 (setq tmm-c-prompt (nth (1- history-len) history)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
108 (add-hook 'minibuffer-setup-hook 'tmm-add-prompt) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
109 (unwind-protect |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
110 (setq out |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
111 (completing-read |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
112 (concat gl-str " (up/down to change, PgUp to menu): ") |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
113 tmm-km-list nil t nil |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
114 (cons 'history (* 2 history-len)))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
115 (save-excursion |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
116 (set-buffer "*Completions*") |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
117 (use-local-map tmm-old-comp-map) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
118 (bury-buffer (current-buffer))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
119 ))) |
10955 | 120 (setq bind (cdr (assoc out tmm-km-list))) |
121 (and (null bind) | |
122 (> (length out) (length tmm-c-prompt)) | |
123 (string= (substring out 0 (length tmm-c-prompt)) tmm-c-prompt) | |
124 (setq out (substring out (length tmm-c-prompt)) | |
125 bind (cdr (assoc out tmm-km-list)))) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
126 (and (null bind) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
127 (setq out (try-completion out tmm-km-list) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
128 bind (cdr (assoc out tmm-km-list)))) |
10955 | 129 (setq last-command-event (car bind)) |
130 (setq bind (cdr bind)) | |
131 (if bind | |
132 (if in-popup (tmm-prompt t bind) | |
133 (if (keymapp bind) | |
134 (if (listp bind) | |
135 (progn | |
136 (condition-case nil | |
137 (require 'mouse) | |
138 (error nil)) | |
139 (condition-case nil | |
140 (x-popup-menu nil bind) ; Get the shortcuts | |
141 (error nil)) | |
142 (tmm-prompt bind)) | |
143 (tmm-prompt (symbol-value bind)) | |
144 ) | |
145 (if last-command-event | |
146 (call-interactively bind) | |
147 bind))) | |
148 gl-str))) | |
149 | |
150 | |
151 (defun tmm-add-shortcuts (list) | |
152 "Adds shortcuts to cars of elements of the list. | |
153 Takes a list of lists with a string as car, returns list with | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
154 shortcuts added to these cars. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
155 Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
156 (let ((next-shortcut-number 0)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
157 (mapcar (lambda (elt) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
158 (let ((str (car elt)) f b) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
159 (setq f (upcase (substring str 0 1))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
160 ;; If does not work, try beginning of the other word |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
161 (if (and (member f tmm-short-cuts) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
162 (string-match " \\([^ ]\\)" str)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
163 (setq f (upcase (substring |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
164 str |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
165 (setq b (match-beginning 1)) (1+ b))))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
166 ;; If we don't have an unique letter shortcut, |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
167 ;; pick a digit as a shortcut instead. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
168 (if (member f tmm-short-cuts) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
169 (if (< next-shortcut-number 10) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
170 (setq f (format "%d" next-shortcut-number) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
171 next-shortcut-number (1+ next-shortcut-number)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
172 (setq f nil))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
173 (if (null f) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
174 elt |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
175 (setq tmm-short-cuts (cons f tmm-short-cuts)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
176 (cons (concat f tmm-mid-prompt str) (cdr elt))))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
177 (reverse list)))) |
10955 | 178 |
179 (defun tmm-add-prompt () | |
180 (remove-hook 'minibuffer-setup-hook 'tmm-add-prompt) | |
12763
b8e986069a58
Don't alter bindings in minibuffer-local-must-match-map
Richard M. Stallman <rms@gnu.org>
parents:
10956
diff
changeset
|
181 (make-local-hook 'minibuffer-exit-hook) |
b8e986069a58
Don't alter bindings in minibuffer-local-must-match-map
Richard M. Stallman <rms@gnu.org>
parents:
10956
diff
changeset
|
182 (add-hook 'minibuffer-exit-hook 'tmm-delete-map nil t) |
10955 | 183 (let ((map (make-sparse-keymap)) (win (selected-window))) |
184 (mapcar (lambda (str) | |
185 (define-key map str 'tmm-shortcut) | |
186 (define-key map (downcase str) 'tmm-shortcut)) | |
187 tmm-short-cuts) | |
188 (setq tmm-old-mb-map (current-local-map)) | |
189 (use-local-map (append map (cdr tmm-old-mb-map))) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
190 (define-key (current-local-map) [pageup] 'tmm-goto-completions) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
191 (define-key (current-local-map) [prior] 'tmm-goto-completions) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
192 (define-key (current-local-map) "\ev" 'tmm-goto-completions) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
193 (define-key (current-local-map) "\e\e" 'abort-recursive-edit) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
194 (define-key (current-local-map) "\C-n" 'next-history-element) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
195 (define-key (current-local-map) "\C-p" 'previous-history-element) |
10955 | 196 ;; Get window and hide it for electric mode to get correct size |
197 (save-window-excursion | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
198 (let ((completions |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
199 (mapcar 'car minibuffer-completion-table))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
200 (with-output-to-temp-buffer "*Completions*" |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
201 (display-completion-list completions))) |
10955 | 202 (set-buffer "*Completions*") |
203 (goto-char 1) | |
204 (insert tmm-completion-prompt) | |
205 ) | |
206 (save-excursion | |
207 (other-window 1) ; Electric-pop-up-window does | |
208 ; not work in minibuffer | |
209 (set-buffer (window-buffer (Electric-pop-up-window "*Completions*"))) | |
210 (setq tmm-old-comp-map (current-local-map)) | |
211 (use-local-map (append map (cdr tmm-old-comp-map))) | |
212 (select-window win) ; Cannot use | |
213 ; save-window-excursion, since | |
214 ; it restores the size | |
215 ) | |
216 (insert tmm-c-prompt))) | |
217 | |
218 (defun tmm-delete-map () | |
12763
b8e986069a58
Don't alter bindings in minibuffer-local-must-match-map
Richard M. Stallman <rms@gnu.org>
parents:
10956
diff
changeset
|
219 (remove-hook 'minibuffer-exit-hook 'tmm-delete-map t) |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
220 (if tmm-old-mb-map |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
221 (use-local-map tmm-old-mb-map))) |
10955 | 222 |
223 (defun tmm-shortcut () | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
224 "Choose the shortcut that the user typed." |
10955 | 225 (interactive) |
226 (let ((c (upcase (char-to-string last-command-char))) s) | |
227 (if (member c tmm-short-cuts) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
228 (if (equal (buffer-name) "*Completions*") |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
229 (progn |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
230 (beginning-of-buffer) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
231 (re-search-forward |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
232 (concat "\\(^\\|[ \t]\\)" c tmm-mid-prompt)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
233 (choose-completion)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
234 (erase-buffer) ; In minibuffer |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
235 (mapcar (lambda (elt) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
236 (if (string= |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
237 (substring (car elt) 0 |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
238 (min (1+ (length tmm-mid-prompt)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
239 (length (car elt)))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
240 (concat c tmm-mid-prompt)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
241 (setq s (car elt)))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
242 tmm-km-list) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
243 (insert s) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
244 (exit-minibuffer))))) |
10955 | 245 |
246 (defun tmm-goto-completions () | |
247 (interactive) | |
248 (setq tmm-c-prompt (buffer-string)) | |
249 (erase-buffer) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
250 (switch-to-buffer-other-window "*Completions*") |
10955 | 251 (search-forward tmm-c-prompt) |
252 (search-backward tmm-c-prompt)) | |
253 | |
254 | |
255 (defun tmm-get-keymap (elt &optional in-x-menu) | |
256 "Prepends (DOCSTRING EVENT BINDING) to free variable `tmm-km-list'. | |
257 The values are deduced from the argument ELT, that should be an | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
258 element of keymap, an `x-popup-menu' argument, or an element of |
10955 | 259 `x-popup-menu' argument (when IN-X-MENU is not-nil). |
260 Does it only if it is not already there. Uses free variable | |
261 `tmm-table-undef' to keep undefined keys." | |
262 (let (km str cache (event (car elt))) | |
263 (setq elt (cdr elt)) | |
264 (if (eq elt 'undefined) | |
265 (setq tmm-table-undef (cons (cons event nil) tmm-table-undef)) | |
266 (or | |
267 (assoc event tmm-table-undef) | |
268 (and (if (listp elt) | |
269 (keymapp elt) | |
270 (fboundp elt)) | |
271 (setq km elt)) | |
272 (and (if (listp (cdr-safe elt)) | |
273 (keymapp (cdr-safe elt)) | |
274 (fboundp (cdr-safe elt))) | |
275 (setq km (cdr elt)) | |
276 (and (stringp (car elt)) (setq str (car elt)))) | |
277 (and (if (listp (cdr-safe (cdr-safe elt))) | |
278 (keymapp (cdr-safe (cdr-safe elt))) | |
279 (fboundp (cdr-safe (cdr-safe elt)))) | |
280 (setq km (cdr (cdr elt))) | |
281 (and (stringp (car elt)) (setq str (car elt))) | |
282 (or (and str | |
283 (stringp (cdr (car (cdr elt)))) ; keyseq cache | |
284 (setq cache (cdr (car (cdr elt)))) | |
285 cache (setq str (concat str cache))) str)) | |
286 (and (if (listp (cdr-safe (cdr-safe (cdr-safe elt)))) | |
287 (keymapp (cdr-safe (cdr-safe (cdr-safe elt)))) | |
288 (fboundp (cdr-safe (cdr-safe (cdr-safe elt))))) | |
289 ; New style of easy-menu | |
290 (setq km (cdr (cdr (cdr elt)))) | |
291 (and (stringp (car elt)) (setq str (car elt))) | |
292 (or (and str | |
293 (stringp (cdr (car (cdr (cdr elt))))) ; keyseq cache | |
294 (setq cache (cdr (car (cdr (cdr elt))))) | |
295 cache (setq str (concat str cache))) | |
296 str)) | |
297 (and (stringp event) ; x-popup or x-popup element | |
298 (if (or in-x-menu (stringp (car-safe elt))) | |
299 (setq str event event nil km elt) | |
300 (setq str event event nil km (cons 'keymap elt)) | |
301 ))) | |
302 (and km (stringp km) (setq str km)) | |
303 (and km str | |
304 (or (assoc str tmm-km-list) | |
305 (setq tmm-km-list | |
306 (cons (cons str (cons event km)) tmm-km-list))) | |
307 )))) | |
308 | |
309 | |
310 (defun tmm-get-keybind (keyseq) | |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
311 "Return the current binding of KEYSEQ, merging prefix definitions. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
312 If KEYSEQ is a prefix key that has local and gloibal bindings, |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
313 we merge them into a single keymap which shows the proper order of the menu. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
314 However, for the menu bar itself, the value does not take account |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
315 of `menu-bar-final-items'." |
10955 | 316 (let (allbind bind) |
13334
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
317 (setq bind (key-binding keyseq)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
318 ;; If KEYSEQ is a prefix key, then BIND is either nil |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
319 ;; or a symbol defined as a keymap (which satisfies keymapp). |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
320 (if (keymapp bind) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
321 (setq bind nil)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
322 ;; If we have a non-keymap definition, return that. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
323 (or bind |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
324 (progn |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
325 ;; Otherwise, it is a prefix, so make a list of the subcommands. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
326 ;; Make a list of all the bindings in all the keymaps. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
327 (setq allbind (mapcar 'cdr (minor-mode-key-binding keyseq))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
328 (setq allbind (cons (local-key-binding keyseq) allbind)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
329 (setq allbind (cons (global-key-binding keyseq) allbind)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
330 ;; Merge all the elements of ALLBIND into one keymap. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
331 (mapcar (lambda (in) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
332 (if (and (symbolp in) (keymapp in)) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
333 (setq in (symbol-function in))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
334 (and in (keymapp in) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
335 (if (keymapp bind) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
336 (setq bind (nconc bind (copy-sequence (cdr in)))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
337 (setq bind (copy-sequence in))))) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
338 allbind) |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
339 ;; Return that keymap. |
c55f17d3931f
(tmm-old-mb-map): Initialize to nil.
Richard M. Stallman <rms@gnu.org>
parents:
12960
diff
changeset
|
340 bind)))) |
10955 | 341 |
342 (add-hook 'calendar-load-hook (lambda () (require 'cal-menu))) | |
343 | |
344 | |
345 (provide 'tmm) | |
346 | |
347 | |
348 ;;; tmm.el ends here |