all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ami Fischman" <ami@fischman.org>
To: emacs-devel@gnu.org
Subject: crazy interaction between buffer-locality and function-locality of variables
Date: Sat, 1 Nov 2008 20:34:07 -0700	[thread overview]
Message-ID: <9aa0cfde0811012034h30c79d6cxa66f6ee0754e027d@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]

This snippet:

(make-local-variable 'ami-wcb-bug-foo)
(defun ami-wcb-bug (ami-wcb-bug-foo)
  (with-temp-buffer
    ami-wcb-bug-foo))
(ami-wcb-bug 'bar)

eval'd in a *scratch* buffer results in this error: (void-variable
ami-wcb-bug-foo)
because ami-wcb-bug-foo is not bound in the temporary buffer, because the
same name has been declared local in *scratch*, and the function-call
binding happens in that buffer.  A similar situation for let-binding is
described in elisp.info's "11.10.1 Introduction to Buffer-Local Variables".
This happens in 22.1.1 and in CVS HEAD.

Is the behavior of binding function arguments variables subject to the
locality of the current buffer at function call time intentional?  It makes
writing functions that respond to asynchronous events require using local
variables with names that are globally unique (prefixed with package name,
presumably), which is a PITA.  An example of where this bit me: gnus makes
'timestamp buffer-local in *Summary* buffers, and emacs-jabber has a
function that uses "timestamp" as the name of one of its arguments and then
calls with-temp-buffer inside that function.  So most of the time receiving
jabber messages works just fine, but if the user happens to have point in a
*Summary* buffer then message reciept triggers a void-variable error.

It seems to me that this behavior is broken, but if it's to be kept there
needs to be strong guidance against making variables whose names /aren't/
prefixed with the package name buffer-local.

Cheers,
-Ami

[-- Attachment #2: Type: text/html, Size: 1699 bytes --]

             reply	other threads:[~2008-11-02  3:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-02  3:34 Ami Fischman [this message]
2008-11-02 16:57 ` crazy interaction between buffer-locality and function-locality of variables Stefan Monnier
2008-11-02 17:43   ` Ami Fischman
2008-11-02 20:05     ` Stefan Monnier
2008-11-02 20:31       ` crazy interaction between buffer-locality and function-localityof variables Drew Adams
2008-11-02 23:19 ` crazy interaction between buffer-locality and function-locality of variables Richard M. Stallman
2008-11-02 23:59   ` Ami Fischman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9aa0cfde0811012034h30c79d6cxa66f6ee0754e027d@mail.gmail.com \
    --to=ami@fischman.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.