[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: reading a variable from the user

From: Drew Adams
Subject: RE: reading a variable from the user
Date: Wed, 10 Oct 2012 07:13:36 -0700

> 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)
                    ((fboundp '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
               (or default-value
                   (and (boundp symb) (symbol-name symb)))

If you want functions like `symbol-nearest-point' then get

There is also function `read-var-and-value' in library `simple+.el'.  It does
"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."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]