Merge from emacs-24; up to 2012-05-07T14:57:18Z!michael.albinus@gmx.de
[bpt/emacs.git] / lisp / tmm.el
index 2a0d1d3..4bc1c9a 100644 (file)
@@ -165,14 +165,13 @@ Its value should be an event that has a binding in MENU."
     ;; tmm-km-list is an alist of (STRING . MEANING).
     ;; It has no other elements.
     ;; The order of elements in tmm-km-list is the order of the menu bar.
-    (mapc (lambda (elt)
-            (cond
-             ((stringp elt) (setq gl-str elt))
-             ((listp elt) (tmm-get-keymap elt not-menu))
-             ((vectorp elt)
-              (dotimes (i (length elt))
-                (tmm-get-keymap (cons i (aref elt i)) not-menu)))))
-          menu)
+    (dolist (elt menu)
+      (cond
+       ((stringp elt) (setq gl-str elt))
+       ((listp elt) (tmm-get-keymap elt not-menu))
+       ((vectorp elt)
+        (dotimes (i (length elt))
+          (tmm-get-keymap (cons i (aref elt i)) not-menu)))))
     ;; Choose an element of tmm-km-list; put it in choice.
     (if (and not-menu (= 1 (length tmm-km-list)))
        ;; If this is the top-level of an x-popup-menu menu,
@@ -230,8 +229,7 @@ Its value should be an event that has a binding in MENU."
                               (- (* 2 history-len) index-of-default))))))))
       (setq choice (cdr (assoc out tmm-km-list)))
       (and (null choice)
-          (> (length out) (length tmm-c-prompt))
-          (string= (substring out 0 (length tmm-c-prompt)) tmm-c-prompt)
+           (string-prefix-p tmm-c-prompt out)
           (setq out (substring out (length tmm-c-prompt))
                 choice (cdr (assoc out tmm-km-list))))
       (and (null choice) out
@@ -313,15 +311,13 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
 (defun tmm-define-keys (minibuffer)
   (let ((map (make-sparse-keymap)))
     (suppress-keymap map t)
-    (mapc
-     (lambda (c)
-       (if (listp tmm-shortcut-style)
-          (define-key map (char-to-string c) 'tmm-shortcut)
-        ;; only one kind of letters are shortcuts, so map both upcase and
-        ;; downcase input to the same
-        (define-key map (char-to-string (downcase c)) 'tmm-shortcut)
-        (define-key map (char-to-string (upcase c)) 'tmm-shortcut)))
-     tmm-short-cuts)
+    (dolist (c tmm-short-cuts)
+      (if (listp tmm-shortcut-style)
+          (define-key map (char-to-string c) 'tmm-shortcut)
+        ;; only one kind of letters are shortcuts, so map both upcase and
+        ;; downcase input to the same
+        (define-key map (char-to-string (downcase c)) 'tmm-shortcut)
+        (define-key map (char-to-string (upcase c)) 'tmm-shortcut)))
     (if minibuffer
        (progn
           (define-key map [pageup] 'tmm-goto-completions)
@@ -333,9 +329,9 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
       (use-local-map (append map (current-local-map))))))
 
 (defun tmm-completion-delete-prompt ()
-  (set-buffer standard-output)
+  (with-current-buffer standard-output
   (goto-char (point-min))
-  (delete-region (point) (search-forward "Possible completions are:\n")))
+    (delete-region (point) (search-forward "Possible completions are:\n"))))
 
 (defun tmm-remove-inactive-mouse-face ()
   "Remove the mouse-face property from inactive menu items."
@@ -354,38 +350,24 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
     (set-buffer-modified-p nil)))
 
 (defun tmm-add-prompt ()
-  (add-hook 'minibuffer-exit-hook 'tmm-delete-map nil t)
   (unless tmm-c-prompt
     (error "No active menu entries"))
   (setq tmm-old-mb-map (tmm-define-keys t))
   ;; Get window and hide it for electric mode to get correct size
-  (save-window-excursion
-    (let ((completions
-           (mapcar 'car minibuffer-completion-table)))
-      (or tmm-completion-prompt
-          (add-hook 'completion-setup-hook
-                    'tmm-completion-delete-prompt 'append))
-      (unwind-protect
-          (with-output-to-temp-buffer "*Completions*"
-            (display-completion-list completions))
-        (remove-hook 'completion-setup-hook 'tmm-completion-delete-prompt)))
-    (set-buffer "*Completions*")
+  (or tmm-completion-prompt
+      (add-hook 'completion-setup-hook
+                'tmm-completion-delete-prompt 'append))
+  (unwind-protect
+      (minibuffer-completion-help)
+    (remove-hook 'completion-setup-hook 'tmm-completion-delete-prompt))
+  (with-current-buffer "*Completions*"
     (tmm-remove-inactive-mouse-face)
     (when tmm-completion-prompt
-      (let ((buffer-read-only nil))
-        (goto-char (point-min))
-        (insert tmm-completion-prompt))))
-  (save-selected-window
-    (other-window 1)                   ; Electric-pop-up-window does
-                                       ; not work in minibuffer
-    (Electric-pop-up-window "*Completions*"))
+      (let ((inhibit-read-only t))
+       (goto-char (point-min))
+       (insert tmm-completion-prompt))))
   (insert tmm-c-prompt))
 
-(defun tmm-delete-map ()
-  (remove-hook 'minibuffer-exit-hook 'tmm-delete-map t)
-  (if tmm-old-mb-map
-      (use-local-map tmm-old-mb-map)))
-
 (defun tmm-shortcut ()
   "Choose the shortcut that the user typed."
   (interactive)
@@ -401,14 +383,13 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
              (choose-completion))
          ;; In minibuffer
          (delete-region (minibuffer-prompt-end) (point-max))
-         (mapc (lambda (elt)
-                 (if (string=
-                      (substring (car elt) 0
-                                 (min (1+ (length tmm-mid-prompt))
-                                      (length (car elt))))
-                      (concat (char-to-string c) tmm-mid-prompt))
-                     (setq s (car elt))))
-                 tmm-km-list)
+         (dolist (elt tmm-km-list)
+            (if (string=
+                 (substring (car elt) 0
+                            (min (1+ (length tmm-mid-prompt))
+                                 (length (car elt))))
+                 (concat (char-to-string c) tmm-mid-prompt))
+                (setq s (car elt))))
          (insert s)
          (exit-minibuffer)))))
 
@@ -524,6 +505,10 @@ of `menu-bar-final-items'."
        (progn
          ;; Otherwise, it is a prefix, so make a list of the subcommands.
          ;; Make a list of all the bindings in all the keymaps.
+          ;; FIXME: we'd really like to just use `key-binding' now that it
+          ;; returns a keymap that contains really all the bindings under that
+          ;; prefix, but `keyseq' is always [menu-bar], so the desired order of
+          ;; the bindings is difficult to recover.
          (setq minorbind (mapcar 'cdr (minor-mode-key-binding keyseq)))
          (setq localbind (local-key-binding keyseq))
          (setq globalbind (copy-sequence (cdr (global-key-binding keyseq))))
@@ -540,20 +525,16 @@ of `menu-bar-final-items'."
          (setq allbind (cons globalbind (cons localbind minorbind)))
 
          ;; Merge all the elements of ALLBIND into one keymap.
-         (mapc (lambda (in)
-                 (if (and (symbolp in) (keymapp in))
-                     (setq in (symbol-function in)))
-                 (and in (keymapp in)
-                      (if (keymapp bind)
-                          (setq bind (nconc bind (copy-sequence (cdr in))))
-                        (setq bind (copy-sequence in)))))
-                 allbind)
+         (dolist (in allbind)
+            (if (and (symbolp in) (keymapp in))
+                (setq in (symbol-function in)))
+            (and in (keymapp in)
+                 (setq bind (if (keymapp bind)
+                                (nconc bind (copy-sequence (cdr in)))
+                              (copy-sequence in)))))
          ;; Return that keymap.
          bind))))
 
-;; Huh?  What's that about?  --Stef
-(add-hook 'calendar-load-hook (lambda () (require 'cal-menu)))
-
 (provide 'tmm)
 
 ;;; tmm.el ends here