From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Help needed with defadvice Date: Fri, 22 Nov 2013 13:27:41 +0700 Message-ID: <877gc1t0gy.fsf@ericabrahamsen.net> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1385101600 23213 80.91.229.3 (22 Nov 2013 06:26:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 22 Nov 2013 06:26:40 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 22 07:26:45 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VjkCQ-00078t-TK for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Nov 2013 07:26:43 +0100 Original-Received: from localhost ([::1]:37061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjkCQ-00023A-Db for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Nov 2013 01:26:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjkC8-00022y-Hj for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 01:26:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VjkC1-0004xd-76 for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 01:26:24 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:37182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjkC1-0004x8-03 for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 01:26:17 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VjkBy-0006wA-9p for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 07:26:14 +0100 Original-Received: from 223.204.248.32 ([223.204.248.32]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Nov 2013 07:26:14 +0100 Original-Received: from eric by 223.204.248.32 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Nov 2013 07:26:14 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 55 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 223.204.248.32 User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:+SIXX3Oel6WLe565UVFp1WsHWDs= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:94566 Archived-At: Perry Smith 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