开发者

evaluate expression before it is put in lambda

开发者 https://www.devze.com 2023-01-08 03:31 出处:网络
I have the following piece of code in my .emacs: (dolist (mode \'(scheme emacs-lisp lisp clojure)) (add-hook

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
 开发者_如何学Python       (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.


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")))))
0

精彩评论

暂无评论...
验证码 换一张
取 消