1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Add new convenience function `buffer-local-boundp'

* doc/lispref/variables.texi (Creating Buffer-Local): Document it.
* lisp/subr.el (buffer-local-boundp): New function.

* src/data.c (Flocal_variable_p): Mention it.
This commit is contained in:
Lars Ingebrigtsen 2021-05-31 07:21:09 +02:00
parent db91108315
commit 77f67d12f6
5 changed files with 31 additions and 1 deletions

View file

@ -1582,6 +1582,12 @@ buffer-local binding in buffer @var{buffer}, it returns the default
value (@pxref{Default Value}) of @var{variable} instead.
@end defun
@defun buffer-local-boundp variable buffer
This returns non-@code{nil} if there's either a buffer-local binding
of @var{variable} (a symbol) in buffer @var{buffer}, or @var{variable}
has a global binding.
@end defun
@defun buffer-local-variables &optional buffer
This function returns a list describing the buffer-local variables in
buffer @var{buffer}. (If @var{buffer} is omitted, the current buffer

View file

@ -2726,6 +2726,10 @@ customize them.
* Lisp Changes in Emacs 28.1
+++
** New function 'buffer-local-boundp'.
This predicate says whether a symbol is bound in a specific buffer.
---
** Emacs now attempts to test for high-rate subprocess output more fairly.
When several subprocesses produce output simultaneously at high rate,

View file

@ -195,6 +195,14 @@ buffer-local wherever it is set."
(list 'progn (list 'defvar var val docstring)
(list 'make-variable-buffer-local (list 'quote var))))
(defun buffer-local-boundp (symbol buffer)
"Return non-nil if SYMBOL is bound in BUFFER.
Also see `local-variable-p'."
(condition-case nil
(buffer-local-value symbol buffer)
(:success t)
(void-variable nil)))
(defmacro push (newelt place)
"Add NEWELT to the list stored in the generalized variable PLACE.
This is morally equivalent to (setf PLACE (cons NEWELT PLACE)),

View file

@ -2200,7 +2200,9 @@ From now on the default value will apply in this buffer. Return VARIABLE. */)
DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1, 2, 0,
doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
BUFFER defaults to the current buffer. */)
BUFFER defaults to the current buffer.
Also see `buffer-local-boundp'.*/)
(Lisp_Object variable, Lisp_Object buffer)
{
struct buffer *buf = decode_buffer (buffer);

View file

@ -684,5 +684,15 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(should (>= (length (apropos-internal "^help" #'commandp)) 15))
(should-not (apropos-internal "^next-line$" #'keymapp)))
(ert-deftest test-buffer-local-boundp ()
(let ((buf (generate-new-buffer "boundp")))
(with-current-buffer buf
(setq-local test-boundp t))
(setq test-global-boundp t)
(should (buffer-local-boundp 'test-boundp buf))
(should-not (buffer-local-boundp 'test-not-boundp buf))
(should (buffer-local-boundp 'test-global-boundp buf))))
(provide 'subr-tests)
;;; subr-tests.el ends here