all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'drain'" <aeuster@gmail.com>, <Help-gnu-emacs@gnu.org>
Subject: RE: reading a variable from the user
Date: Wed, 10 Oct 2012 07:13:36 -0700	[thread overview]
Message-ID: <D9C9B9320D2549D0B24BB987C90DC002@us.oracle.com> (raw)
In-Reply-To: <1349853875855-266778.post@n5.nabble.com>

> 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





  parent reply	other threads:[~2012-10-10 14:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-10  7:24 reading a variable from the user drain
2012-10-10  9:08 ` Francesco Mazzoli
2012-10-10  9:16   ` Tassilo Horn
2012-10-10  9:22     ` horse_rivers
2012-10-10 13:59 ` Doug Lewan
2012-10-10 14:13 ` Drew Adams [this message]
2012-10-11  1:09   ` drain
2012-10-11  3:27     ` Eric Abrahamsen
2012-10-11  6:08       ` PJ Weisberg
2012-10-11  6:50         ` Eric Abrahamsen
2012-10-11  6:16       ` drain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D9C9B9320D2549D0B24BB987C90DC002@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=Help-gnu-emacs@gnu.org \
    --cc=aeuster@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.