How to enable hl-line-mode for dired?

时间:2015-06-25 18:42:53

标签: emacs elisp

I'm trying to enable hl-line-mode just for dired-mode, but its not working. Enabling global-hl-mode works but It's every buffer not just one which I don't want. (defun hl-mode-for-dired () (setq hl-line-mode 1) ) (add-hook 'dired-mode-hook 'hl-mode-for-dired) I get this error output in my emacs log if I try to execute the the elisp. Another question is why is the error output garbled like that? hl-mode-for-dired diredp-nb-marked-in-mode-name #[nil "ÁÀ!ÂÃÄ!Ä " [font-lock-defaults make-local-variable (... t nil nil beginning-of-line) fboundp font-lock-refresh-defaults] 2] #[nil "ÆÇ\" È=ÉÇÊ#ÆË\"$ È=*ÉËÌ#)ÍÎÏÐÑ!QAA²AA² AA²ÉÒ Ó\"Ô#ÉÒÓ\"Õ#ÉÒÓ \"Ö#," [dired-mode-map now bdjc bdj sep map lookup-key "J" undefined define-key bmkp-dired-jump " " ...] 6] #[nil "ÁÀ!Â" [bookmark-make-record-function make-local-variable bmkp-make-dired-record] 2] dired-extra-startup)

1 个答案:

答案 0 :(得分:4)

这就是你所需要的:

(add-hook 'dired-after-readin-hook 'hl-line-mode)

hl-line-mode是一个本地挂钩。 global-hl-line-mode是一个全局挂钩。您只希望它用于Dired缓冲区,这意味着您需要hl-line-mode

哦,用它来关掉它:

(remove-hook 'dired-after-readin-hook 'hl-line-mode)