From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Perry Smith Newsgroups: gmane.emacs.help Subject: Re: Help needed with defadvice Date: Fri, 22 Nov 2013 19:41:29 -0600 Message-ID: References: <8738mo7w0j.fsf@gmail.com> <87y54g5cd6.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Content-Type: multipart/signed; boundary="Apple-Mail=_A8D41E64-0262-4D50-AD9F-2A7E7512969F"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Trace: ger.gmane.org 1385170916 4425 80.91.229.3 (23 Nov 2013 01:41:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Nov 2013 01:41:56 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org Help" To: Alex Kost Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 23 02:42:01 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 1Vk2ES-0007X3-Dn for geh-help-gnu-emacs@m.gmane.org; Sat, 23 Nov 2013 02:42:00 +0100 Original-Received: from localhost ([::1]:41855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vk2ES-00085Q-0X for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Nov 2013 20:42:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vk2E9-000856-Db for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 20:41:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vk2E0-0004Z3-VZ for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 20:41:41 -0500 Original-Received: from mail-oa0-x22c.google.com ([2607:f8b0:4003:c02::22c]:41048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vk2E0-0004Yy-Nm for help-gnu-emacs@gnu.org; Fri, 22 Nov 2013 20:41:32 -0500 Original-Received: by mail-oa0-f44.google.com with SMTP id m1so2235815oag.17 for ; Fri, 22 Nov 2013 17:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=Ltd6sgs5l9N4ZyfBiBCYOkZKkbqEcojlZVfqsiMTGwY=; b=sUsaQ8TcDUVxPfvu7SRLWcUy79s3awy6FtV9ra2iYG/KL9eDOIEMn9DHovzSbu6PKi Ojst3OpsiEV4vDMLx7T9aFBuMG9lu3fjqU2gXJ1L2cXP1T6TKV0XN52or61RIzhZPOZ3 GvfeJx39ystrQmWhfw4pktPG1hJkeheQdS3cSq81fg1Gtl80N23JnPQYkHPeDHDCYmfm pCI3BcV6qVC6RRvlahRZHo103FqhZWJAi9YydrANVzHI7O5muXKZZ+wXbbIfAc1eHbOY xf3fB8xEqdI0C072Z+TIzt59h8Na2TvRMwg0wux5mWT6ZMQPQKyqknRHhL+nEgPmuhBU 7j8A== X-Received: by 10.60.68.135 with SMTP id w7mr13568196oet.9.1385170892090; Fri, 22 Nov 2013 17:41:32 -0800 (PST) Original-Received: from magicbook.austin.ibm.com ([32.97.110.54]) by mx.google.com with ESMTPSA id tz10sm52122119obc.10.2013.11.22.17.41.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 17:41:31 -0800 (PST) In-Reply-To: <87y54g5cd6.fsf@gmail.com> X-Mailer: Apple Mail (2.1510) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::22c 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:94577 Archived-At: --Apple-Mail=_A8D41E64-0262-4D50-AD9F-2A7E7512969F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Nov 22, 2013, at 3:56 PM, Alex Kost wrote: > Perry Smith (2013-11-22 19:50 +0400) wrote: >=20 >> On Nov 22, 2013, at 1:09 AM, Alex Kost wrote: >>=20 >>> Perry Smith (2013-11-22 06:45 +0400) wrote: >>>=20 >>>> I have this defadvice: >>>>=20 >>>> (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=20 >>>> (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)))) >>>>=20 >>>> 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. >>=20 >> To Eric: changing let to let* had not effect. >>=20 >>>=20 >>> 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)). >>=20 >> No change. If this helps, when I do ^h-v cscope-out-buffer I get: >>=20 >> cscope-out-buffer is a variable defined in `cscope.el'. >> Its value is "banana" >>=20 >> Automatically becomes buffer-local when set. >>=20 >> Documentation: >> Buffer associated with the cscope process >>=20 >> "banana" is the global I set with: >> (set-default 'cscope-out-buffer "banana") in *scratch* >>=20 >> 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. >=20 > It looks like something interferes, because your initial advice works > for buffer-local variables. >=20 > Steps to reproduce: >=20 > 1. emacs -q > 2. Insert this into *scratch* buffer and eval it: >=20 > (defvar inherited-alist '(v1)) > (defvar v1 nil) > (make-variable-buffer-local 'v1) > (set 'v1 123) >=20 > (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=20 > (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)))) >=20 > After evaluating you get `v1' variable with nil as global value and = 123 > as local value in *scratch* buffer. >=20 > 3. Create new buffer with "C-x b" and the local value of v1 will be = 123 > there. >=20 > 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. Thanks... I attacked this from the opposite direction adding debug = trying to narrow down when the locals got killed. I finally bumped into = these lines: (defmacro define-derived-mode (child parent name &optional docstring = &rest body) ... (interactive) ; Run the parent. (delay-mode-hooks (,(or parent 'kill-all-local-variables)) <<<<<<<<< ; Identify the child mode. (setq major-mode (quote ,child)) (setq mode-name ,name) ...) I'm going to drive home and play with this some more but I predict that = that is what is killing my local variables. Does anyone know why this is there? I somewhat assumed I had this in some of my poop but this is stock emacs = code (24.3). Thank you to all for their time and patience... Perry --Apple-Mail=_A8D41E64-0262-4D50-AD9F-2A7E7512969F Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJSkAfJAAoJEIPoMwNgGirlYzYH/jZD6UHLkXmzK5wK8dEWnSxb zYShL89ogJnj+pQOtcixqCmhhz1/Jh2Wiwz4RZRutP4aPoSecOSP2NLzptpxibTk oI80f50j+LPPRT+p7YapTJGa8a6hIlhNliM4BAsl1fpxQwjZvgl7cp1EGbAWOr1V dfMb/pjpqK8TO9NmqF8rIaIXntHA0J+F47as7JuZlUk6QGBn1PUQ+mHV7nuOJBlV 9Xsrdj27GtBQhByo9gcTR9QWttjrhv3nu7BhdHR5c5KQqcYEljRSG5gDQA6EIYSm 1Al1rMxgq0DsBJn9MntVBDjnSgc/0KQ2Yy+1ewFSaer3GAyWmI5h6YsfLnDz4mc= =qfR2 -----END PGP SIGNATURE----- --Apple-Mail=_A8D41E64-0262-4D50-AD9F-2A7E7512969F--