[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help needed with defadvice

From: Perry Smith
Subject: Help needed with defadvice
Date: Thu, 21 Nov 2013 20:45:26 -0600

I have this defadvice:

(defadvice get-buffer-create (around inherit activate)
  (let ((set-list (mapcar '(lambda ( v )
                             (cons v (symbol-value v)))
    (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)))

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-buffer buf)
    (setq set-list
          (mapcar '(lambda ( v )
                     (cons v (symbol-value v)))
    (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)))

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've been poking at this for most of today and can't figure out what is 

Thank you for your help,

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

reply via email to

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