all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help needed with defadvice
@ 2013-11-22  2:45 Perry Smith
  2013-11-22  6:27 ` Eric Abrahamsen
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Perry Smith @ 2013-11-22  2:45 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1970 bytes --]

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

Thank you for your help,
Perry


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2013-11-24 18:21 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-22  2:45 Help needed with defadvice Perry Smith
2013-11-22  6:27 ` Eric Abrahamsen
2013-11-22  7:09 ` Alex Kost
2013-11-22 15:50   ` Perry Smith
2013-11-22 21:56     ` Alex Kost
2013-11-23  1:41       ` Perry Smith
2013-11-23  7:00         ` Alex Kost
2013-11-23 14:48         ` Stefan Monnier
2013-11-23 15:22           ` Perry Smith
2013-11-23 15:38             ` Stefan Monnier
2013-11-23 16:24               ` Perry Smith
2013-11-24 18:21                 ` Stefan Monnier
2013-11-23 15:43           ` Alex Kost
     [not found]   ` <mailman.6834.1385135422.10748.help-gnu-emacs@gnu.org>
2013-11-23  8:35     ` jack-mac
2013-11-22 14:44 ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.