Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
reading a variable from the user
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
drain  
View profile  
 More options Oct 10 2012, 3:24 am
Newsgroups: gnu.emacs.help
From: drain <aeus...@gmail.com>
Date: Wed, 10 Oct 2012 00:24:35 -0700 (PDT)
Local: Wed, Oct 10 2012 3:24 am
Subject: reading a variable from the user
Is there a function that prompts the user in the mini-buffer, matches the
string input with a local variable name, and then returns the variable?

--
View this message in context: http://emacs.1067599.n5.nabble.com/reading-a-variable-from-the-user-t...
Sent from the Emacs - Help mailing list archive at Nabble.com.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco Mazzoli  
View profile  
 More options Oct 10 2012, 5:08 am
Newsgroups: gnu.emacs.help
From: Francesco Mazzoli <f...@mazzo.li>
Date: Wed, 10 Oct 2012 10:08:34 +0100
Local: Wed, Oct 10 2012 5:08 am
Subject: Re: reading a variable from the user
At Wed, 10 Oct 2012 00:24:35 -0700 (PDT),

drain wrote:
> Is there a function that prompts the user in the mini-buffer, matches the
> string input with a local variable name, and then returns the variable?

You can use something like

    (defun foo (var)
      (interactive "v")
      (message "%S" (symbol-value var)))

See the help page for `interactive' for more info.

--
Francesco * Often in error, never in doubt


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tassilo Horn  
View profile  
 More options Oct 10 2012, 5:16 am
Newsgroups: gnu.emacs.help
From: Tassilo Horn <t...@gnu.org>
Date: Wed, 10 Oct 2012 11:16:06 +0200
Local: Wed, Oct 10 2012 5:16 am
Subject: Re: reading a variable from the user

Francesco Mazzoli <f...@mazzo.li> writes:
> At Wed, 10 Oct 2012 00:24:35 -0700 (PDT),
> drain wrote:
>> Is there a function that prompts the user in the mini-buffer, matches the
>> string input with a local variable name, and then returns the variable?

> You can use something like

>     (defun foo (var)
>       (interactive "v")
>       (message "%S" (symbol-value var)))

> See the help page for `interactive' for more info.

Or simply do `C-h v <variable-name> RET' which shows the documentation
and the current value of that variable.

Bye,
Tassilo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
horse_rivers  
View profile  
 More options Oct 10 2012, 5:23 am
Newsgroups: gnu.emacs.help
From: horse_rivers <horse_riv...@126.com>
Date: Wed, 10 Oct 2012 17:22:54 +0800 (CST)
Local: Wed, Oct 10 2012 5:22 am
Subject: Re:Re: reading a variable from the user

is this in gdb's  debug mode ,which is used to get  the  debugged  process's  local  varible value?

At 2012-10-10 17:16:06,"Tassilo Horn" <t...@gnu.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doug Lewan  
View profile  
 More options Oct 10 2012, 9:59 am
Newsgroups: gnu.emacs.help
From: Doug Lewan <do...@shubertticketing.com>
Date: Wed, 10 Oct 2012 13:59:38 +0000
Local: Wed, Oct 10 2012 9:59 am
Subject: RE: reading a variable from the user
Drain,

Are you looking for a command or a function?

If you're looking for a command:
Francesco Mazzoli suggested `(interactive "v...")' for a command, and Tassilo Horn suggested using the help system: `C-h v <variable-name> RET'. There's also `M-x apropos', which will match regular expressions.
All of those make sense if this is for *your* consumption.

If you are looking for a function:
I don't know of any such function right off. You might want to learn about `obarray' and `(mapatoms)'.

I hope this helps.

,Doug


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Drew Adams  
View profile  
 More options Oct 10 2012, 10:14 am
Newsgroups: gnu.emacs.help
From: "Drew Adams" <drew.ad...@oracle.com>
Date: Wed, 10 Oct 2012 07:13:36 -0700
Local: Wed, Oct 10 2012 10:13 am
Subject: RE: reading a variable from the user

> Is there a function that prompts the user in the mini-buffer,
> matches the string input with a local variable name, and then
> returns the variable?

Not sure what you need.  There is function `read-variable'.
That works only for user options, in spite of the misleading name.

See also function `read-any-variable' in library `strings.el':

