unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / 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

* Re: Help needed with defadvice
  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 14:44 ` Stefan Monnier
  2 siblings, 0 replies; 15+ messages in thread
From: Eric Abrahamsen @ 2013-11-22  6:27 UTC (permalink / raw)
  To: help-gnu-emacs

Perry Smith <pedzsan@gmail.com> 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




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

* Re: Help needed with defadvice
  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
       [not found]   ` <mailman.6834.1385135422.10748.help-gnu-emacs@gnu.org>
  2013-11-22 14:44 ` Stefan Monnier
  2 siblings, 2 replies; 15+ messages in thread
From: Alex Kost @ 2013-11-22  7:09 UTC (permalink / raw)
  To: Perry Smith; +Cc: help-gnu-emacs

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.

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)).

2. Don't quote lambdas: <http://www.emacswiki.org/emacs/QuotedLambda>.

3. "alist" means "association list", so you shouldn't call
`inherited-alist' like this as it's a simple list.  For info about
alists look at (info "(elisp) Association Lists").

4. I believe making an advice for `get-buffer-create' is not a good
idea.  Don't you have a lot of messages about setting variables in
*temp* buffers?  Thus you will set unintended variables for any new
buffer.  Do you really need that?



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

* Re: Help needed with defadvice
  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 14:44 ` Stefan Monnier
  2 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2013-11-22 14:44 UTC (permalink / raw)
  To: help-gnu-emacs

>       (mapcar '(lambda ( c )

Running the for the Useless Use of Quote Award?


        Stefan




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

* Re: Help needed with defadvice
  2013-11-22  7:09 ` Alex Kost
@ 2013-11-22 15:50   ` Perry Smith
  2013-11-22 21:56     ` Alex Kost
       [not found]   ` <mailman.6834.1385135422.10748.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Perry Smith @ 2013-11-22 15:50 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org Help

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


On Nov 22, 2013, at 1:09 AM, Alex Kost <alezost@gmail.com> 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.

I changed it to be:

(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 (make-local-variable (car c)) (cdr c)))
	      set-list)))
  (setq cscope-out-buffer "juice"))

and describe-variable still has the same output.  It is still set to "banana" (not "juice")

(I tried setq as well as set with make-variable-buffer-local).

> 
> 2. Don't quote lambdas: <http://www.emacswiki.org/emacs/QuotedLambda>.

Ok.  (no change to my issue)

> 
> 3. "alist" means "association list", so you shouldn't call
> `inherited-alist' like this as it's a simple list.  For info about
> alists look at (info "(elisp) Association Lists").

Thanks... I should have known that.  In my defense, I wrote this
25 years ago and I haven't touched it since.

> 
> 4. I believe making an advice for `get-buffer-create' is not a good
> idea.  Don't you have a lot of messages about setting variables in
> *temp* buffers?  Thus you will set unintended variables for any new
> buffer.  Do you really need that?

I had it "up" a level or two doing advice for create-file-buffer but it had
the same problem.  The message will go away when I'm done.  I'm not
sure where I want to put it.

On perhaps a side note, the documentation for make-variable-buffer-local 
has this curious sentence:

Note that binding the variable with `let', or setting it while
a `let'-style binding made in this buffer is in effect,
does not make the variable buffer-local.

I think I'm doing the 2nd phrase -- right?  But then I get confused and
I don't understand why my other example works because it is inside
a let binding a well.  Even if I remove my let, I am likely going to be
inside a let but whoever is calling down to the function I am advising.

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

* Re: Help needed with defadvice
  2013-11-22 15:50   ` Perry Smith
@ 2013-11-22 21:56     ` Alex Kost
  2013-11-23  1:41       ` Perry Smith
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Kost @ 2013-11-22 21:56 UTC (permalink / raw)
  To: Perry Smith; +Cc: help-gnu-emacs@gnu.org Help

Perry Smith (2013-11-22 19:50 +0400) wrote:

> On Nov 22, 2013, at 1:09 AM, Alex Kost <alezost@gmail.com> 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.




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

* Re: Help needed with defadvice
  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
  0 siblings, 2 replies; 15+ messages in thread
From: Perry Smith @ 2013-11-23  1:41 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-gnu-emacs@gnu.org Help

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

On Nov 22, 2013, at 3:56 PM, Alex Kost <alezost@gmail.com> wrote:

> Perry Smith (2013-11-22 19:50 +0400) wrote:
> 
>> On Nov 22, 2013, at 1:09 AM, Alex Kost <alezost@gmail.com> 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.

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


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

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

* Re: Help needed with defadvice
  2013-11-23  1:41       ` Perry Smith
