I'd like to find which variables contain a certain value.
Is there a way to do a regex search through the values of every variable in Emacs?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
apropos-value do what you're looking for?
(apropos-value PATTERN &optional DO-ALL) Show all symbols whose value’s printed representation matches PATTERN. PATTERN can be a word, a list of words (separated by spaces), or a regexp (using some regexp special characters). If it is a word, search for matches for that word as a substring. If it is a list of words, search for matches for any two (or more) of those words.
icicle-apropos-value enhances vanilla command
apropos-value, by letting you simultaneously match the variable name and value against regexps (or substrings or other patterns). You need not match them both, but you can match them both.
And (as with all Icicles completion) you can match the name or the value or both progressively, that is, using multiple patterns incrementally. This is particularly important for a case where, as you say, you are matching against all variables in Emacs, to start with. That is, you do not care to match against names; you just want to match values.
To match both name and value just use
C-M-j to end the name pattern and begin the value pattern. So to match only values, you start with
C-M-j and then type the value pattern, as the name pattern is empty.
For example, to see all variables whose current value matches
S-TAB shows matches):
M-x icicle-apropos-value RET
SYMBOL C-M-j VALUE:
To see all variables whose current value matches regexp
SYMBOL C-M-j VALUE:
Matching variables and their values are shown in buffer
*Completions*, as completion candidates. You can cycle among the candidates, making each one current in turn, using the vertical-arrow keys:
<down> <down> <down>....
The first doc-string line for the current completion candidate is shown in the mode-line of
You can get a full (i.e.,
C-h v) description of the current candidate by using a help key on it:
C-M-RET. To see help on each candidate in turn, cycle using arrow keys with
C-M- (e.g., repeat
C-h f icicle-apropos-value says this:
icicle-apropos-valueis an interactive compiled Lisp function in
It is bound to
menu-bar help-menu apropos icicles icicle-apropos-value,
menu-bar help-menu apropos apropos-var-value,
menu-bar help-menu search-documentation find-option-by-value.
Choose a variable, function, or other symbol description.
This is similar to vanilla command
apropos-value, but you can match against the variable name and its printed value at the same time.
By default, each completion candidate is multi-completion composed of a variable name plus its value. They are separated by
"^G^J", by default).
With a prefix arg, candidates are different kinds of symbols:
- < 0: functions and their defs (but byte-compiled defs are skipped)
- > 0: symbols and their plists
= 0: variables and their values, functions and their definitions, and other symbols and their plists
C-u): use the last-computed (cached) set of candidates
You can use
C-$during completion to toggle filtering the domain of initial candidates according to the prefix argument, as follows:
- none: only user options (+ values)
- < 0: only commands (+ definitions)
- > 0: only faces (+ plists)
- = 0: only options (+ values), commands (+ defs), faces (+ plists)
icicle-describe-vars-w-val-satisfying- values satisfy a predicate
icicle-plist- similar to this command with positive prefix arg
icicle-doc- match name & doc
icicle-describe-option-of-type- match name & defcustom type
Because you will often use this command in contexts that result in many, many completion candidates, the following are turned off by default for this command:
- Icomplete mode. You can toggle this using
- Icicles incremental completion. You can cycle this using
Read input, then call
icicle-doc-actionto act on it.
Input-candidate completion and cycling are available. While cycling, these keys with prefix
C-return- Act on current completion candidate only
C-wheel-down- Move to next completion candidate and act
C-wheel-up- Move to previous completion candidate and act
C-next- Move to next apropos-completion candidate and act
C-prior- Move to previous apropos-completion candidate and act
C-end- Move to next prefix-completion candidate and act
C-home- Move to previous prefix-completion candidate and act
C-!- Act on all candidates, successively (careful!)
When candidate action and cycling are combined (e.g.
C-next), user option
icicle-act-before-cycle-flagdetermines which occurs first.
C-, the same keys (
C-M-down, and so on) provide help about candidates.
S-RETto finally choose a candidate, or