diff options
| author | Vitalie Spinu | 2013-06-13 16:43:53 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-06-13 16:43:53 -0400 |
| commit | c23d55f45b8a326758c4baa3c6e1e980b294f5b6 (patch) | |
| tree | a5b9d41c535f36ef521182a1a9d79dda284d4f6e | |
| parent | 8baeb37a954d035419ed3309621cba3465f99f32 (diff) | |
| download | emacs-c23d55f45b8a326758c4baa3c6e1e980b294f5b6.tar.gz emacs-c23d55f45b8a326758c4baa3c6e1e980b294f5b6.zip | |
* lisp/subr.el (internal-push-keymap, internal-pop-keymap): New functions.
(set-temporary-overlay-map): Use them; and take advantage of
lexical-binding.
Fixes: debbugs:14095
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/subr.el | 64 |
2 files changed, 51 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 89d970ace1f..3525568ab2d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2013-06-13 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * subr.el (internal-push-keymap, internal-pop-keymap): New functions. | ||
| 4 | (set-temporary-overlay-map): Use them (bug#14095); and take advantage of | ||
| 5 | lexical-binding. | ||
| 6 | |||
| 7 | 2013-06-13 Vitalie Spinu <spinuvit@gmail.com> | ||
| 8 | |||
| 9 | * subr.el (set-temporary-overlay-map): Add on-exit argument. | ||
| 10 | |||
| 1 | 2013-06-13 Glenn Morris <rgm@gnu.org> | 11 | 2013-06-13 Glenn Morris <rgm@gnu.org> |
| 2 | 12 | ||
| 3 | * startup.el (tty-handle-args): | 13 | * startup.el (tty-handle-args): |
diff --git a/lisp/subr.el b/lisp/subr.el index 8f290f356da..380b2ba66ee 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -4234,7 +4234,25 @@ use `called-interactively-p'." | |||
| 4234 | (declare (obsolete called-interactively-p "23.2")) | 4234 | (declare (obsolete called-interactively-p "23.2")) |
| 4235 | (called-interactively-p 'interactive)) | 4235 | (called-interactively-p 'interactive)) |
| 4236 | 4236 | ||
| 4237 | (defun set-temporary-overlay-map (map &optional keep-pred) | 4237 | (defun internal-push-keymap (keymap symbol) |
| 4238 | (let ((map (symbol-value symbol))) | ||
| 4239 | (unless (memq keymap map) | ||
| 4240 | (unless (memq 'add-keymap-witness (symbol-value symbol)) | ||
| 4241 | (setq map (make-composed-keymap nil (symbol-value symbol))) | ||
| 4242 | (push 'add-keymap-witness (cdr map)) | ||
| 4243 | (set symbol map)) | ||
| 4244 | (push keymap (cdr map))))) | ||
| 4245 | |||
| 4246 | (defun internal-pop-keymap (keymap symbol) | ||
| 4247 | (let ((map (symbol-value symbol))) | ||
| 4248 | (when (memq keymap map) | ||
| 4249 | (setf (cdr map) (delq keymap (cdr map)))) | ||
| 4250 | (let ((tail (cddr map))) | ||
| 4251 | (and (or (null tail) (keymapp tail)) | ||
| 4252 | (eq 'add-keymap-witness (nth 1 map)) | ||
| 4253 | (set symbol tail))))) | ||
| 4254 | |||
| 4255 | (defun set-temporary-overlay-map (map &optional keep-pred on-exit) | ||
| 4238 | "Set MAP as a temporary keymap taking precedence over most other keymaps. | 4256 | "Set MAP as a temporary keymap taking precedence over most other keymaps. |
| 4239 | Note that this does NOT take precedence over the \"overriding\" maps | 4257 | Note that this does NOT take precedence over the \"overriding\" maps |
| 4240 | `overriding-terminal-local-map' and `overriding-local-map' (or the | 4258 | `overriding-terminal-local-map' and `overriding-local-map' (or the |
| @@ -4244,29 +4262,29 @@ found in MAP, the normal key lookup sequence then continues. | |||
| 4244 | Normally, MAP is used only once. If the optional argument | 4262 | Normally, MAP is used only once. If the optional argument |
| 4245 | KEEP-PRED is t, MAP stays active if a key from MAP is used. | 4263 | KEEP-PRED is t, MAP stays active if a key from MAP is used. |
| 4246 | KEEP-PRED can also be a function of no arguments: if it returns | 4264 | KEEP-PRED can also be a function of no arguments: if it returns |
| 4247 | non-nil then MAP stays active." | 4265 | non-nil then MAP stays active. |
| 4248 | (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map")) | 4266 | |
| 4249 | (overlaysym (make-symbol "t")) | 4267 | Optional ON-EXIT argument is a function that is called after the |
| 4250 | (alist (list (cons overlaysym map))) | 4268 | deactivation of MAP." |
| 4251 | (clearfun | 4269 | (letrec ((clearfun |
| 4252 | ;; FIXME: Use lexical-binding. | 4270 | (lambda () |
| 4253 | `(lambda () | 4271 | ;; FIXME: Handle the case of multiple temporary-overlay-maps |
| 4254 | (unless ,(cond ((null keep-pred) nil) | 4272 | ;; E.g. if isearch and C-u both use temporary-overlay-maps, Then |
| 4273 | ;; the lifetime of the C-u should be nested within the isearch | ||
| 4274 | ;; overlay, so the pre-command-hook of isearch should be | ||
| 4275 | ;; suspended during the C-u one so we don't exit isearch just | ||
| 4276 | ;; because we hit 1 after C-u and that 1 exits isearch whereas it | ||
| 4277 | ;; doesn't exit C-u. | ||
| 4278 | (unless (cond ((null keep-pred) nil) | ||
| 4255 | ((eq t keep-pred) | 4279 | ((eq t keep-pred) |
| 4256 | `(eq this-command | 4280 | (eq this-command |
| 4257 | (lookup-key ',map | 4281 | (lookup-key map (this-command-keys-vector)))) |
| 4258 | (this-command-keys-vector)))) | 4282 | (t (funcall keep-pred))) |
| 4259 | (t `(funcall ',keep-pred))) | 4283 | (remove-hook 'pre-command-hook clearfun) |
| 4260 | (set ',overlaysym nil) ;Just in case. | 4284 | (internal-pop-keymap map 'overriding-terminal-local-map) |
| 4261 | (remove-hook 'pre-command-hook ',clearfunsym) | 4285 | (when on-exit (funcall on-exit)))))) |
| 4262 | (setq emulation-mode-map-alists | 4286 | (add-hook 'pre-command-hook clearfun) |
| 4263 | (delq ',alist emulation-mode-map-alists)))))) | 4287 | (internal-push-keymap map 'overriding-terminal-local-map))) |
| 4264 | (set overlaysym overlaysym) | ||
| 4265 | (fset clearfunsym clearfun) | ||
| 4266 | (add-hook 'pre-command-hook clearfunsym) | ||
| 4267 | ;; FIXME: That's the keymaps with highest precedence, except for | ||
| 4268 | ;; the `keymap' text-property ;-( | ||
| 4269 | (push alist emulation-mode-map-alists))) | ||
| 4270 | 4288 | ||
| 4271 | ;;;; Progress reporters. | 4289 | ;;;; Progress reporters. |
| 4272 | 4290 | ||