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?

Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
luozengbin
  • 305
  • 2
  • 11
  • possible duplicate of [automatically disable a global minor mode for a specific major mode](http://stackoverflow.com/questions/6837511/automatically-disable-a-global-minor-mode-for-a-specific-major-mode) – phils Apr 03 '12 at 10:22

3 Answers3

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)))
...
Daimrod
  • 4,902
  • 23
  • 25
  • 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 '14 at 10:28
  • Perhaps `setq-local` instead of `make-variable-buffer-local`? – Vladimir Panteleev Mar 29 '16 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.

event_jr
  • 17,467
  • 4
  • 47
  • 62
  • 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 03 '12 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)

Qian
  • 1,007
  • 7
  • 6