Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

evaluate expression before it is put in lambda

Tags:

emacs

lisp

elisp

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.

like image 260
EvgeniySharapov Avatar asked Jul 16 '10 14:07

EvgeniySharapov


1 Answers

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")))))
like image 133
Trey Jackson Avatar answered Sep 20 '22 12:09

Trey Jackson