diff options
| author | Stefan Monnier | 2012-05-04 21:47:04 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-05-04 21:47:04 -0400 |
| commit | f95e9344c9a9e0f5d28df1a9e8ac0ebed3c512fb (patch) | |
| tree | 1aad36ab59a506ae3c24d957941faa555df2bc78 /lisp | |
| parent | 71873e2b335b721e0b3c585e88211c9564f4c743 (diff) | |
| download | emacs-f95e9344c9a9e0f5d28df1a9e8ac0ebed3c512fb.tar.gz emacs-f95e9344c9a9e0f5d28df1a9e8ac0ebed3c512fb.zip | |
New function set-temporary-overlay-map and macros (defvar|setq)-local.
* lisp/subr.el (setq-local, defvar-local): New macros.
(kbd): Redefine as an alias.
(with-selected-window): Leave unrelated frames alone.
(set-temporary-overlay-map): New function.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/subr.el | 72 |
2 files changed, 62 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5c38eb86fa7..276cd7fca6f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2012-05-05 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * subr.el (setq-local, defvar-local): New macros. | ||
| 4 | (kbd): Redefine as an alias. | ||
| 5 | (with-selected-window): Leave unrelated frames alone. | ||
| 6 | (set-temporary-overlay-map): New function. | ||
| 7 | |||
| 1 | 2012-05-04 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2012-05-04 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * subr.el (user-error): New function. | 10 | * subr.el (user-error): New function. |
diff --git a/lisp/subr.el b/lisp/subr.el index 8cfb1eeea16..5d28b96cd7e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -116,6 +116,19 @@ BODY should be a list of Lisp expressions. | |||
| 116 | ;; depend on backquote.el. | 116 | ;; depend on backquote.el. |
| 117 | (list 'function (cons 'lambda cdr))) | 117 | (list 'function (cons 'lambda cdr))) |
| 118 | 118 | ||
| 119 | (defmacro setq-local (var val) | ||
| 120 | "Set variable VAR to value VAL in current buffer." | ||
| 121 | ;; Can't use backquote here, it's too early in the bootstrap. | ||
| 122 | (list 'set (list 'make-local-variable (list 'quote var)) val)) | ||
| 123 | |||
| 124 | (defmacro defvar-local (var val &optional docstring) | ||
| 125 | "Define VAR as a buffer-local variable with default value VAL. | ||
| 126 | Like `defvar' but additionally marks the variable as being automatically | ||
| 127 | buffer-local wherever it is set." | ||
| 128 | ;; Can't use backquote here, it's too early in the bootstrap. | ||
| 129 | (list 'progn (list 'defvar var val docstring) | ||
| 130 | (list 'make-variable-buffer-local (list 'quote var)))) | ||
| 131 | |||
| 119 | (defun apply-partially (fun &rest args) | 132 | (defun apply-partially (fun &rest args) |
| 120 | "Return a function that is a partial application of FUN to ARGS. | 133 | "Return a function that is a partial application of FUN to ARGS. |
| 121 | ARGS is a list of the first N arguments to pass to FUN. | 134 | ARGS is a list of the first N arguments to pass to FUN. |
| @@ -506,11 +519,8 @@ side-effects, and the argument LIST is not modified." | |||
| 506 | 519 | ||
| 507 | ;;;; Keymap support. | 520 | ;;;; Keymap support. |
| 508 | 521 | ||
| 509 | (defmacro kbd (keys) | 522 | (defalias 'kbd 'read-kbd-macro) |
| 510 | "Convert KEYS to the internal Emacs key representation. | 523 | (put 'kbd 'pure t) |
| 511 | KEYS should be a string constant in the format used for | ||
| 512 | saving keyboard macros (see `edmacro-mode')." | ||
| 513 | (read-kbd-macro keys)) | ||
| 514 | 524 | ||
| 515 | (defun undefined () | 525 | (defun undefined () |
| 516 | "Beep to tell the user this binding is undefined." | 526 | "Beep to tell the user this binding is undefined." |
| @@ -2986,21 +2996,26 @@ potentially make a different buffer current. It does not alter | |||
| 2986 | the buffer list ordering." | 2996 | the buffer list ordering." |
| 2987 | (declare (indent 1) (debug t)) | 2997 | (declare (indent 1) (debug t)) |
| 2988 | ;; Most of this code is a copy of save-selected-window. | 2998 | ;; Most of this code is a copy of save-selected-window. |
| 2989 | `(let ((save-selected-window-window (selected-window)) | 2999 | `(let* ((save-selected-window-destination ,window) |
| 2990 | ;; It is necessary to save all of these, because calling | 3000 | (save-selected-window-window (selected-window)) |
| 2991 | ;; select-window changes frame-selected-window for whatever | 3001 | ;; Selecting a window on another frame changes not only the |
| 2992 | ;; frame that window is in. | 3002 | ;; selected-window but also the frame-selected-window of the |
| 2993 | (save-selected-window-alist | 3003 | ;; destination frame. So we need to save&restore it. |
| 2994 | (mapcar (lambda (frame) (list frame (frame-selected-window frame))) | 3004 | (save-selected-window-other-frame |
| 2995 | (frame-list)))) | 3005 | (unless (eq (selected-frame) |
| 3006 | (window-frame save-selected-window-destination)) | ||
| 3007 | (frame-selected-window | ||
| 3008 | (window-frame save-selected-window-destination))))) | ||
| 2996 | (save-current-buffer | 3009 | (save-current-buffer |
| 2997 | (unwind-protect | 3010 | (unwind-protect |
| 2998 | (progn (select-window ,window 'norecord) | 3011 | (progn (select-window save-selected-window-destination 'norecord) |
| 2999 | ,@body) | 3012 | ,@body) |
| 3000 | (dolist (elt save-selected-window-alist) | 3013 | ;; First reset frame-selected-window. |
| 3001 | (and (frame-live-p (car elt)) | 3014 | (if (window-live-p save-selected-window-other-frame) |
| 3002 | (window-live-p (cadr elt)) | 3015 | ;; We don't use set-frame-selected-window because it does not |
| 3003 | (set-frame-selected-window (car elt) (cadr elt) 'norecord))) | 3016 | ;; pass the `norecord' argument to Fselect_window. |
| 3017 | (select-window save-selected-window-other-frame 'norecord)) | ||
| 3018 | ;; Then reset the actual selected-window. | ||
| 3004 | (when (window-live-p save-selected-window-window) | 3019 | (when (window-live-p save-selected-window-window) |
| 3005 | (select-window save-selected-window-window 'norecord)))))) | 3020 | (select-window save-selected-window-window 'norecord)))))) |
| 3006 | 3021 | ||
| @@ -3808,6 +3823,29 @@ The properties used on SYMBOL are `composefunc', `sendfunc', | |||
| 3808 | (put symbol 'abortfunc (or abortfunc 'kill-buffer)) | 3823 | (put symbol 'abortfunc (or abortfunc 'kill-buffer)) |
| 3809 | (put symbol 'hookvar (or hookvar 'mail-send-hook))) | 3824 | (put symbol 'hookvar (or hookvar 'mail-send-hook))) |
| 3810 | 3825 | ||
| 3826 | (defun set-temporary-overlay-map (map &optional keep-pred) | ||
| 3827 | (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map")) | ||
| 3828 | (overlaysym (make-symbol "t")) | ||
| 3829 | (alist (list (cons overlaysym map))) | ||
| 3830 | (clearfun | ||
| 3831 | ;; FIXME: Use lexical-binding. | ||
| 3832 | `(lambda () | ||
| 3833 | (unless ,(cond ((null keep-pred) nil) | ||
| 3834 | ((eq t keep-pred) | ||
| 3835 | `(eq this-command | ||
| 3836 | (lookup-key ',map | ||
| 3837 | (this-command-keys-vector)))) | ||
| 3838 | (t `(funcall ',keep-pred))) | ||
| 3839 | (remove-hook 'pre-command-hook ',clearfunsym) | ||
| 3840 | (setq emulation-mode-map-alists | ||
| 3841 | (delq ',alist emulation-mode-map-alists)))))) | ||
| 3842 | (set overlaysym overlaysym) | ||
| 3843 | (fset clearfunsym clearfun) | ||
| 3844 | (add-hook 'pre-command-hook clearfunsym) | ||
| 3845 | ;; FIXME: That's the keymaps with highest precedence, except for | ||
| 3846 | ;; the `keymap' text-property ;-( | ||
| 3847 | (push alist emulation-mode-map-alists))) | ||
| 3848 | |||
| 3811 | ;;;; Progress reporters. | 3849 | ;;;; Progress reporters. |
| 3812 | 3850 | ||
| 3813 | ;; Progress reporter has the following structure: | 3851 | ;; Progress reporter has the following structure: |