annotate lisp/tmm.el @ 13550:06e46fbae7f0

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