Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable line numbers but allow them in prog-mode and text-mode

I would like to disable the line numbers in Emacs because having them in Org-mode, terminal, mu4e, elfeed, etc.. looks ugly.

So I removed this:

(global-display-line-numbers-mode t)

Now I'm wondering if it's possible to enable the line numbers only for prog-mode and eventually plain text files (but not Org), I think that's text-mode.

Any suggestion is appreciated.

  (dolist (mode '(text-mode-hook
                  prog-mode-hook
                  conf-mode-hook))
    (add-hook mode (lambda () (display-line-numbers-mode 1))))
like image 849
Zoltan King Avatar asked Nov 16 '25 12:11

Zoltan King


1 Answers

you need to just enable them for corresponding modes using hooks. The hook need to call display-line-numbers-mode with 1 as argument to enable this mode. I personally prefer to put code for the hook into a separate function, that could be redefined at any point of time if necessary, something like this (this hook will be called when entering file with most of programming modes):

(defun my-display-numbers-hook ()
  (display-line-numbers-mode 1)
  )
(add-hook 'prog-mode-hook 'my-display-numbers-hook)

Similarly you can do it for text-mode - it will enable for all text-mode-based files:

(add-hook 'text-mode-hook 'my-display-numbers-hook)
like image 63
Alex Ott Avatar answered Nov 18 '25 21:11

Alex Ott