unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* setting non-user variables
@ 2017-05-31 14:26 Héctor Lahoz
  2017-05-31 14:45 ` Emanuel Berg
  2017-05-31 15:40 ` Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: Héctor Lahoz @ 2017-05-31 14:26 UTC (permalink / raw)
  To: help-gnu-emacs

Recently I upgraded my Emacs to version 24 (I don't like to live on
the edge :-) and noticed that I can't use set-variable to set
this buffer-local variable anymore. What should I do?
Why was this changed?

;; before I did:
;; set-variable RET mpkg-master-file RET "file.txt" RET
(make-variable-buffer-local
 (defvar mpkg-master-file))

Do I need an interactive command to set the variable?

(defun set-master-file (filename)
  (interative "fFilename: ")
  (setq mpkg-master-file filename))



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

* Re: setting non-user variables
  2017-05-31 14:26 setting non-user variables Héctor Lahoz
@ 2017-05-31 14:45 ` Emanuel Berg
  2017-05-31 14:58   ` Héctor Lahoz
  2017-05-31 15:40 ` Eli Zaretskii
  1 sibling, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2017-05-31 14:45 UTC (permalink / raw)
  To: help-gnu-emacs

"Héctor Lahoz" <hectorlahoz@gmail.com> writes:

> Recently I upgraded my Emacs to version 24 (I don't like to live on
> the edge :-) and noticed that I can't use set-variable to set
> this buffer-local variable anymore. What should I do?
> Why was this changed?
>
> ;; before I did:
> ;; set-variable RET mpkg-master-file RET "file.txt" RET
> (make-variable-buffer-local
>  (defvar mpkg-master-file))
>
> Do I need an interactive command to set the variable?
>
> (defun set-master-file (filename)
>   (interative "fFilename: ")
>   (setq mpkg-master-file filename))

... what? :)

Try

    (set-variable 'mpkg-master-file "file.txt" t)

with t as in MAKE-LOCAL.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: setting non-user variables
  2017-05-31 14:45 ` Emanuel Berg
@ 2017-05-31 14:58   ` Héctor Lahoz
  2017-05-31 15:20     ` Emanuel Berg
  2017-05-31 15:21     ` John Ankarström
  0 siblings, 2 replies; 14+ messages in thread
From: Héctor Lahoz @ 2017-05-31 14:58 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg wrote:
> Try
> 
>     (set-variable 'mpkg-master-file "file.txt" t)
> 
> with t as in MAKE-LOCAL.
> 

What I meant is that I used set-variable interactively,
as M-x set-variable. Without LISP code.



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

* Re: setting non-user variables
  2017-05-31 14:58   ` Héctor Lahoz
@ 2017-05-31 15:20     ` Emanuel Berg
  2017-06-01  9:12       ` Héctor Lahoz
  2017-05-31 15:21     ` John Ankarström
  1 sibling, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2017-05-31 15:20 UTC (permalink / raw)
  To: help-gnu-emacs

Héctor Lahoz <hectorlahoz@gmail.com> writes:

>> Try
>> 
>>     (set-variable 'mpkg-master-file "file.txt" t)
>> 
>> with t as in MAKE-LOCAL.
>
> What I meant is that I used set-variable
> interactively, as M-x set-variable.
> Without LISP code.

Aha, then do C-u before you do M-x!

From the help

    (set-variable VARIABLE VALUE &optional MAKE-LOCAL)

    [...]
    
    With a prefix argument, set VARIABLE to VALUE
    buffer-locally.

So

    C-u M-x set-variable RET mpkg-master-file RET file.txt RET

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: setting non-user variables
  2017-05-31 14:58   ` Héctor Lahoz
  2017-05-31 15:20     ` Emanuel Berg
@ 2017-05-31 15:21     ` John Ankarström
  2017-05-31 15:23       ` John Ankarström
  1 sibling, 1 reply; 14+ messages in thread
From: John Ankarström @ 2017-05-31 15:21 UTC (permalink / raw)
  To: help-gnu-emacs

Héctor Lahoz <hectorlahoz@gmail.com> writes:

> What I meant is that I used set-variable interactively,
> as M-x set-variable. Without LISP code.

For this, I would use `customize-set-variable' - or,
`customize-variable' if you want the Customize GUI.

- John



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

* Re: setting non-user variables
  2017-05-31 15:21     ` John Ankarström
