bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#65209: 30.0.50; Unexpected behaviour of setq-local


From: Michael Heerdegen
Subject: bug#65209: 30.0.50; Unexpected behaviour of setq-local
Date: Tue, 22 Aug 2023 05:09:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Eli Zaretskii <eliz@gnu.org> writes:

> > Ehm - does somebody care about the manual?
>
> What do you mean?

My wish would be that the manual says a bit more about how let-binding
and buffer-local play together.  We have this

|    *Warning:* When a variable has buffer-local bindings in one or more
| buffers, ‘let’ rebinds the binding that’s currently in effect.  For
| instance, if the current buffer has a buffer-local value, ‘let’
| temporarily rebinds that.  If no buffer-local bindings are in effect,
| ‘let’ rebinds the default value.  If inside the ‘let’ you then change to
| a different current buffer in which a different binding is in effect,
| you won’t see the ‘let’ binding any more.  And if you exit the ‘let’
| while still in the other buffer, you won’t see the unbinding occur
| (though it will occur properly).

in (info "(elisp) Intro to Buffer-Local") [good] and also some words
about `set-default' being prevented from setting the default value
inside `let' in (info "(elisp) Default Value").

But the manual leaves open some questions (after reading the manual I
was not able to tell that the bug in this report was a bug):

How are bindings working when not changing the current buffer inside the
let?  If I create a buffer-local binding and the `let' is left, what
binding is left in the buffer - is the variable in that buffer still
buffer local, or does leaving the let maybe also remove the local
variable?

This example derived from Stefan's test clarifies most questions:

#+begin_src emacs-lisp
;; -*- lexical-binding: t -*-

(defvar-local my-var :default)

(let (inside-let local-inside-let inside-let-other-buffer local-outer outer)
  (with-temp-buffer
    (let ((my-var :let-bound))
      (setq inside-let my-var)
      (setq-local my-var :buffer-local)
      (setq local-inside-let my-var)
      (setq inside-let-other-buffer (with-temp-buffer my-var)))
    (setq local-outer my-var)
    (setq outer (with-temp-buffer my-var)))
  (list inside-let local-inside-let inside-let-other-buffer
        local-outer outer))

;; --> (:let-bound :buffer-local :let-bound
;;      :buffer-local :default)
#+end_src


Then, sometimes one sees this warning (e.g. when evaluating the above
example):

| Making my-var buffer-local while locally let-bound!

People will want to know what it means and whether (or when) they need
to care about it or can ignore it.


Finally, should we also talk about lexical variables vs. buffer-local?
They are different again:

#+begin_src emacs-lisp
(with-temp-buffer
  (let ((var :let-bound))
    (set (make-local-variable 'var) :buffer-local)
    var)) ;;    --> :let-bound, not :buffer-local!
#+end_src


Michael.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]