8

i enable hl-mode in global scope with the following code.

(global-hl-line-mode t) 

to turn off hl-line feature in a specified mode. i do it with the following code.

(add-hook 'org-mode-hook (lambda () (global-hl-line-mode 0)))

but it turns off the hl-line feature for global scope.

how to disable hl-line feature in a specified mode?

1

3 Answers 3

14

There is often information and documentation in the Commentary section in the source file.

[...]
;; You could make variable `global-hl-line-mode' buffer-local and set
;; it to nil to avoid highlighting specific buffers, when the global
;; mode is used.
[...]

Thus, you can put something like this in your .emacs.

(global-hl-line-mode)
(make-variable-buffer-local 'global-hl-line-mode)
(add-hook 'some-mode-hook (lambda () (setq global-hl-line-mode nil)))
...
2
  • This is not working for me. I tried the following: (add-hook 'term-mode-hook (lambda () (setq global-hl-line-mode nil))). I am trying to turn off the hi-line feature when I am in ansi-term mode. Any suggestions?
    – modulitos
    Jun 30, 2014 at 10:28
  • Perhaps setq-local instead of make-variable-buffer-local? Mar 29, 2016 at 18:02
1

use hl-line-mode insted of global-hl-line-mode.

EDIT: You're right. This doesn't work.

The commentary says that the global-mode isn't meant to be used. I take it to mean that you can't selectively disable it once enabled.

I enable the hl-line-mode in major-mode hooks where I need it.

1
  • i already try that way. but "(hl-line-mode 0)" can not turn off hl-line that turn on by "(global-hl-line-mode t)"
    – luozengbin
    Apr 3, 2012 at 10:14
0

write the following line in your dotEmacs file, and use f5 to toggle the hl-line-mode

(global-set-key [f5] 'hl-line-mode)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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