[Top][All Lists]

[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: Fri, 22 Nov 2013 11:09:32 +0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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.

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)).

2. Don't quote lambdas: <>.

3. "alist" means "association list", so you shouldn't call
`inherited-alist' like this as it's a simple list.  For info about
alists look at (info "(elisp) Association Lists").

4. I believe making an advice for `get-buffer-create' is not a good
idea.  Don't you have a lot of messages about setting variables in
*temp* buffers?  Thus you will set unintended variables for any new
buffer.  Do you really need that?

reply via email to

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