help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Monitoring variable changes


From: spamfilteraccount
Subject: Re: Monitoring variable changes
Date: 9 Oct 2006 23:09:44 -0700
User-agent: G2/1.0

spamfilteraccount@gmail.com wrote:
>
> Is there a better way to do this than saving the previous value of the
> user option and comparing it to the current value every time before I
> try to use the preprocessed value?

The best solution I could come up with was creating a wrapper function
which ensures the cached value is always up-to-date. It does the some
kind of preprocessing for different variables.  I copy it here for
reference:


(defun get-cached-value (sourcevar)
  "Return cached value for the given source variable SOURCEVAR."
  (let ((cachevar (intern (concat (symbol-name sourcevar) "-cache")))
        (prevvar (intern (concat (symbol-name sourcevar) "-prev"))))
    (unless (and (boundp cachevar)
                 (eq (eval prevvar) (eval sourcevar)))
      (set cachevar
           ;; do some caching/preprocessing here
           ...)
      (set prevvar (eval sourcevar)))
    (eval cachevar)))


Invocation: (get-cached-value 'varname)



reply via email to

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