All pastes #423187 Raw Edit

Something

public text v1 · immutable
·published 2007-04-03 23:22 UTC
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))