[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help needed with defadvice
From: |
Alex Kost |
Subject: |
Re: Help needed with defadvice |
Date: |
Sat, 23 Nov 2013 01:56:53 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Perry Smith (2013-11-22 19:50 +0400) wrote:
> On Nov 22, 2013, at 1:09 AM, Alex Kost <alezost@gmail.com> wrote:
>
>> Perry Smith (2013-11-22 06:45 +0400) wrote:
>>
>>> I have this defadvice:
>>>
>>> (defadvice get-buffer-create (around inherit activate)
>>> (let ((set-list (mapcar '(lambda ( v )
>>> (cons v (symbol-value v)))
>>> inherited-alist)))
>>> (with-current-buffer ad-do-it
>>> (mapcar '(lambda ( c )
>>> (message "Setting %s to %s inside %s"
>>> (car c) (cdr c) (buffer-name (current-buffer)))
>>> (set (car c) (cdr c)))
>>> set-list))))
>>>
>>> inherited-alist is a list of symbols that I add to. When a buffer is
>>> created, I run through the list of variables and get their values as seen
>>> from the current buffer. I then call get-buffer-create (via ad-do-it) and
>>> do a set on each of the variables. The "message" is there just for
>>> debugging. I get the messages like I expect .... e.g. "Setting foo to dog
>>> inside cat.c" or whatever. All the symbols in inherited-alist are
>>> buffer-local variables.
>
> To Eric: changing let to let* had not effect.
>
>>
>> 1. With `set' you set a global value, you probably want
>> (set (make-local-variable (car c)) (cdr c)) instead of
>> (set (car c) (cdr c)).
>
> No change. If this helps, when I do ^h-v cscope-out-buffer I get:
>
> cscope-out-buffer is a variable defined in `cscope.el'.
> Its value is "banana"
>
> Automatically becomes buffer-local when set.
>
> Documentation:
> Buffer associated with the cscope process
>
> "banana" is the global I set with:
> (set-default 'cscope-out-buffer "banana") in *scratch*
>
> I'm coming to the conclusion that something after get-buffer-create
> is blasting the local variables back to their defaults. (By the
> way, I have added another message after the set and it
> shows that it is being set. I've also explicitly set one of these
> variables outside of the let and it is still not being set.
It looks like something interferes, because your initial advice works
for buffer-local variables.
Steps to reproduce:
1. emacs -q
2. Insert this into *scratch* buffer and eval it:
(defvar inherited-alist '(v1))
(defvar v1 nil)
(make-variable-buffer-local 'v1)
(set 'v1 123)
(defadvice get-buffer-create (around inherit activate)
(let ((set-list (mapcar '(lambda ( v )
(cons v (symbol-value v)))
inherited-alist)))
(with-current-buffer ad-do-it
(mapcar '(lambda ( c )
;; (message "Setting %s to %s inside %s"
;; (car c) (cdr c) (buffer-name (current-buffer)))
(set (car c) (cdr c)))
set-list))))
After evaluating you get `v1' variable with nil as global value and 123
as local value in *scratch* buffer.
3. Create new buffer with "C-x b" and the local value of v1 will be 123
there.
4. Switch to a buffer where v1 is nil (for example with "C-h e") and
create new buffer again. And it will inherit nil for v1.
- Help needed with defadvice, Perry Smith, 2013/11/21
- Re: Help needed with defadvice, Eric Abrahamsen, 2013/11/22
- Re: Help needed with defadvice, Alex Kost, 2013/11/22
- Re: Help needed with defadvice, Perry Smith, 2013/11/22
- Re: Help needed with defadvice,
Alex Kost <=
- Re: Help needed with defadvice, Perry Smith, 2013/11/22
- Re: Help needed with defadvice, Alex Kost, 2013/11/23
- Re: Help needed with defadvice, Stefan Monnier, 2013/11/23
- Re: Help needed with defadvice, Perry Smith, 2013/11/23
- Re: Help needed with defadvice, Stefan Monnier, 2013/11/23
- Re: Help needed with defadvice, Perry Smith, 2013/11/23
- Re: Help needed with defadvice, Stefan Monnier, 2013/11/24
- Re: Help needed with defadvice, Alex Kost, 2013/11/23
Message not available
Re: Help needed with defadvice, Stefan Monnier, 2013/11/22