]> code.delx.au - gnu-emacs-elpa/commitdiff
* temp-buffer-browse.el: Use set-transient-map instead
authorLeo Liu <sdl.web@gmail.com>
Sat, 8 Feb 2014 04:44:09 +0000 (12:44 +0800)
committerLeo Liu <sdl.web@gmail.com>
Sat, 8 Feb 2014 04:44:15 +0000 (12:44 +0800)
temp-buffer-browse.el

index da2fb7330307d6e63e13d90ae8d2c94ac685994c..7d03b7749fb2edd05c1c76f886f1684bb00cea83 100644 (file)
@@ -1,6 +1,6 @@
 ;;; temp-buffer-browse.el --- temp buffer browse mode  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2013  Free Software Foundation, Inc.
+;; Copyright (C) 2013-2014  Free Software Foundation, Inc.
 
 ;; Author: Leo Liu <sdl.web@gmail.com>
 ;; Version: 1.1
 ;;; Code:
 
 (eval-and-compile
-  (or (fboundp 'set-temporary-overlay-map) ; new in 24.3
-      (defun set-temporary-overlay-map (map &optional keep-pred)
-        "Set MAP as a temporary keymap taking precedence over most other keymaps.
-Note that this does NOT take precedence over the \"overriding\" maps
-`overriding-terminal-local-map' and `overriding-local-map' (or the
-`keymap' text property).  Unlike those maps, if no match for a key is
-found in MAP, the normal key lookup sequence then continues.
-
-Normally, MAP is used only once.  If the optional argument
-KEEP-PRED is t, MAP stays active if a key from MAP is used.
-KEEP-PRED can also be a function of no arguments: if it returns
-non-nil then MAP stays active."
-        (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map"))
-               (overlaysym (make-symbol "t"))
-               (alist (list (cons overlaysym map)))
-               (clearfun
-                `(lambda ()
-                   (unless ,(cond ((null keep-pred) nil)
-                                  ((eq t keep-pred)
-                                   `(eq this-command
-                                        (lookup-key ',map
-                                                    (this-command-keys-vector))))
-                                  (t `(funcall ',keep-pred)))
-                     (set ',overlaysym nil) ;Just in case.
-                     (remove-hook 'pre-command-hook ',clearfunsym)
-                     (setq emulation-mode-map-alists
-                           (delq ',alist emulation-mode-map-alists))))))
-          (set overlaysym overlaysym)
-          (fset clearfunsym clearfun)
-          (add-hook 'pre-command-hook clearfunsym)
-          (push alist emulation-mode-map-alists)))))
+  (cond
+   ((fboundp 'set-transient-map) nil)
+   ((fboundp 'set-temporary-overlay-map) ; new in 24.3
+    (defalias 'set-transient-map 'set-temporary-overlay-map))
+   (t
+    (defun set-transient-map (map &optional keep-pred)
+      (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map"))
+             (overlaysym (make-symbol "t"))
+             (alist (list (cons overlaysym map)))
+             (clearfun
+              `(lambda ()
+                 (unless ,(cond ((null keep-pred) nil)
+                                ((eq t keep-pred)
+                                 `(eq this-command
+                                      (lookup-key ',map
+                                                  (this-command-keys-vector))))
+                                (t `(funcall ',keep-pred)))
+                   (set ',overlaysym nil) ;Just in case.
+                   (remove-hook 'pre-command-hook ',clearfunsym)
+                   (setq emulation-mode-map-alists
+                         (delq ',alist emulation-mode-map-alists))))))
+        (set overlaysym overlaysym)
+        (fset clearfunsym clearfun)
+        (add-hook 'pre-command-hook clearfunsym)
+        (push alist emulation-mode-map-alists))))))
 
 (defcustom temp-buffer-browse-fringe-bitmap 'centered-vertical-bar
   "Fringe bitmap to use in the temp buffer window."
@@ -136,7 +130,7 @@ scroll down and close the temp buffer window, respectively."
       ;; negative priority.
       (unless (bound-and-true-p adaptive-wrap-prefix-mode)
         (overlay-put o 'wrap-prefix (overlay-get o 'line-prefix)))
-      (set-temporary-overlay-map
+      (set-transient-map
        temp-buffer-browse-map
        (lambda ()
          ;; When any error happens the keymap is active forever.