(defun read-any-variable (prompt &optional default-value)
  "Read name of a variable and return it as a symbol.
Unlike `read-variable', which reads only user options, this reads the
name of any variable.

Prompts with arg string PROMPT.  By default, return DEFAULT-VALUE if
non-nil.  If DEFAULT-VALUE is nil and the nearest symbol to the cursor
is a variable, then return that by default."
  (let ((symb (cond ((fboundp 'symbol-nearest-point)
                     (symbol-nearest-point))
                    ((fboundp 'symbol-at-point)
                     (symbol-at-point))
                    (t nil)))
        (enable-recursive-minibuffers t))
    (when (and default-value (symbolp default-value))
      (setq default-value (symbol-name default-value)))
    (intern (completing-read
               prompt obarray 'boundp t nil
               'minibuffer-history
               (or default-value
                   (and (boundp symb) (symbol-name symb)))
               t))))

http://www.emacswiki.org/emacs-en/download/strings.el

If you want functions like `symbol-nearest-point' then get
http://www.emacswiki.org/emacs-en/download/thingatpt%2b.el

There is also function `read-var-and-value' in library `simple+.el'.  It does
this:
"Read a variable name and value.
READ-VAR-FN is a function to read the variable name.
SET-VAR-HIST-VAR is a variable holding a history of variable values.
MAKE-LOCAL-P non-nil means the variable is to be local.
Optional arg BUFFER is the buffer used to determine the current value
of the variable, which is used as the default value when reading the new value."
http://www.emacswiki.org/emacs-en/download/simple%2b.el


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
drain  
View profile  
 More options Oct 10 2012, 9:09 pm
Newsgroups: gnu.emacs.help
From: drain <aeus...@gmail.com>
Date: Wed, 10 Oct 2012 18:09:50 -0700 (PDT)
Local: Wed, Oct 10 2012 9:09 pm
Subject: RE: reading a variable from the user
strings.el and simple+.el are new to me: thanks. They may contain the answer,
and I need to pick through them carefully, but I'll just be forthright about
what I am trying to do. Very new to Emacs Lisp...

I want to prompt myself with "To:", enter a contact name and a topic, then
pass them as arguments to compose-mail.

This was no problem, but the goal right now is to cut out the redundant
conditional statement, and instead match the name string I enter to its
variable directly, for example "William" to the William variable. Might
require pointers or arrays of some sort, but I haven't gotten that far in
the Emacs Lisp Intro.

Here's what I have:

(defun custom-compose-mail (Contact Topic)
  (interactive "sTo: \nsTopic: ")
  (setq William "x...@xxxxxxxxxxx.org"
        David "xxxxxxxx...@gmail.com"
        Jason "xxxxxxx...@gmail.com"
        Carl "xxx...@gmail.com")
  (cond ((equal Contact "William") (setq Contact William))
        ((equal Contact "David") (setq Contact David))
        ((equal Contact "Jason") (setq Contact Jason))
        ((equal Contact "Carl") (setq Contact Carl)))
  (compose-mail Contact Topic)
  (end-of-buffer)
  (newline))

--
View this message in context: http://emacs.1067599.n5.nabble.com/reading-a-variable-from-the-user-t...
Sent from the Emacs - Help mailing list archive at Nabble.com.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Abrahamsen  
View profile  
 More options Oct 10 2012, 11:28 pm
Newsgroups: gnu.emacs.help
From: Eric Abrahamsen <e...@ericabrahamsen.net>
Date: Thu, 11 Oct 2012 11:27:41 +0800
Local: Wed, Oct 10 2012 11:27 pm
Subject: Re: reading a variable from the user

On Thu, Oct 11 2012, drain wrote:
> strings.el and simple+.el are new to me: thanks. They may contain the answer,
> and I need to pick through them carefully, but I'll just be forthright about
> what I am trying to do. Very new to Emacs Lisp...

> I want to prompt myself with "To:", enter a contact name and a topic, then
> pass them as arguments to compose-mail.

> This was no problem, but the goal right now is to cut out the redundant
> conditional statement, and instead match the name string I enter to its
> variable directly, for example "William" to the William variable. Might
> require pointers or arrays of some sort, but I haven't gotten that far in
> the Emacs Lisp Intro.

There are many, many ways to do this obviously (hash tables, BBDB, etc),
but for the purposes of learning elisp it might be best to start with
some kind of association list (alist, section 5.8 of the Elisp manual).
That would look like this:

(setq names '((william "x...@xxxxxxxxxxx.org")
              (david "xxxxxxxx...@gmail.com")
              (carl "xxxxxxx...@gmail.com")))

or like this:

(setq names '((william . "x...@xxxxxxxxxxx.org")
              (david . "xxxxxxxx...@gmail.com")
              (carl . "xxxxxxx...@gmail.com")))

The difference, as far as I know, is that in the first method you can
have multiple values per list (so something like (william "William"
"White" "x...@xxxxxx.org")), whereas the dotted cons cell notation (the
second one) only allows two atoms.

If you look at the association list section of the manual, you'll see a
bunch of functions for working with lists like these. The main one is
`assoc':

(assoc 'william names) -> (william "sdfsdf@sdfsdf")

(second (assoc 'william names)) -> "sdfsdf@sdfsdf"

It's generally better to use a `let' instead of a `setq' to make
temporary variables in your functions. Here I've used let*, which is
only different in that it evaluates the statements one by one, so later
statements can refer to values established in earlier statements.

