aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Roberts2005-06-03 11:24:06 +0000
committerNick Roberts2005-06-03 11:24:06 +0000
commit04a5d30f456ea68f17c8fb593e85ef74c9893a81 (patch)
tree22dead2ad794058590067770409286d75e83d77c
parent76668788b504bdfce0521492a4da5d3cd4de2eeb (diff)
downloademacs-04a5d30f456ea68f17c8fb593e85ef74c9893a81.tar.gz
emacs-04a5d30f456ea68f17c8fb593e85ef74c9893a81.zip
(tmm-inactive-face): New face.
(tmm-remove-inactive-mouse-face): New function. (tmm-prompt, tmm-add-one-shortcut) (tmm-add-prompt, tmm-get-keymap): Make active menu items visible but not selectable.
-rw-r--r--lisp/tmm.el110
1 files changed, 73 insertions, 37 deletions
diff --git a/lisp/tmm.el b/lisp/tmm.el
index 168dbdd14dc..51e04941730 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -133,6 +133,12 @@ specify nil for this variable."
133 :type '(choice integer (const nil)) 133 :type '(choice integer (const nil))
134 :group 'tmm) 134 :group 'tmm)
135 135
136(require 'font-lock)
137(defface tmm-inactive-face
138 '((t :inherit font-lock-comment-face))
139 "Face used for inactive menu items."
140 :group 'tmm)
141
136;;;###autoload 142;;;###autoload
137(defun tmm-prompt (menu &optional in-popup default-item) 143(defun tmm-prompt (menu &optional in-popup default-item)
138 "Text-mode emulation of calling the bindings in keymap. 144 "Text-mode emulation of calling the bindings in keymap.
@@ -193,7 +199,14 @@ Its value should be an event that has a binding in MENU."
193 (eq (car-safe (cdr (car tail))) 'menu-item))) 199 (eq (car-safe (cdr (car tail))) 'menu-item)))
194 (setq index-of-default (1+ index-of-default))) 200 (setq index-of-default (1+ index-of-default)))
195 (setq tail (cdr tail))))) 201 (setq tail (cdr tail)))))
196 (setq history (reverse (mapcar 'car tmm-km-list))) 202 (let ((prompt (concat "^." (regexp-quote tmm-mid-prompt))))
203 (setq history
204 (reverse (delq nil
205 (mapcar
206 (lambda (elt)
207 (if (string-match prompt (car elt))
208 (car elt)))
209 tmm-km-list)))))
197 (setq history-len (length history)) 210 (setq history-len (length history))
198 (setq history (append history history history history)) 211 (setq history (append history history history history))
199 (setq tmm-c-prompt (nth (- history-len 1 index-of-default) history)) 212 (setq tmm-c-prompt (nth (- history-len 1 index-of-default) history))
@@ -259,37 +272,43 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
259 272
260(defsubst tmm-add-one-shortcut (elt) 273(defsubst tmm-add-one-shortcut (elt)
261;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts 274;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts
262 (let* ((str (car elt)) 275 (cond
263 (paren (string-match "(" str)) 276 ((eq (cddr elt) 'ignore)
264 (pos 0) (word 0) char) 277 (cons (concat " " (make-string (length tmm-mid-prompt) ?\-)
265 (catch 'done ; ??? is this slow? 278 (car elt))
266 (while (and (or (not tmm-shortcut-words) ; no limit on words 279 (cdr elt)))
267 (< word tmm-shortcut-words)) ; try n words 280 (t
268 (setq pos (string-match "\\w+" str pos)) ; get next word 281 (let* ((str (car elt))
269 (not (and paren (> pos paren)))) ; don't go past "(binding.." 282 (paren (string-match "(" str))
270 (if (or (= pos 0) 283 (pos 0) (word 0) char)
271 (/= (aref str (1- pos)) ?.)) ; avoid file extensions 284 (catch 'done ; ??? is this slow?
272 (let ((shortcut-style 285 (while (and (or (not tmm-shortcut-words) ; no limit on words
273 (if (listp tmm-shortcut-style) ; convert to list 286 (< word tmm-shortcut-words)) ; try n words
274 tmm-shortcut-style 287 (setq pos (string-match "\\w+" str pos)) ; get next word
275 (list tmm-shortcut-style)))) 288 (not (and paren (> pos paren)))) ; don't go past "(binding.."
276 (while shortcut-style ; try upcase and downcase variants 289 (if (or (= pos 0)
277 (setq char (funcall (car shortcut-style) (aref str pos))) 290 (/= (aref str (1- pos)) ?.)) ; avoid file extensions
278 (if (not (memq char tmm-short-cuts)) (throw 'done char)) 291 (let ((shortcut-style
279 (setq shortcut-style (cdr shortcut-style))))) 292 (if (listp tmm-shortcut-style) ; convert to list
280 (setq word (1+ word)) 293 tmm-shortcut-style
281 (setq pos (match-end 0))) 294 (list tmm-shortcut-style))))
282 (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit 295 (while shortcut-style ; try upcase and downcase variants
283 (setq char tmm-next-shortcut-digit) 296 (setq char (funcall (car shortcut-style) (aref str pos)))
284 (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit)) 297 (if (not (memq char tmm-short-cuts)) (throw 'done char))
285 (if (not (memq char tmm-short-cuts)) (throw 'done char))) 298 (setq shortcut-style (cdr shortcut-style)))))
286 (setq char nil)) 299 (setq word (1+ word))
287 (if char (setq tmm-short-cuts (cons char tmm-short-cuts))) 300 (setq pos (match-end 0)))
288 (cons (concat (if char (concat (char-to-string char) tmm-mid-prompt) 301 (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit
289 ;; keep them lined up in columns 302 (setq char tmm-next-shortcut-digit)
290 (make-string (1+ (length tmm-mid-prompt)) ?\ )) 303 (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit))
291 str) 304 (if (not (memq char tmm-short-cuts)) (throw 'done char)))
292 (cdr elt)))) 305 (setq char nil))
306 (if char (setq tmm-short-cuts (cons char tmm-short-cuts)))
307 (cons (concat (if char (concat (char-to-string char) tmm-mid-prompt)
308 ;; keep them lined up in columns
309 (make-string (1+ (length tmm-mid-prompt)) ?\ ))
310 str)
311 (cdr elt))))))
293 312
294;; This returns the old map. 313;; This returns the old map.
295(defun tmm-define-keys (minibuffer) 314(defun tmm-define-keys (minibuffer)
@@ -319,9 +338,27 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
319 (goto-char 1) 338 (goto-char 1)
320 (delete-region 1 (search-forward "Possible completions are:\n"))) 339 (delete-region 1 (search-forward "Possible completions are:\n")))
321 340
341(defun tmm-remove-inactive-mouse-face ()
342 "Remove the mouse-face property from inactive menu items."
343 (let ((inhibit-read-only t)
344 (inactive-string
345 (concat " " (make-string (length tmm-mid-prompt) ?\-)))
346 next)
347 (save-excursion
348 (goto-char (point-min))
349 (while (not (eobp))
350 (setq next (next-single-char-property-change (point) 'mouse-face))
351 (when (looking-at inactive-string)
352 (remove-text-properties (point) next '(mouse-face))
353 (add-text-properties (point) next '(face tmm-inactive-face)))
354 (goto-char next)))
355 (set-buffer-modified-p nil)))
356
322(defun tmm-add-prompt () 357(defun tmm-add-prompt ()
323 (remove-hook 'minibuffer-setup-hook 'tmm-add-prompt) 358 (remove-hook 'minibuffer-setup-hook 'tmm-add-prompt)
324 (add-hook 'minibuffer-exit-hook 'tmm-delete-map nil t) 359 (add-hook 'minibuffer-exit-hook 'tmm-delete-map nil t)
360 (unless tmm-c-prompt
361 (error "No active menu entries"))
325 (let ((win (selected-window))) 362 (let ((win (selected-window)))
326 (setq tmm-old-mb-map (tmm-define-keys t)) 363 (setq tmm-old-mb-map (tmm-define-keys t))
327 ;; Get window and hide it for electric mode to get correct size 364 ;; Get window and hide it for electric mode to get correct size
@@ -334,8 +371,9 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
334 (with-output-to-temp-buffer "*Completions*" 371 (with-output-to-temp-buffer "*Completions*"
335 (display-completion-list completions)) 372 (display-completion-list completions))
336 (remove-hook 'completion-setup-hook 'tmm-completion-delete-prompt)) 373 (remove-hook 'completion-setup-hook 'tmm-completion-delete-prompt))
374 (set-buffer "*Completions*")
375 (tmm-remove-inactive-mouse-face)
337 (when tmm-completion-prompt 376 (when tmm-completion-prompt
338 (set-buffer "*Completions*")
339 (let ((buffer-read-only nil)) 377 (let ((buffer-read-only nil))
340 (goto-char (point-min)) 378 (goto-char (point-min))
341 (insert tmm-completion-prompt)))) 379 (insert tmm-completion-prompt))))
@@ -345,7 +383,6 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
345 (Electric-pop-up-window "*Completions*") 383 (Electric-pop-up-window "*Completions*")
346 (with-current-buffer "*Completions*" 384 (with-current-buffer "*Completions*"
347 (setq tmm-old-comp-map (tmm-define-keys nil)))) 385 (setq tmm-old-comp-map (tmm-define-keys nil))))
348
349 (insert tmm-c-prompt))) 386 (insert tmm-c-prompt)))
350 387
351(defun tmm-delete-map () 388(defun tmm-delete-map ()
@@ -438,7 +475,7 @@ It uses the free variable `tmm-table-undef' to keep undefined keys."
438 (setq km (and (eval visible) km))) 475 (setq km (and (eval visible) km)))
439 (setq enable (plist-get plist :enable)) 476 (setq enable (plist-get plist :enable))
440 (if enable 477 (if enable
441 (setq km (and (eval enable) km))) 478 (setq km (if (eval enable) km 'ignore)))
442 (and str 479 (and str
443 (consp (nth 3 elt)) 480 (consp (nth 3 elt))
444 (stringp (cdr (nth 3 elt))) ; keyseq cache 481 (stringp (cdr (nth 3 elt))) ; keyseq cache
@@ -467,8 +504,7 @@ It uses the free variable `tmm-table-undef' to keep undefined keys."
467 ;; Verify that the command is enabled; 504 ;; Verify that the command is enabled;
468 ;; if not, don't mention it. 505 ;; if not, don't mention it.
469 (when (and km (symbolp km) (get km 'menu-enable)) 506 (when (and km (symbolp km) (get km 'menu-enable))
470 (unless (eval (get km 'menu-enable)) 507 (setq km (if (eval (get km 'menu-enable)) km 'ignore)))
471 (setq km nil)))
472 (and km str 508 (and km str
473 (or (assoc str tmm-km-list) 509 (or (assoc str tmm-km-list)
474 (push (cons str (cons event km)) tmm-km-list)))))) 510 (push (cons str (cons event km)) tmm-km-list))))))