@ 2013-11-23  7:00         ` Alex Kost
  2013-11-23 14:48         ` Stefan Monnier
  1 sibling, 0 replies; 15+ messages in thread
From: Alex Kost @ 2013-11-23  7:00 UTC (permalink / raw)
  To: Perry Smith; +Cc: help-gnu-emacs@gnu.org Help

Perry Smith (2013-11-23 05:41 +0400) wrote:

> 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).

As for me, i don't see a reason for killing local variables there.  For
example i have some local variables and after "M-x text-mode" they all
die as text-mode is a derived-mode.  This behaviour doesn't seem right
to me.

Will you "M-x report-emacs-bug" about it? (to clarify why that is there)



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

* Re: Help needed with defadvice
       [not found]   ` <mailman.6834.1385135422.10748.help-gnu-emacs@gnu.org>
@ 2013-11-23  8:35     ` jack-mac
  0 siblings, 0 replies; 15+ messages in thread
From: jack-mac @ 2013-11-23  8:35 UTC (permalink / raw)
  To: help-gnu-emacs

Le vendredi 22 novembre 2013 16:50:02 UTC+1, Perry Smith a écrit :
> On perhaps a side note, the documentation for make-variable-buffer-local 
> has this curious sentence:
> 
>> Note that binding the variable with `let', 
>> does not make the variable buffer-local.
> 
> I think I'm doing the 2nd phrase -- right?

I don't think so!

They probably mean:
>> or setting it while a `let'-style binding OF THIS SAME VARIABLE
>> made in this buffer is in effect,

