11

I have global-hl-line-mode setup in my init file:

(use-package hl-line
  :init (global-hl-line-mode 1))

Is it possible to disable it when I am in eshell and ansi-term? I tried adding a hook like this:

(add-hook 'eshell-mode-hook (hl-line-mode -1))

But it didn't work.

Drew
  • 75,699
  • 9
  • 109
  • 225
Manuel Uberti
  • 3,150
  • 18
  • 36

2 Answers2

11

global-hl-line-mode sets variable global-hl-line-mode to t. The global mode is separate from the non-global (hl-line-mode).

The following will disable it in the selected mode:

(add-hook 'eshell-mode-hook (lambda ()
                                    (setq-local global-hl-line-mode
                                                nil)))
(add-hook 'term-mode-hook (lambda ()
                                    (setq-local global-hl-line-mode
                                                nil)))

The documentation indicates that setting it directly does not take effect, however when testing it it does remove the highlighting while in the *Eshell* buffer.

Jonathan Leech-Pepin
  • 4,307
  • 1
  • 19
  • 32
3

This works for ansi-term if you're using emacs 24.3+:

(add-hook 'term-mode-hook (lambda ()
                            (setq-local global-hl-line-mode
                                        nil)))

Thanks to Jonathan and glucas.

erikstokes
  • 12,686
  • 2
  • 34
  • 56
Manuel Uberti
  • 3,150
  • 18
  • 36