mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
Make second arg to defvar-local optional
This change allows declaring a variable both special
and buffer-local like so:
(defvar-local foo)
* lisp/subr.el (defvar-local): Make second argument optional.
* test/lisp/subr-tests.el (subr-test-defvar-local): New test.
* doc/lispref/variables.texi (Creating Buffer-Local): Document above change.
* etc/NEWS:
* lisp/mb-depth.el (minibuffer-depth-overlay):
* lisp/minibuf-eldef.el (minibuf-eldef-initial-input)
(minibuf-eldef-initial-buffer-length)
(minibuf-eldef-showing-default-in-prompt, minibuf-eldef-overlay):
* lisp/misc.el (list-dynamic-libraries--loaded-only-p):
* lisp/simple.el (minibuffer-history-isearch-message-overlay): Use
above new one-argument form of 'defvar-local'.
This commit is contained in:
parent
a6523599f9
commit
ce03bf252a
8 changed files with 35 additions and 20 deletions
|
|
@ -1649,7 +1649,7 @@ on having separate values in separate buffers, then using
|
||||||
@code{make-variable-buffer-local} can be the best solution.
|
@code{make-variable-buffer-local} can be the best solution.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
@defmac defvar-local variable value &optional docstring
|
@defmac defvar-local variable &optional value docstring
|
||||||
This macro defines @var{variable} as a variable with initial value
|
This macro defines @var{variable} as a variable with initial value
|
||||||
@var{value} and @var{docstring}, and marks it as automatically
|
@var{value} and @var{docstring}, and marks it as automatically
|
||||||
buffer-local. It is equivalent to calling @code{defvar} followed by
|
buffer-local. It is equivalent to calling @code{defvar} followed by
|
||||||
|
|
|
||||||
5
etc/NEWS
5
etc/NEWS
|
|
@ -1565,6 +1565,11 @@ and signal an error if they are given a non-number.
|
||||||
They return non-nil if an integer is odd or even, respectively, and
|
They return non-nil if an integer is odd or even, respectively, and
|
||||||
signal an error if they are given a non-integer.
|
signal an error if they are given a non-integer.
|
||||||
|
|
||||||
|
+++
|
||||||
|
** The 'defvar-local' macro second argument is now optional.
|
||||||
|
This means that you can now call it with just one argument, like
|
||||||
|
'defvar', to declare a variable both special, and buffer-local.
|
||||||
|
|
||||||
** ERT
|
** ERT
|
||||||
|
|
||||||
*** Some experimental ERT macros are now considered stable.
|
*** Some experimental ERT macros are now considered stable.
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,7 @@ the `minibuffer-depth-indicator' face."
|
||||||
;; An overlay covering the prompt. This is a buffer-local variable in
|
;; An overlay covering the prompt. This is a buffer-local variable in
|
||||||
;; each affected minibuffer.
|
;; each affected minibuffer.
|
||||||
;;
|
;;
|
||||||
(defvar minibuffer-depth-overlay)
|
(defvar-local minibuffer-depth-overlay)
|
||||||
(make-variable-buffer-local 'minibuffer-depth-overlay)
|
|
||||||
|
|
||||||
;; This function goes on minibuffer-setup-hook
|
;; This function goes on minibuffer-setup-hook
|
||||||
(defun minibuffer-depth-setup ()
|
(defun minibuffer-depth-setup ()
|
||||||
|
|
|
||||||
|
|
@ -88,19 +88,16 @@ should be displayed in its place.")
|
||||||
;;; The following are all local variables in the minibuffer
|
;;; The following are all local variables in the minibuffer
|
||||||
|
|
||||||
;; Input pre-inserted into the minibuffer before the user can edit it.
|
;; Input pre-inserted into the minibuffer before the user can edit it.
|
||||||
(defvar minibuf-eldef-initial-input)
|
(defvar-local minibuf-eldef-initial-input)
|
||||||
(make-variable-buffer-local 'minibuf-eldef-initial-input)
|
|
||||||
;; and the length of the buffer with it inserted.
|
;; and the length of the buffer with it inserted.
|
||||||
(defvar minibuf-eldef-initial-buffer-length)
|
(defvar-local minibuf-eldef-initial-buffer-length)
|
||||||
(make-variable-buffer-local 'minibuf-eldef-initial-buffer-length)
|
|
||||||
|
|
||||||
;; True if the current minibuffer prompt contains the default spec.
|
;; True if the current minibuffer prompt contains the default spec.
|
||||||
(defvar minibuf-eldef-showing-default-in-prompt)
|
(defvar-local minibuf-eldef-showing-default-in-prompt)
|
||||||
(make-variable-buffer-local 'minibuf-eldef-showing-default-in-prompt)
|
|
||||||
|
|
||||||
;; An overlay covering the default portion of the prompt
|
;; An overlay covering the default portion of the prompt
|
||||||
(defvar minibuf-eldef-overlay)
|
(defvar-local minibuf-eldef-overlay)
|
||||||
(make-variable-buffer-local 'minibuf-eldef-overlay)
|
|
||||||
|
|
||||||
|
|
||||||
;;; Hook functions
|
;;; Hook functions
|
||||||
|
|
|
||||||
|
|
@ -262,8 +262,7 @@ variation of `C-x M-c M-butterfly' from url `https://xkcd.com/378/'."
|
||||||
;; A command to list dynamically loaded libraries. This useful in
|
;; A command to list dynamically loaded libraries. This useful in
|
||||||
;; environments where dynamic-library-alist is used, i.e., Windows
|
;; environments where dynamic-library-alist is used, i.e., Windows
|
||||||
|
|
||||||
(defvar list-dynamic-libraries--loaded-only-p)
|
(defvar-local list-dynamic-libraries--loaded-only-p)
|
||||||
(make-variable-buffer-local 'list-dynamic-libraries--loaded-only-p)
|
|
||||||
|
|
||||||
(defun list-dynamic-libraries--loaded (from)
|
(defun list-dynamic-libraries--loaded (from)
|
||||||
"Compute the \"Loaded from\" column.
|
"Compute the \"Loaded from\" column.
|
||||||
|
|
|
||||||
|
|
@ -3235,8 +3235,7 @@ Return 0 if current buffer is not a minibuffer."
|
||||||
;; isearch minibuffer history
|
;; isearch minibuffer history
|
||||||
(add-hook 'minibuffer-setup-hook 'minibuffer-history-isearch-setup)
|
(add-hook 'minibuffer-setup-hook 'minibuffer-history-isearch-setup)
|
||||||
|
|
||||||
(defvar minibuffer-history-isearch-message-overlay)
|
(defvar-local minibuffer-history-isearch-message-overlay)
|
||||||
(make-variable-buffer-local 'minibuffer-history-isearch-message-overlay)
|
|
||||||
|
|
||||||
(defun minibuffer-history-isearch-setup ()
|
(defun minibuffer-history-isearch-setup ()
|
||||||
"Set up a minibuffer for using isearch to search the minibuffer history.
|
"Set up a minibuffer for using isearch to search the minibuffer history.
|
||||||
|
|
|
||||||
16
lisp/subr.el
16
lisp/subr.el
|
|
@ -192,14 +192,20 @@ pair.
|
||||||
(setq pairs (cdr (cdr pairs))))
|
(setq pairs (cdr (cdr pairs))))
|
||||||
(macroexp-progn (nreverse expr))))
|
(macroexp-progn (nreverse expr))))
|
||||||
|
|
||||||
(defmacro defvar-local (var val &optional docstring)
|
(defmacro defvar-local (symbol &rest args)
|
||||||
"Define VAR as a buffer-local variable with default value VAL.
|
"Define SYMBOL as a buffer-local variable with default value VALUE.
|
||||||
Like `defvar' but additionally marks the variable as being automatically
|
Like `defvar' but additionally marks the variable as being automatically
|
||||||
buffer-local wherever it is set."
|
buffer-local wherever it is set.
|
||||||
|
\n(fn symbol &optional value docstring)"
|
||||||
(declare (debug defvar) (doc-string 3) (indent 2))
|
(declare (debug defvar) (doc-string 3) (indent 2))
|
||||||
;; Can't use backquote here, it's too early in the bootstrap.
|
;; Can't use backquote here, it's too early in the bootstrap.
|
||||||
(list 'progn (list 'defvar var val docstring)
|
(let ((value (car-safe args))
|
||||||
(list 'make-variable-buffer-local (list 'quote var))))
|
(docstring (car-safe (cdr-safe args))))
|
||||||
|
(list 'progn
|
||||||
|
(if (zerop (length args))
|
||||||
|
(list 'defvar symbol)
|
||||||
|
(list 'defvar symbol value docstring))
|
||||||
|
(list 'make-variable-buffer-local (list 'quote symbol)))))
|
||||||
|
|
||||||
(defun buffer-local-boundp (symbol buffer)
|
(defun buffer-local-boundp (symbol buffer)
|
||||||
"Return non-nil if SYMBOL is bound in BUFFER.
|
"Return non-nil if SYMBOL is bound in BUFFER.
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,16 @@
|
||||||
(require 'ert-x)
|
(require 'ert-x)
|
||||||
(eval-when-compile (require 'cl-lib))
|
(eval-when-compile (require 'cl-lib))
|
||||||
|
|
||||||
|
(defvar-local subr-tests--local-var1)
|
||||||
|
(defvar-local subr-tests--local-var2 'hello)
|
||||||
|
(defvar-local subr-tests--local-var3 nil "Doc.")
|
||||||
|
(ert-deftest subr-test-defvar-local ()
|
||||||
|
(should (local-variable-if-set-p 'subr-tests--local-var1))
|
||||||
|
(should (local-variable-if-set-p 'subr-tests--local-var2))
|
||||||
|
(should (eq subr-tests--local-var2 'hello))
|
||||||
|
(should (local-variable-if-set-p 'subr-tests--local-var3))
|
||||||
|
(should (get 'subr-tests--local-var3 'variable-documentation)))
|
||||||
|
|
||||||
(ert-deftest subr-test-apply-partially ()
|
(ert-deftest subr-test-apply-partially ()
|
||||||
(should (functionp (apply-partially #'identity)))
|
(should (functionp (apply-partially #'identity)))
|
||||||
(should (functionp (apply-partially #'list 1 2 3)))
|
(should (functionp (apply-partially #'list 1 2 3)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue