all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* interactive interface to supply variables
@ 2013-12-14 19:09 Emanuel Berg
  2013-12-14 19:52 ` Juanma Barranquero
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-14 19:09 UTC (permalink / raw)
  To: help-gnu-emacs

(defvar test-var 1)
(symbol-value 'test-var)      ; 1
(symbol-name 'test-var)       ; "test-var" (both correct)

But:

(custom-variable-p 'test-var) ; nil

This messes up this defun:

(defun describe-variable-short (var)
  (interactive "v Variable: ")
  (message (format " %s: %s" (symbol-name var) (symbol-value var))) )

Because if `custom-variable-p' is nil, (interactive "v
... reports [No match].

How does `describe-variable' do that? (Perhaps I should
just copy their interface, because they also suggest
the variable at point as default. But that's step two.)

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
  2013-12-14 19:09 interactive interface to supply variables Emanuel Berg
@ 2013-12-14 19:52 ` Juanma Barranquero
  2013-12-15  4:58   ` Michael Heerdegen
       [not found]   ` <mailman.9280.1387083570.10748.help-gnu-emacs@gnu.org>
       [not found] ` <mailman.9242.1387050824.10748.help-gnu-emacs@gnu.org>
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 15+ messages in thread
From: Juanma Barranquero @ 2013-12-14 19:52 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: Emacs Help List

> (symbol-name 'test-var)       ; "test-var" (both correct)

This is irrelevant: (symbol-name 'my-var) => "my-var" even if no
(defvar my-var X) was ever used.

> How does `describe-variable' do that? (Perhaps I should
> just copy their interface, because they also suggest
> the variable at point as default. But that's step two.)

  custom-variable-p is a compiled Lisp function in `custom.el'.

  Return non-nil if variable is a customizable variable.
  A customizable variable is either (i) a variable whose property
  list contains a non-nil `standard-value' or `custom-autoload'
  property, or (ii) an alias for another customizable variable.

So:

  (defvar test-var 1)
  (put 'test-var 'standard-value t)

   J



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

* Re: interactive interface to supply variables
       [not found] ` <mailman.9242.1387050824.10748.help-gnu-emacs@gnu.org>
@ 2013-12-14 20:46   ` Emanuel Berg
  0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-14 20:46 UTC (permalink / raw)
  To: help-gnu-emacs

Juanma Barranquero <lekktu@gmail.com> writes:

> This is irrelevant: (symbol-name 'my-var) => "my-var"
> even if no (defvar my-var X) was ever used.

OK, but it is not irrelevant as it is used in the
defun.

>   (defvar test-var 1) (put 'test-var 'standard-value
>   t)

Yes, that works for (custom-variable-p 'test-var) but
again, if you examine the defun the interface looks
like this:

(interactive "v Variable: ")

And the question is: how do I make that accept
variables, *all* variables, not only those that pass
`custom-variable-p'?

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
  2013-12-14 19:09 interactive interface to supply variables Emanuel Berg
  2013-12-14 19:52 ` Juanma Barranquero
       [not found] ` <mailman.9242.1387050824.10748.help-gnu-emacs@gnu.org>
@ 2013-12-14 21:01 ` Barry Margolin
  2013-12-14 21:42   ` Emanuel Berg
  2013-12-14 21:09 ` Jambunathan K
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Barry Margolin @ 2013-12-14 21:01 UTC (permalink / raw)
  To: help-gnu-emacs

In article <87vbyr45bj.fsf@nl106-137-194.student.uu.se>,
 Emanuel Berg <embe8573@student.uu.se> wrote:

> (defvar test-var 1)
> (symbol-value 'test-var)      ; 1
> (symbol-name 'test-var)       ; "test-var" (both correct)
> 
> But:
> 
> (custom-variable-p 'test-var) ; nil
> 
> This messes up this defun:
> 
> (defun describe-variable-short (var)
>   (interactive "v Variable: ")
>   (message (format " %s: %s" (symbol-name var) (symbol-value var))) )
> 
> Because if `custom-variable-p' is nil, (interactive "v
> ... reports [No match].
> 
> How does `describe-variable' do that? (Perhaps I should
> just copy their interface, because they also suggest
> the variable at point as default. But that's step two.)

I'm still using Emacs 22.x. In this version, the "v" specification reads 
any variable for which user-variable-p is true:

(1) the first character of its documentation is `*', or
(2) it is customizable (its property list contains a non-nil value
    of `standard-value' or `custom-autoload'), or
(3) it is an alias for another user variable.

Have they removed clause (1) in your version? If not, give your variable 
a doc string beginning with "*".

describe-variable uses a custom interactive specification. It accepts 
any symbol that has a binding or has a documentation string. If you want 
this more liberal prompt, you'll probably have to copy the code.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* Re: interactive interface to supply variables
  2013-12-14 19:09 interactive interface to supply variables Emanuel Berg
                   ` (2 preceding siblings ...)
  2013-12-14 21:01 ` Barry Margolin
@ 2013-12-14 21:09 ` Jambunathan K
       [not found] ` <mailman.9258.1387055530.10748.help-gnu-emacs@gnu.org>
  2013-12-14 23:39 ` Drew Adams
  5 siblings, 0 replies; 15+ messages in thread
From: Jambunathan K @ 2013-12-14 21:09 UTC (permalink / raw)
  To: help-gnu-emacs


Declare the variable with defcustom instead of defvar.

You can `put' and `get' stuff on a symbol.  As an experiment, Try C-x n
n or any of the narrowing command and see what happens to your .emacs.

You can also use the "x" interactive spec and check the expression that
is input with symbolp.

Emanuel Berg <embe8573@student.uu.se> writes:

> (defvar test-var 1)
> (symbol-value 'test-var)      ; 1
> (symbol-name 'test-var)       ; "test-var" (both correct)
>
> But:
>
> (custom-variable-p 'test-var) ; nil
>
> This messes up this defun:
>
> (defun describe-variable-short (var)
>   (interactive "v Variable: ")
>   (message (format " %s: %s" (symbol-name var) (symbol-value var))) )
>
> Because if `custom-variable-p' is nil, (interactive "v
> ... reports [No match].
>
> How does `describe-variable' do that? (Perhaps I should
> just copy their interface, because they also suggest
> the variable at point as default. But that's step two.)



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

* Re: interactive interface to supply variables
  2013-12-14 21:01 ` Barry Margolin
@ 2013-12-14 21:42   ` Emanuel Berg
  0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-14 21:42 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> I'm still using Emacs 22.x. In this version, the "v"
> specification reads any variable for which
> user-variable-p is true:
>
> (1) the first character of its documentation is `*' ...
>
> Have they removed clause (1) in your version? If not,
> give your variable a doc string beginning with "*".

Again, that isn't something that would solve anything
because the purpose is to have the help function work
on *all* variables, not just those that are prepared in
this way or the other. In practice, when I am to use
the defun, this can of course never be expected!

> describe-variable uses a custom interactive
> specification. It accepts any symbol that has a
> binding or has a documentation string. If you want
> this more liberal prompt, you'll probably have to
> copy the code.

Yes, I will check that out after we have reached
somewhere sensible with this.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
       [not found] ` <mailman.9258.1387055530.10748.help-gnu-emacs@gnu.org>
@ 2013-12-14 21:46   ` Emanuel Berg
  2013-12-14 21:51   ` Emanuel Berg
  2013-12-15  0:09   ` Emanuel Berg
  2 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-14 21:46 UTC (permalink / raw)
  To: help-gnu-emacs

Jambunathan K <kjambunathan@gmail.com> writes:

> Declare the variable with defcustom instead of
> defvar.

Again, this is nothing that can be solved by changing
the *variable*. That is the whole thing: the interface
should accept *all* variables, and it doesn't. To solve
this, we much change the interface, or perhaps some
global the interface works upon, not the single,
individual test variable.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
       [not found] ` <mailman.9258.1387055530.10748.help-gnu-emacs@gnu.org>
  2013-12-14 21:46   ` Emanuel Berg
@ 2013-12-14 21:51   ` Emanuel Berg
  2013-12-15  5:41     ` Jambunathan K
       [not found]     ` <mailman.9281.1387086321.10748.help-gnu-emacs@gnu.org>
  2013-12-15  0:09   ` Emanuel Berg
  2 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-14 21:51 UTC (permalink / raw)
  To: help-gnu-emacs

Jambunathan K <kjambunathan@gmail.com> writes:

> You can also use the "x" interactive spec and check
> the expression that is input with symbolp.

But then, you will not get autocompletion for variables
(only), or a [No match] if there isn't such a variable,
will you?

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* RE: interactive interface to supply variables
  2013-12-14 19:09 interactive interface to supply variables Emanuel Berg
                   ` (4 preceding siblings ...)
       [not found] ` <mailman.9258.1387055530.10748.help-gnu-emacs@gnu.org>
@ 2013-12-14 23:39 ` Drew Adams
  5 siblings, 0 replies; 15+ messages in thread
From: Drew Adams @ 2013-12-14 23:39 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

> (interactive "v Variable: ")

"vVariable: " is more conventional, FWIW.

> How does `describe-variable' do that?

What does `describe-variable' say about how it does it?  Ask it.
Take a look.  Why ask someone here to say how `describe-variable'
does it?  What fun is that?

`interactive' with a string arg is very simple.  It serves only
as an abbreviation for common use cases - nothing more.

But `interactive' with a non-string arg does whatever you want.
It is easy to make it prompt for and provide completion for all
symbols that are `boundp', i.e., all variables (in the current
obarray).  I'm guessing that's a challenge you might enjoy, once
undertaken.  `C-h f interactive' and `C-h f completing-read'.

Emacs itself is the first helper to ask about such things - for
one's own greatest benefit.  Google is a reasonable second.

This list or StackOverflow is really best fit for questions you
still have after you have already tried something on your own.

Nothing wrong with asking here first, of course.  But for most
people there are better ways to learn to fish, and it is more
interesting to discover most of Emacs by interacting with Emacs
itself.

This example is a good opportunity to ask Emacs - a relatively
easy challenge that rewards quickly.



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

* Re: interactive interface to supply variables
       [not found] ` <mailman.9258.1387055530.10748.help-gnu-emacs@gnu.org>
  2013-12-14 21:46   ` Emanuel Berg
  2013-12-14 21:51   ` Emanuel Berg
@ 2013-12-15  0:09   ` Emanuel Berg
  2013-12-15  0:46     ` Emanuel Berg
  2 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2013-12-15  0:09 UTC (permalink / raw)
  To: help-gnu-emacs

This proved to be not so easy as I thought.

I installed emacs24-el and in help-fns.el I saw how
they did it in `describe-variable' - this is a
variation of their method, only, to determine if it is
a variable, they use

(or (get vv 'variable-documentation)
    (and (boundp vv)
         (not (keywordp vv)))))

while I use `boundp' only - I don't know what
`keywordp' brings. However, `boundp' isn't optimal for
unbounded variables (of course) - in those cases, it
should be communicated that there is such a variable,
only it isn't bound. `symbolp' perhaps in combination
with something else (because sumbolp is too inclusive).

Anyway, check it out.

(defun describe-variable-short (var)
  (interactive
   (let*((v            (variable-at-point))
         (var-at-point (not (eq v 0)))
         (v-name       (if var-at-point (symbol-name v)))
         (v-final
          (completing-read
           ;; prompt
           (format " Variable%s: " (if var-at-point
                                       (format " (default %s)" v)
                                       ""))
           obarray                   ; from this set (all objects?)
           (lambda (vv) (boundp vv)) ; delimit set
           t                         ; require match
           nil                       ; no insert to minibuffer (?)
           nil                       ; no history
           v-name                    ; default
          )))
   `(,(intern v-final))))
  (message (format " %s: %s" (symbol-name var) (symbol-value var))) )
(global-set-key "\C-hV" 'describe-variable-short)

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
  2013-12-15  0:09   ` Emanuel Berg
@ 2013-12-15  0:46     ` Emanuel Berg
  0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-15  0:46 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> I installed emacs24-el and in help-fns.el I saw how
> they did it in `describe-variable' - this is a
> variation of their method, only, to determine if it
> is a variable, they use
>
> (or (get vv 'variable-documentation)
>     (and (boundp vv)
>          (not (keywordp vv)))))
>
> while I use `boundp' only - I don't know what
> `keywordp' brings.

`keywordp' is to exclude keywords. Those are not
special forms like "defun", or even "if", but instead
:foreground, :bold, anything that starts with a colon.

`boundp' will always eval to t for those, as they are
bound to their names.

Perhaps it makes sense to exclude those, as those
aren't variables, for sure.

But this is possible

(defvar :var-looks-like-keyword)

though further assignment is not (?).

So I don't think I'll add that. It doesn't hurt to have
it say that :bold is :bold.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
  2013-12-14 19:52 ` Juanma Barranquero
@ 2013-12-15  4:58   ` Michael Heerdegen
       [not found]   ` <mailman.9280.1387083570.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 15+ messages in thread
From: Michael Heerdegen @ 2013-12-15  4:58 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> I'm still using Emacs 22.x. In this version, the "v" specification reads 
> any variable for which user-variable-p is true:
>
> (1) the first character of its documentation is `*', or
> (2) it is customizable (its property list contains a non-nil value
>     of `standard-value' or `custom-autoload'), or
> (3) it is an alias for another user variable.
>
> Have they removed clause (1) in your version? If not, give your variable 
> a doc string beginning with "*".

AFAIK, the `*' prefix rule for user variable doc strings has been given
up.

And now (recent release of Emacs), `user-variable-p' is an obsoleted
alias for `custom-variable-p':

,----------------------------------------------------------------------
| Return non-nil if VARIABLE is a customizable variable.
| A customizable variable is either (i) a variable whose property
| list contains a non-nil `standard-value' or `custom-autoload'
| property, or (ii) an alias for another customizable variable.
`----------------------------------------------------------------------


Regards,

Michael.




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

* Re: interactive interface to supply variables
       [not found]   ` <mailman.9280.1387083570.10748.help-gnu-emacs@gnu.org>
@ 2013-12-15  5:23     ` Emanuel Berg
  0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-15  5:23 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> And now (recent release of Emacs), `user-variable-p'
> is an obsoleted alias for `custom-variable-p'.

Yes: 24.3. So what is the consensus (if there is one)
to determine if something is a variable or not? - like
I said, in describe-function they put a condition on
obarray:

(or (get vv 'variable-documentation)
    (and (boundp vv)
         (not (keywordp vv)))))

`custom-variable-p' corresponds to "v" in the
interactive string, and that wasn't inclusive enough,
at least not in my case - which is - quite general, or
am I wrong?!

I think the above solution (the Elisp) should be put
into something like `variable-p' and then this should
be possible to indicate in the interactive
string. Perhaps an optional param (and/or prefix arg)
would indicate where to look if not in obarray.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: interactive interface to supply variables
  2013-12-14 21:51   ` Emanuel Berg
@ 2013-12-15  5:41     ` Jambunathan K
       [not found]     ` <mailman.9281.1387086321.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 15+ messages in thread
From: Jambunathan K @ 2013-12-15  5:41 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> Jambunathan K <kjambunathan@gmail.com> writes:
>
>> You can also use the "x" interactive spec and check
>> the expression that is input with symbolp.
>
> But then, you will not get autocompletion for variables
> (only), or a [No match] if there isn't such a variable,
> will you?

Add this to your .emacs.

   (find-function-setup-keys)

Then doing this will land you in the .el file.
   
   C-x F describe-variable

Look at how the interactive spec is defined.

It would have answered ALL or MOST of your questions.  It would have
also answered questions that you have not had yet.

When you are comfortable with Emacs Lisp, I don't see any reason why
should rely on help for others.  This is the reason I suggested that you
should checkout Emacs from bzr repo or install the .el files (if they
are not shipped by default in your distribution.)





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

* Re: interactive interface to supply variables
       [not found]     ` <mailman.9281.1387086321.10748.help-gnu-emacs@gnu.org>
@ 2013-12-15 18:14       ` Emanuel Berg
  0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-15 18:14 UTC (permalink / raw)
  To: help-gnu-emacs

Jambunathan K <kjambunathan@gmail.com> writes:

> Add this to your .emacs.
>
>    (find-function-setup-keys)
>
> Then doing this will land you in the .el file.
>    
>    C-x F describe-variable

Yes, you can also use C-h f (`describe-function') and
follow the link.

> When you are comfortable with Emacs Lisp ...

I'm not comfortable with Elisp (but not exactly
dis comfortable, either). I'm more comfortable with C
(or that's a tie perhaps). But Elisp is much more
expressible than C with &optional, &rest, backtick, the
interfaces we just mentioned, macros (compare that to
the C #preprocessor), with tons of other stuff I cannot
think of right now. So Elisp (or Lisp) requires more
work, but it is also much more pleasant as it is much
more dynamic (no recompilation one million times) and
you don't have to bother with types, pointers, memory
[dis]allocation, and all that error prone stuff.

> I don't see any reason why should rely on help for
> others.

I'm not relying on anyone. I did my whole CS education
with barley meeting my teachers. I'm *active* with other
people, in a way that is social, pleasant and
productive. Although I am very thankful for everyone
taking part in this dance, if they themselves don't
enjoy it or see any point of it, I discourage them
from doing it.

> This is the reason I suggested that you should
> checkout Emacs from bzr repo or install the .el files
> (if they are not shipped by default in your
> distribution.)

I mention this in my very first post, and that is also
what I did.

The Emacs source is not shipped by default on Debian,
it would seem, but it is easy to get. The package is
emacs24-el. Contrary to the Elisp manual, that was in
the free Debian repos, so there were no obstacles.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

end of thread, other threads:[~2013-12-15 18:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-14 19:09 interactive interface to supply variables Emanuel Berg
2013-12-14 19:52 ` Juanma Barranquero
2013-12-15  4:58   ` Michael Heerdegen
     [not found]   ` <mailman.9280.1387083570.10748.help-gnu-emacs@gnu.org>
2013-12-15  5:23     ` Emanuel Berg
     [not found] ` <mailman.9242.1387050824.10748.help-gnu-emacs@gnu.org>
2013-12-14 20:46   ` Emanuel Berg
2013-12-14 21:01 ` Barry Margolin
2013-12-14 21:42   ` Emanuel Berg
2013-12-14 21:09 ` Jambunathan K
     [not found] ` <mailman.9258.1387055530.10748.help-gnu-emacs@gnu.org>
2013-12-14 21:46   ` Emanuel Berg
2013-12-14 21:51   ` Emanuel Berg
2013-12-15  5:41     ` Jambunathan K
     [not found]     ` <mailman.9281.1387086321.10748.help-gnu-emacs@gnu.org>
2013-12-15 18:14       ` Emanuel Berg
2013-12-15  0:09   ` Emanuel Berg
2013-12-15  0:46     ` Emanuel Berg
2013-12-14 23:39 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.