@ 2017-05-31 15:23       ` John Ankarström
  0 siblings, 0 replies; 14+ messages in thread
From: John Ankarström @ 2017-05-31 15:23 UTC (permalink / raw)
  To: help-gnu-emacs

john@ankarstrom.se (John Ankarström) writes:

> For this, I would use `customize-set-variable' - or,
> `customize-variable' if you want the Customize GUI.

Oh, sorry, I just reread your message, Héctor, and realized that
you want to set buffer-local variables. Please ignore my reply :-)

- John



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

* Re: setting non-user variables
  2017-05-31 14:26 setting non-user variables Héctor Lahoz
  2017-05-31 14:45 ` Emanuel Berg
@ 2017-05-31 15:40 ` Eli Zaretskii
  2017-06-01  9:24   ` Héctor Lahoz
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2017-05-31 15:40 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Héctor Lahoz" <hectorlahoz@gmail.com>
> Date: Wed, 31 May 2017 16:26:44 +0200
> 
> Recently I upgraded my Emacs to version 24 (I don't like to live on
> the edge :-) and noticed that I can't use set-variable to set
> this buffer-local variable anymore. What should I do?
> Why was this changed?
> 
> ;; before I did:
> ;; set-variable RET mpkg-master-file RET "file.txt" RET
> (make-variable-buffer-local
>  (defvar mpkg-master-file))

What package defines mpkg-master-file?  I couldn't find it in packages
bundled with Emacs.

Also, what version of Emacs did you have before the upgrade?



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

* Re: setting non-user variables
  2017-05-31 15:20     ` Emanuel Berg
@ 2017-06-01  9:12       ` Héctor Lahoz
  2017-06-01 13:45         ` Emanuel Berg
  0 siblings, 1 reply; 14+ messages in thread
From: Héctor Lahoz @ 2017-06-01  9:12 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg wrote:
> Héctor Lahoz <hectorlahoz@gmail.com> writes:
> 
> >> Try
> >> 
> >>     (set-variable 'mpkg-master-file "file.txt" t)
> >> 
> >> with t as in MAKE-LOCAL.
> >
> > What I meant is that I used set-variable
> > interactively, as M-x set-variable.
> > Without LISP code.
> 
> Aha, then do C-u before you do M-x!

Thanks, but the key is not "C-u". Either using
"C-u" or not, when I hit TAB it says "no match"
and I can't set the variable.



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

* Re: setting non-user variables
  2017-05-31 15:40 ` Eli Zaretskii
@ 2017-06-01  9:24   ` Héctor Lahoz
  2017-06-01 10:02     ` tomas
  0 siblings, 1 reply; 14+ messages in thread
From: Héctor Lahoz @ 2017-06-01  9:24 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:
> > From: "Héctor Lahoz" <hectorlahoz@gmail.com>
> > Date: Wed, 31 May 2017 16:26:44 +0200
> > 
> > Recently I upgraded my Emacs to version 24 (I don't like to live on
> > the edge :-) and noticed that I can't use set-variable to set
> > this buffer-local variable anymore. What should I do?
> > Why was this changed?
> > 
> > ;; before I did:
> > ;; set-variable RET mpkg-master-file RET "file.txt" RET
> > (make-variable-buffer-local
> >  (defvar mpkg-master-file))
> 
> What package defines mpkg-master-file?  I couldn't find it in packages
> bundled with Emacs.

It is my own. Not published yet.
 
> Also, what version of Emacs did you have before the upgrade?

23.4.1

So, to be clear. The variable is defined like this:

(make-variable-buffer-local
 (defvar mpkg-master-file nil
         "The path of the video associated to the current buffer"))

With 23 I could set the variable interactively, with 24 I can't.



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

