6

I have the following piece of code in my .emacs:

(dolist (mode '(scheme emacs-lisp lisp clojure))
  (add-hook
   (intern (concat (symbol-name mode) "-mode-hook"))
   (lambda ()
     (progn
        (run-programming-hook)
        (message "%s" (concat (symbol-name mode) "-mode")))

Obviously the mode variable is void when lambda gets to execute. The question is how I evaluate mode in such a way that it doesn't get into a lambda as a variable but rather as a value in that variable? In other words, I want the message to be printed when the hook is run.

1
  • 1
    Just a quick note: your "obviously ... is void" is wrong -- it should not be this way, and Emacs Lisp is one of very few languages where this still happens. It's called dynamic scope. Related to this, look for the lexical-let form in Emacs, which is a hack that emulates the saner behavior that would work. Commented Jul 17, 2010 at 22:21

1 Answer 1

11

What you can use is backquote:

(dolist (mode '(scheme emacs-lisp lisp clojure))
  (add-hook
   (intern (concat (symbol-name mode) "-mode-hook"))
   `(lambda ()
       (run-programming-hook)
       (message "%s" ,(concat (symbol-name mode) "-mode")))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.