As far as I can tell you can't use symbols in the assoc list set up by
`let' (is this wrong?). So your function might look like:

(defun custom-compose-mail (contact topic)
  (interactive "sTo: \nsTopic: ")
  (let* ((names '(("William" "x...@xxxxxxxxxxx.org")
                  ("David" "xxxxxxxx...@gmail.com")
                  ("Jason" "xxxxxxx...@gmail.com")
                  ("Carl" "xxx...@gmail.com")))
         (contact (second (assoc contact names))))
    (compose-mail contact topic)
    (end-of-buffer)
    (newline)))

The next thing to do, for the sake of usability, would be to choose a
name using `completing-read', so that you could type a few letters and
use TAB to complete.

Hope that's useful,

Eric

--
GNU Emacs 24.2.50.1 (i686-pc-linux-gnu, GTK+ Version 3.4.4)
 of 2012-10-10 on pellet


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
PJ Weisberg  
View profile  
 More options Oct 11 2012, 2:09 am
Newsgroups: gnu.emacs.help
From: PJ Weisberg <pjweisb...@gmail.com>
Date: Wed, 10 Oct 2012 23:08:49 -0700
Local: Thurs, Oct 11 2012 2:08 am
Subject: Re: reading a variable from the user

On Wednesday, October 10, 2012, Eric Abrahamsen <e...@ericabrahamsen.net>
wrote:

> The difference, as far as I know, is that in the first method you can
> have multiple values per list (so something like (william "William"
> "White" "x...@xxxxxx.org")), whereas the dotted cons cell notation (the
> second one) only allows two atoms.

FYI, '(william "William" "White" "x...@xxxxxx.org") is exactly the same as
'(william . ("William" "White" "x...@xxxxxx.org"))

For that matter it's the same as '(william . ("William" . ("White" . ("
x...@xxxxxx.org" . nil)))).  A list is just a chain of cons cells.

--
-PJ

Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
drain  
View profile  
 More options Oct 11 2012, 2:16 am
Newsgroups: gnu.emacs.help
From: drain <aeus...@gmail.com>
Date: Wed, 10 Oct 2012 23:16:16 -0700 (PDT)
Local: Thurs, Oct 11 2012 2:16 am
Subject: Re: reading a variable from the user
Exactly what I was looking for. And it is very useful -- indeed more
important -- that you directed me to the relevant concepts behind this
function.

. . .

Somewhat related, does anyone know how to customize the draft / reply
buffers to display only these fields, much the way the *messages* buffer is
customized with the following code:

(setq mime-view-mailcap-files '("~/Emacs/Wanderlust/mailcap")

      wl-message-ignored-field-list '("^.*:")
      wl-message-visible-field-list
      '("^To:"
    "^Cc:"
    "^From:"
    "^Subject:")

      wl-message-sort-field-list
      '("^From"
        "^Subject"
        "^To"
        "^Cc"))

Might be too Wanderlust-specific for the Emacs list, but wl-en has yet to
respond.

--
View this message in context: http://emacs.1067599.n5.nabble.com/reading-a-variable-from-the-user-t...
Sent from the Emacs - Help mailing list archive at Nabble.com.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Abrahamsen  
View profile  
 More options Oct 11 2012, 2:50 am
Newsgroups: gnu.emacs.help
From: Eric Abrahamsen <e...@ericabrahamsen.net>
Date: Thu, 11 Oct 2012 14:50:19 +0800
Local: Thurs, Oct 11 2012 2:50 am
Subject: Re: reading a variable from the user

On Thu, Oct 11 2012, PJ Weisberg wrote:
> On Wednesday, October 10, 2012, Eric Abrahamsen <
> e...@ericabrahamsen.net> wrote:
>> The difference, as far as I know, is that in the first method you
> can
>> have multiple values per list (so something like (william "William"
>> "White" "x...@xxxxxx.org")), whereas the dotted cons cell notation
> (the
>> second one) only allows two atoms.

> FYI, '(william "William" "White" "x...@xxxxxx.org") is exactly the same
> as '(william . ("William" "White" "x...@xxxxxx.org"))

> For that matter it's the same as '(william . ("William" . ("White" .
> ("x...@xxxxxx.org" . nil)))).  A list is just a chain of cons cells.

Ugh, of course! If I'd thought about it for two more seconds that would
have been obvious -- that's the whole building block of lists! I wonder
if there's much practical difference between alists made of lists vs
those made of cons cells...

--
GNU Emacs 24.2.50.1 (i686-pc-linux-gnu, GTK+ Version 3.4.4)
 of 2012-10-10 on pellet


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »