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?

2 Answers 2


Does 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.

Icicles command 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 nil (S-TAB shows matches):

M-x icicle-apropos-value RET


To see all variables whose current value matches regexp .*plist:

SYMBOL C-M-j VALUE: C-M-j .*plist S-TAB

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 *Completions*.

You can get a full (i.e., C-h v) description of the current candidate by using a help key on it: C-M-mouse-2 or C-M-RET. To see help on each candidate in turn, cycle using arrow keys with C-M- (e.g., repeat C-M-<down>).

See Value-Aware Variable-Apropos Multi-Commands.

C-h f icicle-apropos-value says this:

icicle-apropos-value is an interactive compiled Lisp function in icicles-cmd1.el.

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 icicle-list-join-string ("^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

  • plain (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)

See also:

  • icicle-apropos-vars-w-val-satisfying, icicle-describe-vars-w-val-satisfying - values satisfy a predicate
  • icicle-plist - similar to this command with positive prefix arg
  • icicle-vardoc, icicle-fundoc, icicle-doc - match name & doc
  • icicle-apropos-options-of-type, 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 M-i M-#.
  • Icicles incremental completion. You can cycle this using M-i #.

Read input, then call icicle-doc-action to act on it.

Input-candidate completion and cycling are available. While cycling, these keys with prefix C- are active:

C-mouse-2, C-return - Act on current completion candidate only C-down, C-wheel-down - Move to next completion candidate and act C-up, 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-flag determines which occurs first.

With prefix C-M- instead of C-, the same keys (C-M-mouse-2, C-M-RET, C-M-down, and so on) provide help about candidates.

Use mouse-2, RET, or S-RET to finally choose a candidate, or C-g to quit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.