* Re: setting non-user variables
  2017-06-01  9:24   ` Héctor Lahoz
@ 2017-06-01 10:02     ` tomas
  2017-06-01 14:20       ` Drew Adams
  0 siblings, 1 reply; 14+ messages in thread
From: tomas @ 2017-06-01 10:02 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Jun 01, 2017 at 11:24:03AM +0200, Héctor Lahoz wrote:
> Eli Zaretskii wrote:
> > > From: "Héctor Lahoz" <hectorlahoz@gmail.com>
> > > Date: Wed, 31 May 2017 16:26:44 +0200
> > > 
> > > Recently I upgraded my Emacs to version 24 (I don't like to live on
> > > the edge :-) and noticed that I can't use set-variable to set
> > > this buffer-local variable anymore. What should I do?
> > > Why was this changed?
> > > 
> > > ;; before I did:
> > > ;; set-variable RET mpkg-master-file RET "file.txt" RET
> > > (make-variable-buffer-local
> > >  (defvar mpkg-master-file))
> > 
> > What package defines mpkg-master-file?  I couldn't find it in packages
> > bundled with Emacs.
> 
> It is my own. Not published yet.
>  
> > Also, what version of Emacs did you have before the upgrade?
> 
> 23.4.1
> 
> So, to be clear. The variable is defined like this:
> 
> (make-variable-buffer-local
>  (defvar mpkg-master-file nil
>          "The path of the video associated to the current buffer"))
> 
> With 23 I could set the variable interactively, with 24 I can't.

I can confirm that (Emacs 26.0.50 here). Variables defined through
defvar seem not to be indexed, whether buffer local or not. If you
use `defcustom', though, this will work:

  (defcustom mpkg-master-file nil "...")

No idea how that interacts with buffer-local though.

To me, it looks intentional. I'm a bit pressed now (should be doing
other things), but I'd expect it to be somewhere in the NEWS.

The nice thing about defcustom is that you get lots of options, like
for setting an edit widget for the value (and possibly some validation
code). The ugly thing is that you now get to read some docs ;-)

Cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlkv5iEACgkQBcgs9XrR2kZxUwCfZC0QPCcH04zPQsXbftnymFEl
i60AmwXmoIcFaVuMBi2SC1Djrd/wIpoS
=gAg3
-----END PGP SIGNATURE-----



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

* Re: setting non-user variables
  2017-06-01  9:12       ` Héctor Lahoz
@ 2017-06-01 13:45         ` Emanuel Berg
  0 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2017-06-01 13:45 UTC (permalink / raw)
  To: help-gnu-emacs

Héctor Lahoz <hectorlahoz@gmail.com> writes:

>> Aha, then do C-u before you do M-x!
>
> Thanks, but the key is not "C-u". Either using "C-u"
> or not, when I hit TAB it says "no match" and
> I can't set the variable.

C-u is `universal-argument'. You can try this for
example with C-u c

    cccc (4 c's)

or, C-u C-u c

    cccccccccccccccc (4**2 = 16 c's)

or, C-u C-u C-u c

    cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
    (4**3 = 64 c's)

or, C-u 3 c

    ccc (3 c's)

and so on.

What you describe is because there isn't any
"mpkg-master-file" variable. So you either need to
load the mode programmatically with `require' or
`load', or go to a situation (state) in Emacs wich
implies it, "the mode" being whatever
module has the variable defined.

You can look for it with

    C-h v mpkg-master-file RET

is it there?

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* RE: setting non-user variables
  2017-06-01 10:02     ` tomas
@ 2017-06-01 14:20       ` Drew Adams
  2017-06-01 15:10         ` tomas
  2017-06-01 15:22         ` Héctor Lahoz
  0 siblings, 2 replies; 14+ messages in thread
From: Drew Adams @ 2017-06-01 14:20 UTC (permalink / raw)
  To: tomas, help-gnu-emacs

> > (make-variable-buffer-local
> >  (defvar mpkg-master-file nil
> >          "The path of the video associated to the current buffer"))
> >
> > With 23 I could set the variable interactively, with 24 I can't.
> 
> I can confirm that (Emacs 26.0.50 here). Variables defined through
> defvar seem not to be indexed, whether buffer local or not. If you
> use `defcustom', though, this will work:
> 
>   (defcustom mpkg-master-file nil "...")

Yes, `set-variable' is for "user variables", aka user options,
only, aka symbols that satisfy predicate `user-variable-p'.

Today, that means a variable that is defined using defcustom,
or an alias to such a variable.

