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

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

Re: Unreferenced symbols in closures, and a problem with closures in min


From: Kelly Dean
Subject: Re: Unreferenced symbols in closures, and a problem with closures in minor modes
Date: Tue, 28 May 2013 21:44:43 -0700 (PDT)

Stefan Monnier wrote:
[...]
> To add&remove functions from hooks, it's much better to make sure you
> actually pass the exact same object (not just one that should hopefully
> be `equal').

Thanks for the fast help and explanations. Per your suggestion I'm avoiding 
both the equality testing of functions and the unwanted lexical environment 
this way:
(defun bar-off () (bar 0))
(define-minor-mode bar "Bar" nil " Bar" nil
  (if bar (add-hook 'foo-hook 'bar-off nil t)
    (remove-hook 'foo-hook 'bar-off t)))

although I was tempted to do it this way just to spite the interpreter :-)
(setq bar-off (lambda () (bar 0)))
(define-minor-mode bar "Bar" nil " Bar" nil
  (if bar (add-hook 'foo-hook (symbol-value 'bar-off) nil t)
    (remove-hook 'foo-hook (symbol-value 'bar-off) t)))




reply via email to

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