I'm trying to disable hl-anything only when I'm using org-mode or org-agenda-mode but I don't know how to do it.

I have tried this:

(add-hook 'org-mode-hook
          (lambda ()
            (hl-highlight-mode nil)))

And this:

(add-hook 'org-agenda-mode-hook
          (lambda ()
            (hl-highlight-mode nil)))
  • I haven't tried this mode but passing in nil for some modes may turn the mode on; try passing in -1. – amitp Jul 23 '16 at 17:43

hl-highlight-mode is a global minor mode, and you can't disable a global minor mode on a per-buffer basis -- only buffer-local minor modes work that way. A global mode is either on or off globally.

Original answer about buffer-local minor modes follows...

The docstring at C-hf hl-highlight-mode should tell you exactly what its argument does, so just follow that information.

In recent versions of Emacs, modes defined by define-minor-mode are explicitly enabled when called from elisp with a nilargument.

This is to ensure consistent behaviour for the likes of (add-hook 'HOOK 'MINORMODEFUNCTION) -- which results in MINORMODEFUNCTION being called without its optional argument, which is the same thing as passing it an argument of nil.

i.e. your code:

(add-hook 'org-agenda-mode-hook
          (lambda ()
            (hl-highlight-mode nil)))

is equivalent to:

(add-hook 'org-agenda-mode-hook 'hl-highlight-mode)

Prior to that, a nil argument to a minor mode function would toggle the mode (just like calling the mode interactively); but that might be toggling it on or off depending on circumstances, so it wasn't a dependable thing to use in non-interactive cases.

In general a positive numeric argument enables a minor mode, and a non-positive (<= 0) argument disables it. In practice one mostly sees values of 0 or -1 used to disable modes. For modes defined by define-minor-mode there is no difference between those two values.


Note that if hl-highlight-mode were being enabled via a globalized minor mode, it's trickier, and you may need to use after-change-major-mode-hook:

(defun my-inhibit-globalized-hl-highlight-mode ()
  "Counter-act a globalized hl-highlight-mode."
  (add-hook 'after-change-major-mode-hook
            (lambda () (hl-highlight-mode 0))
            :append :local))

(add-hook 'org-agenda-mode-hook 'my-inhibit-globalized-hl-highlight-mode)

See also https://stackoverflow.com/q/6837511

  • Awesome answer @phils thank you! But it doesn't work here. When the minor mode is enable it does not disable it when I change to org-agenda-mode. – squiter Jul 25 '16 at 13:30
  • More information needed, then. For starters, what is hl-highlight-mode and where did you get it from? And how are you currently enabling it? – phils Jul 25 '16 at 13:43
  • Ok, I get it from ELPA. The repo is github.com/hl-anything/hl-anything-emacs and I'am enabling with M-x hl-highlight-mode because (hl-highlight-mode) or (hl-higlight-mode 1) doesn't work. – squiter Jul 25 '16 at 19:10
  • Answer updated. It's a global mode, so you can't do what you want to do. – phils Jul 26 '16 at 11:59
  • Thank you Phils. I didn't know about global minor modes... so.. thank you! :) – squiter Jul 26 '16 at 17:50

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.