[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help needed with defadvice
From: |
Eric Abrahamsen |
Subject: |
Re: Help needed with defadvice |
Date: |
Fri, 22 Nov 2013 13:27:41 +0700 |
User-agent: |
Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux) |
Perry Smith <pedzsan@gmail.com> writes:
> 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.
>
> When I get done and get in cat.c and ask for the value of foo, it is always
> nil.
>
> I have almost the same function:
>
> (defun inherit-from-buffer ( buf )
> "Set all inherited variables of current buffer to those values of BUF"
> (interactive "bBuffer: ")
> (message "Inheriting from %s to %s" buf (buffer-name (current-buffer)))
> (let ((curbuf (current-buffer))
> set-list)
> (set-buffer buf)
> (setq set-list
> (mapcar '(lambda ( v )
> (cons v (symbol-value v)))
> inherited-alist))
> (set-buffer curbuf)
> (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)))
>
> which I call interactively from inside cat.c and give it an argument of
> another buffer to inherit from and it works as expected. The messages are
> the same, everything is the same except the function, after the fact, works
> but doing roughly the same from inside a advice does not.
I don't really know why this wouldn't work, but maybe try changing the
first let to read:
(let* ((curbuf (current-buffer))
(set-list (mapcar '(lambda ( v )
(cons v (buffer-local-value v curbuf)))
inherited-alist))))
Does that change anything? You could also get the full list of buffer
locals with `buffer-local-variables', and then assoc values from
inherited-alist in that list.
Hope that does something,
Eric
- Help needed with defadvice, Perry Smith, 2013/11/21
- Re: Help needed with defadvice,
Eric Abrahamsen <=
- 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, 2013/11/22
- 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