Something like:
(with-current-buffer (current-buffer)
  (let ((my-var 'foo))
    (set (make-local-variable 'my-var) 'bar)
    (message "inside let, my-var is %s" my-var))
  (message "outside let, my-var is %s" (if (boundp 'my-var) my-var '_undef_)))

> But then I get confused and
> I don't understand why my other example works because it is inside
> a let binding a well.  Even if I remove my let, I am likely going to be
> inside a let but whoever is calling down to the function I am advising.

HTH
)jack(


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

* Re: Help needed with defadvice
  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:43           ` Alex Kost
  1 sibling, 2 replies; 15+ messages in thread
From: Stefan Monnier @ 2013-11-23 14:48 UTC (permalink / raw)
  To: help-gnu-emacs

> 	  (,(or parent 'kill-all-local-variables))   <<<<<<<<<
[...]
> Does anyone know why this is there?

Read the Elisp manual's description of what a major mode should do.
Buffer-local variables are (in their majority) specific a particular
major mode, hence they are reset when the major mode changes.


        Stefan




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

* Re: Help needed with defadvice
  2013-11-23 14:48         ` Stefan Monnier
@ 2013-11-23 15:22           ` Perry Smith
  2013-11-23 15:38             ` Stefan Monnier
  2013-11-23 15:43           ` Alex Kost
  1 sibling, 1 reply; 15+ messages in thread
From: Perry Smith @ 2013-11-23 15:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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


On Nov 23, 2013, at 8:48 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>> 	  (,(or parent 'kill-all-local-variables))   <<<<<<<<<
> [...]
>> Does anyone know why this is there?
> 
> Read the Elisp manual's description of what a major mode should do.
> Buffer-local variables are (in their majority) specific a particular
> major mode, hence they are reset when the major mode changes.

Ok.  Alex suggested a bug report.  I guess I will hold off on that.  I have it
written up ready to send.  Let me know if you would prefer it sent or not.

I got around the issue with:

(defadvice kill-all-local-variables (around inherit activate)
  "We want inherited variables to survive a call to this function"
  (let* ((set-list (mapcar (lambda ( v )
			     (cons v (symbol-value v)))
			   inherited-alist)))
    ad-do-it
    (mapcar (lambda ( c )
	      (set (car c) (cdr c)))
	    set-list)))

How about an extra blurb in the documentation for make-variable-buffer-local
(and / or) make-local-variable that notes that they are usually killed when
entering a new mode?  It was clear that someone was killing the variables
but it was hard for me to track down who it was.

Thank you again to all who helped me out.

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

* Re: Help needed with defadvice
  2013-11-23 15:22           ` Perry Smith
@ 2013-11-23 15:38             ` Stefan Monnier
  2013-11-23 16:24               ` Perry Smith
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2013-11-23 15:38 UTC (permalink / raw)
  To: help-gnu-emacs

> (defadvice kill-all-local-variables (around inherit activate)
>   "We want inherited variables to survive a call to this function"
>   (let* ((set-list (mapcar (lambda ( v )
> 			     (cons v (symbol-value v)))
> 			   inherited-alist)))
>     ad-do-it
>     (mapcar (lambda ( c )
> 	      (set (car c) (cdr c)))
> 	    set-list)))

> How about an extra blurb in the documentation for make-variable-buffer-local

Which documentation?  The Elisp manual talks about it, as well as about
the `permanant-local' property, which you might like to use.


        Stefan




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

* Re: Help needed with defadvice
  2013-11-23 14:48         ` Stefan Monnier
  2013-11-23 15:22           ` Perry Smith
@ 2013-11-23 15:43           ` Alex Kost
  1 sibling, 0 replies; 15+ messages in thread
From: Alex Kost @ 2013-11-23 15:43 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier (2013-11-23 18:48 +0400) wrote:

>> 	  (,(or parent 'kill-all-local-variables))   <<<<<<<<<
> [...]
>> Does anyone know why this is there?
>
> Read the Elisp manual's description of what a major mode should do.
> Buffer-local variables are (in their majority) specific a particular
> major mode, hence they are reset when the major mode changes.

Thanks for the explanation.

(info "(elisp) Creating Buffer-Local") tells about that.  Happily there
is still a possibility for a buffer-local variable to survive after
`kill-all-local-variables': setting a `permanent-local' property of that
variable to non-nil.

Perry Smith, I think this can help you.



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

* Re: Help needed with defadvice
  2013-11-23 15:38             ` Stefan Monnier
@ 2013-11-23 16:24               ` Perry Smith
  2013-11-24 18:21                 ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Perry Smith @ 2013-11-23 16:24 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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


On Nov 23, 2013, at 9:38 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>> (defadvice kill-all-local-variables (around inherit activate)
>>  "We want inherited variables to survive a call to this function"
>>  (let* ((set-list (mapcar (lambda ( v )
>> 			     (cons v (symbol-value v)))
>> 			   inherited-alist)))
>>    ad-do-it
>>    (mapcar (lambda ( c )
>> 	      (set (car c) (cdr c)))
>> 	    set-list)))
> 
>> How about an extra blurb in the documentation for make-variable-buffer-local
> 
> Which documentation?  The Elisp manual talks about it, as well as about
> the `permanant-local' property, which you might like to use.

I was thinking about this documentation:

> make-variable-buffer-local is an interactive built-in function in `C
> source code'.
> 
> (make-variable-buffer-local VARIABLE)
> 
> Make VARIABLE become buffer-local whenever it is set.
> At any time, the value for the current buffer is in effect,
> unless the variable has never been set in this buffer,
> in which case the default value is in effect.
> Note that binding the variable with `let', or setting it while
> a `let'-style binding made in this buffer is in effect,
> does not make the variable buffer-local.  Return VARIABLE.
> 
> In most cases it is better to use `make-local-variable',
> which makes a variable local in just one buffer.
> 
> The function `default-value' gets the default value and `set-default' sets it.

I see permanent-local is mentioned in kill-all-local-variables but I don't
know to go to that documentation.  I generally use describe-function
and describe-variable inside emacs and rarely go to the elisp manual
although I was using it for help with advice the past few days.

I view the elisp manual as a "book" and go there to read up on entire
topics but if I *think* I know what I'm doing, I don't use it.  Perhaps I
need to change that habit.

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

* Re: Help needed with defadvice
  2013-11-23 16:24               ` Perry Smith
@ 2013-11-24 18:21                 ` Stefan Monnier
  0 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2013-11-24 18:21 UTC (permalink / raw)
  To: Perry Smith; +Cc: help-gnu-emacs

>> Which documentation?  The Elisp manual talks about it, as well as about
>> the `permanant-local' property, which you might like to use.

> I was thinking about this documentation:

>> make-variable-buffer-local is an interactive built-in function in `C
>> source code'.

I've changed the docstring to explain when it's cleared.


        Stefan



^ 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).