From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alex Kost Newsgroups: gmane.emacs.help Subject: Re: Help needed with defadvice Date: Sat, 23 Nov 2013 01:56:53 +0400 Message-ID: <87y54g5cd6.fsf@gmail.com> References: <8738mo7w0j.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1385157450 30530 80.91.229.3 (22 Nov 2013 21:57:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 22 Nov 2013 21:57:30 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org Help" To: Perry Smith Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 22 22:57:35 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 1VjyjD-0007bF-31 for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Nov 2013 22:57:31 +0100 Original-Received: from localhost ([::1]:41278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjyjC-0006wN-IS for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Nov 2013 16:57:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vjyis-0006vq-8H for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 16:57:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vjyif-0006Vo-6a for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 16:57:10 -0500 Original-Received: from mail-lb0-x234.google.com ([2a00:1450:4010:c04::234]:53551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vjyie-0006Vi-Ux for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 16:56:57 -0500 Original-Received: by mail-lb0-f180.google.com with SMTP id w6so1480921lbh.39 for ; Fri, 22 Nov 2013 13:56:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=zJJqHUbYX0PurBgaryh5O8VcmP02oyXF/U2sSgslwOs=; b=wpSEfIK/nlDK+mwb6zeIkGjHvZt09K9Dq3mu+4V4wZ/7o78QbseOiZ/K27QOd6FJVA 23N59MwKCtsiO9NR0h0F8bP8hVe5mguw9u/JmHJcWTsWfoxIqulfuFZqk5mL/rZzUwVq INt3W+CK7dpxfZUm3Ht7kLVAOiJAoy4tjmjEn1JGPY6YXt/PwCjtO6Kl5sx5uLzemWwy 7/INJ/s/1EL2YZXaDYWxBN3+04N3OJzDLvuVVyT7CdoyrhXnY0bDBWHVlzQJJ774utj7 z9o2rtKThpaRnCgSX7rkVnNkvC9swEIjErhiiYapJNR2c7rUaHUBqyVUsf40HW8hQWTt 9bCw== X-Received: by 10.152.23.137 with SMTP id m9mr11368829laf.17.1385157415712; Fri, 22 Nov 2013 13:56:55 -0800 (PST) Original-Received: from leviafan (128-70-197-79.broadband.corbina.ru. [128.70.197.79]) by mx.google.com with ESMTPSA id vz9sm28315456lbb.17.2013.11.22.13.56.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Nov 2013 13:56:55 -0800 (PST) In-Reply-To: (Perry Smith's message of "Fri, 22 Nov 2013 09:50:02 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::234 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:94575 Archived-At: Perry Smith (2013-11-22 19:50 +0400) wrote: > On Nov 22, 2013, at 1:09 AM, Alex Kost wrote: > >> 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. > > To Eric: changing let to let* had not effect. > >> >> 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)). > > No change. If this helps, when I do ^h-v cscope-out-buffer I get: > > cscope-out-buffer is a variable defined in `cscope.el'. > Its value is "banana" > > Automatically becomes buffer-local when set. > > Documentation: > Buffer associated with the cscope process > > "banana" is the global I set with: > (set-default 'cscope-out-buffer "banana") in *scratch* > > I'm coming to the conclusion that something after get-buffer-create > is blasting the local variables back to their defaults. (By the > way, I have added another message after the set and it > shows that it is being set. I've also explicitly set one of these > variables outside of the let and it is still not being set. It looks like something interferes, because your initial advice works for buffer-local variables. Steps to reproduce: 1. emacs -q 2. Insert this into *scratch* buffer and eval it: (defvar inherited-alist '(v1)) (defvar v1 nil) (make-variable-buffer-local 'v1) (set 'v1 123) (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)))) After evaluating you get `v1' variable with nil as global value and 123 as local value in *scratch* buffer. 3. Create new buffer with "C-x b" and the local value of v1 will be 123 there. 4. Switch to a buffer where v1 is nil (for example with "C-h e") and create new buffer again. And it will inherit nil for v1.