Commit f95e9344 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

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.
parent 71873e2b
...@@ -199,7 +199,12 @@ still be supported for Emacs 24.x. ...@@ -199,7 +199,12 @@ still be supported for Emacs 24.x.
* Lisp changes in Emacs 24.2 * Lisp changes in Emacs 24.2
** New function `set-temporary-overlay-map'.
** New macros `setq-local' and `defvar-local'.
** New error type and new function `user-error'. Doesn't trigger the debugger. ** New error type and new function `user-error'. Doesn't trigger the debugger.
** Completion ** Completion
*** New function `completion-table-with-quoting' to handle completion *** New function `completion-table-with-quoting' to handle completion
......
2012-05-05 Stefan Monnier <monnier@iro.umontreal.ca>
* 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.
2012-05-04 Stefan Monnier <monnier@iro.umontreal.ca> 2012-05-04 Stefan Monnier <monnier@iro.umontreal.ca>
* subr.el (user-error): New function. * subr.el (user-error): New function.
......
...@@ -116,6 +116,19 @@ BODY should be a list of Lisp expressions. ...@@ -116,6 +116,19 @@ BODY should be a list of Lisp expressions.
;; depend on backquote.el. ;; depend on backquote.el.
(list 'function (cons 'lambda cdr))) (list 'function (cons 'lambda cdr)))
(defmacro setq-local (var val)
"Set variable VAR to value VAL in current buffer."
;; Can't use backquote here, it's too early in the bootstrap.
(list 'set (list 'make-local-variable (list 'quote var)) val))
(defmacro defvar-local (var val &optional docstring)
"Define VAR as a buffer-local variable with default value VAL.
Like `defvar' but additionally marks the variable as being automatically
buffer-local wherever it is set."
;; Can't use backquote here, it's too early in the bootstrap.
(list 'progn (list 'defvar var val docstring)
(list 'make-variable-buffer-local (list 'quote var))))
(defun apply-partially (fun &rest args) (defun apply-partially (fun &rest args)
"Return a function that is a partial application of FUN to ARGS. "Return a function that is a partial application of FUN to ARGS.
ARGS is a list of the first N arguments to pass to FUN. 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,11 +519,8 @@ side-effects, and the argument LIST is not modified."
;;;; Keymap support. ;;;; Keymap support.
(defmacro kbd (keys) (defalias 'kbd 'read-kbd-macro)
"Convert KEYS to the internal Emacs key representation. (put 'kbd 'pure t)
KEYS should be a string constant in the format used for
saving keyboard macros (see `edmacro-mode')."
(read-kbd-macro keys))
(defun undefined () (defun undefined ()
"Beep to tell the user this binding is undefined." "Beep to tell the user this binding is undefined."
...@@ -2986,21 +2996,26 @@ potentially make a different buffer current. It does not alter ...@@ -2986,21 +2996,26 @@ potentially make a different buffer current. It does not alter
the buffer list ordering." the buffer list ordering."
(declare (indent 1) (debug t)) (declare (indent 1) (debug t))
;; Most of this code is a copy of save-selected-window. ;; Most of this code is a copy of save-selected-window.
`(let ((save-selected-window-window (selected-window)) `(let* ((save-selected-window-destination ,window)
;; It is necessary to save all of these, because calling (save-selected-window-window (selected-window))
;; select-window changes frame-selected-window for whatever ;; Selecting a window on another frame changes not only the
;; frame that window is in. ;; selected-window but also the frame-selected-window of the
(save-selected-window-alist ;; destination frame. So we need to save&restore it.
(mapcar (lambda (frame) (list frame (frame-selected-window frame))) (save-selected-window-other-frame
(frame-list)))) (unless (eq (selected-frame)
(window-frame save-selected-window-destination))
(frame-selected-window
(window-frame save-selected-window-destination)))))
(save-current-buffer (save-current-buffer
(unwind-protect (unwind-protect
(progn (select-window ,window 'norecord) (progn (select-window save-selected-window-destination 'norecord)
,@body) ,@body)
(dolist (elt save-selected-window-alist) ;; First reset frame-selected-window.
(and (frame-live-p (car elt)) (if (window-live-p save-selected-window-other-frame)
(window-live-p (cadr elt)) ;; We don't use set-frame-selected-window because it does not
(set-frame-selected-window (car elt) (cadr elt) 'norecord))) ;; pass the `norecord' argument to Fselect_window.
(select-window save-selected-window-other-frame 'norecord))
;; Then reset the actual selected-window.
(when (window-live-p save-selected-window-window) (when (window-live-p save-selected-window-window)
(select-window save-selected-window-window 'norecord)))))) (select-window save-selected-window-window 'norecord))))))
...@@ -3808,6 +3823,29 @@ The properties used on SYMBOL are `composefunc', `sendfunc', ...@@ -3808,6 +3823,29 @@ The properties used on SYMBOL are `composefunc', `sendfunc',
(put symbol 'abortfunc (or abortfunc 'kill-buffer)) (put symbol 'abortfunc (or abortfunc 'kill-buffer))
(put symbol 'hookvar (or hookvar 'mail-send-hook))) (put symbol 'hookvar (or hookvar 'mail-send-hook)))
(defun set-temporary-overlay-map (map &optional keep-pred)
(let* ((clearfunsym (make-symbol "clear-temporary-overlay-map"))
(overlaysym (make-symbol "t"))
(alist (list (cons overlaysym map)))
(clearfun
;; FIXME: Use lexical-binding.
`(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)))
(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)
;; FIXME: That's the keymaps with highest precedence, except for
;; the `keymap' text-property ;-(
(push alist emulation-mode-map-alists)))
;;;; Progress reporters. ;;;; Progress reporters.
;; Progress reporter has the following structure: ;; Progress reporter has the following structure:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment