rendered paste body(defun kf-find-variable-by-value (val)
"Return a list of variables (as symbols) whose value matches VAL.
VAL can be a number, a regexp, or symbol, to match a number, string,
or function value, respectively."
(let (matches)
(cond
((stringp val)
(mapcar (lambda (sym)
(if (boundp sym)
(let ((this-val (symbol-value sym)))
(and
(stringp this-val)
(string-match val this-val)
(setq matches (cons sym matches))))))
obarray))
((numberp val)
(mapcar (lambda (sym)
(if (boundp this-val)
(let ((this-val (symbol-value sym)))
(and (numberp this-val)
(equal val this-val)
(setq matches (cons sym matches))))))
obarray))
((symbolp val)
(mapcar (lambda (sym)
(if (fboundp this-val)
(let ((this-fun (symbol-function sym)))
(and (eq val this-fun)
(setq matches (cons sym matches))))))
obarray)))
matches))