It USED to also mean any variable whose doc string begins with `*'.
Alas (IMHO), this feature was removed from Emacs 23 (i.e., long ago).

In Emacs 22 and prior you could do this:

(defvar foo  42 "*This is foo.")
(put 'foo 'variable-interactive "nWidth: ")

M-x set-variable foo RET

 Width: 13 RET

And `foo' was available for completion (e.g. `f TAB') using
`set-variable'.

Giving a variable a `variable-interactive' property tells
`set-variable' how to read a value for it.



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

* Re: setting non-user variables
  2017-06-01 14:20       ` Drew Adams
@ 2017-06-01 15:10         ` tomas
  2017-06-01 15:22         ` Héctor Lahoz
  1 sibling, 0 replies; 14+ messages in thread
From: tomas @ 2017-06-01 15:10 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Jun 01, 2017 at 07:20:03AM -0700, Drew Adams wrote:

[...]

> Yes, `set-variable' is for "user variables", aka user options,
> only, aka symbols that satisfy predicate `user-variable-p'.
> 
> Today, that means a variable that is defined using defcustom,
> or an alias to such a variable.
> 
> It USED to also mean any variable whose doc string begins with `*'.
> Alas (IMHO), this feature was removed from Emacs 23 (i.e., long ago).

[...]

Thanks for the details. This makes my hunches more concrete
(without me having to look all that up: you're spoiling me :)

Cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlkwLmgACgkQBcgs9XrR2kaFmQCfX/svHXKQFJn+bLYm5vHyzXEd
nzcAn1tGk+KM7mLs8mU0H0wly9nn3Jwx
=wFpS
-----END PGP SIGNATURE-----



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

* Re: setting non-user variables
  2017-06-01 14:20       ` Drew Adams
  2017-06-01 15:10         ` tomas
@ 2017-06-01 15:22         ` Héctor Lahoz
  1 sibling, 0 replies; 14+ messages in thread
From: Héctor Lahoz @ 2017-06-01 15:22 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:
> > > (make-variable-buffer-local
> > >  (defvar mpkg-master-file nil
> > >          "The path of the video associated to the current buffer"))
> > >
> > > With 23 I could set the variable interactively, with 24 I can't.
> > 
> > I can confirm that (Emacs 26.0.50 here). Variables defined through
> > defvar seem not to be indexed, whether buffer local or not. If you
> > use `defcustom', though, this will work:
> > 
> >   (defcustom mpkg-master-file nil "...")
> 
> Yes, `set-variable' is for "user variables", aka user options,
> only, aka symbols that satisfy predicate `user-variable-p'.
> 
> Today, that means a variable that is defined using defcustom,
> or an alias to such a variable.
> 
> It USED to also mean any variable whose doc string begins with `*'.
> Alas (IMHO), this feature was removed from Emacs 23 (i.e., long ago).
> 
> In Emacs 22 and prior you could do this:
> 
> (defvar foo  42 "*This is foo.")
> (put 'foo 'variable-interactive "nWidth: ")
> 
> M-x set-variable foo RET
> 
>  Width: 13 RET
> 
> And `foo' was available for completion (e.g. `f TAB') using
> `set-variable'.
> 
> Giving a variable a `variable-interactive' property tells
> `set-variable' how to read a value for it.
> 

You hit the nail on the head. In fact there is a "*" at the
beginning of the docstring and I was wondering why I put it
there some years ago.

Thanks a lot.



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

end of thread, other threads:[~2017-06-01 15:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-31 14:26 setting non-user variables Héctor Lahoz
2017-05-31 14:45 ` Emanuel Berg
2017-05-31 14:58   ` Héctor Lahoz
2017-05-31 15:20     ` Emanuel Berg
2017-06-01  9:12       ` Héctor Lahoz
2017-06-01 13:45         ` Emanuel Berg
2017-05-31 15:21     ` John Ankarström
2017-05-31 15:23       ` John Ankarström
2017-05-31 15:40 ` Eli Zaretskii
2017-06-01  9:24   ` Héctor Lahoz
2017-06-01 10:02     ` tomas
2017-06-01 14:20       ` Drew Adams
2017-06-01 15:10         ` tomas
2017-06-01 15:22         ` Héctor Lahoz

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