Reputation: 18572
I want to exclude modes that don't need show-trailing-whitespace
:
(set-default 'show-trailing-whitespace t)
(defmacro non-trailing-whitespaces-modes (mode)
(let ((hook (intern (concat (symbol-name mode) "-mode-hook"))))
`(add-hook ',hook (lambda () (setq show-trailing-whitespace nil)))))
(defvar trailing-whitespace-exclude-modes '(eshell term help diff ztree org calendar syslog slime-repl Info ielm))
(dolist (m trailing-whitespace-exclude-modes)
(non-trailing-whitespaces-modes m))
However, I cannot add hook using dolist
, but adding idividual call for each mode works, for example:
(non-trailing-whitespaces-modes eshell)
(non-trailing-whitespaces-modes term)
(non-trailing-whitespaces-modes ielm
What's wrong?
Upvotes: 0
Views: 231
Reputation: 20362
Simple:
(macroexpand '(non-trailing-whitespaces-modes m))
;; (add-hook (quote m-mode-hook)
;; (lambda nil (setq show-trailing-whitespace nil)))
Your task does not really require you to use macros. Turn your macro into a function and you're done.
Here's the equivalent defun that can be used in dolist
:
(defun non-trailing-whitespaces-modes (mode)
(let ((hook (intern (concat (symbol-name mode) "-mode-hook"))))
(add-hook hook (lambda () (setq show-trailing-whitespace nil)))))
Upvotes: 1