* Monitoring variable changes
@ 2006-10-07 4:08 spamfilteraccount
2006-10-10 6:09 ` spamfilteraccount
0 siblings, 1 reply; 2+ messages in thread
From: spamfilteraccount @ 2006-10-07 4:08 UTC (permalink / raw)
I have a user option for my package which is a list of strings. I use
this list very frequently in my code and since speed is an issue I want
to do some preprocessing on it.
The problem is the user can change the option anytime (even via setq)
and I need to ensure the preprocessed value always reflects the actual
contents of the user option.
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?
Some hook maybe which can be set to be called when a variable is
changed regardless of how it is set?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Monitoring variable changes
2006-10-07 4:08 Monitoring variable changes spamfilteraccount
@ 2006-10-10 6:09 ` spamfilteraccount
0 siblings, 0 replies; 2+ messages in thread
From: spamfilteraccount @ 2006-10-10 6:09 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-10-10 6:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-07 4:08 Monitoring variable changes spamfilteraccount
2006-10-10 6:09 ` spamfilteraccount
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).