unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Johan Bockgård" <bojohan@gnu.org>
To: Alan Morgan <Alan.Morgan@nextlabs.com>
Cc: "20521@debbugs.gnu.org" <20521@debbugs.gnu.org>
Subject: bug#20521: setq-local definitely behaving oddly for viper mode
Date: Thu, 28 May 2015 00:28:40 +0200	[thread overview]
Message-ID: <87zj4pirjb.fsf@gnu.org> (raw)
In-Reply-To: <0DBA2ACE64E8894F80DEC59F1EB9BE2304A3028A56A1@NXT-EXCH.nextlabs.com> (Alan Morgan's message of "Wed, 27 May 2015 09:50:28 -0700")

Alan Morgan <Alan.Morgan@nextlabs.com> writes:

> I must be going crazy. Here is my latest sanity check code in
> viper-check-state in viper-cmd.el
>
>   (when (eq (default-value 'viper-current-state) 'vi-state)
>     (message "Doomed going in"))
>  (setq-local viper-current-state new-state)
>   (when (eq (default-value 'viper-current-state) 'vi-state)
>     (message "Doomed. viper-current-state is now vi-state"))
>
> The setq-local replaces a simple setq at about line 380. When the
> problem starts I see the "Doomed. Viper-current-state is now
> vi-state", but I do *not* see the "Doomed going in" message. This
> implies that setq-local is setting the default value of the variable
> and that really shouldn't be possible. Either I'm nuts or this is an
> emacs bug.

viper-current-state is defined with make-variable-buffer-local (via
viper-deflocalvar), which makes it an "automatically buffer-local"
variable:

     This function marks VARIABLE (a symbol) automatically buffer-local,
     so that any subsequent attempt to set it will make it local to the
     current buffer at the time.  Unlike ‘make-local-variable’, with
     which it is often confused, this cannot be undone, and affects the
     behavior of the variable in all buffers.

     A peculiar wrinkle of this feature is that binding the variable
     (with ‘let’ or other binding constructs) does not create a
     buffer-local binding for it.  Only setting the variable (with ‘set’
     or ‘setq’), while the variable does not have a ‘let’-style binding
     that was made in the current buffer, does so.

Apparently even an explicit setq-local (make-local-variable) cannot
create a local binding in the situation that the second paragraph talks
about:

(progn
  (make-variable-buffer-local 'x)
  (let ((x 0))
    (setq-local x 1)
    (cons (local-variable-p 'x)
          (default-value 'x))))
 => (nil . 1)






  reply	other threads:[~2015-05-27 22:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 23:35 bug#20521: Viper version is 3.14.2 of July 4, 2013; After some hours of use I don't enter viper mode automatically on new files Alan Morgan
2015-05-15 20:39 ` bug#20521: Bug 2051 Alan Morgan
2015-05-15 21:08   ` Nick Andryshak
2015-05-15 21:42     ` Drew Adams
2015-05-15 23:24       ` Nick Andryshak
2015-05-15 21:51     ` Alan Morgan
2015-05-27 16:50 ` bug#20521: setq-local definitely behaving oddly for viper mode Alan Morgan
2015-05-27 22:28   ` Johan Bockgård [this message]
2015-05-28  2:02     ` Stefan Monnier
2022-02-10  8:11     ` bug#20521: Viper version is 3.14.2 of July 4, 2013; After some hours of use I don't enter viper mode automatically on new files Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87zj4pirjb.fsf@gnu.org \
    --to=bojohan@gnu.org \
    --cc=20521@debbugs.gnu.org \
    --cc=Alan.Morgan@nextlabs.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).