I know there are some other questions like this on the site, but none of them seem to work.

I am trying to enable relative line numbers with a package, and when I do M-x eval-buffer, the mode is enabled, but when I just launch emacs it does not get enabled. I checked and made sure that the location of init.el is the one that emacs is using, and I know that it is at least partially working because I can install packages in it and use them through M-x.

Here is my init.el

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  (add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/"))
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
 '(package-selected-packages (quote (linum-relative markdown-mode))))
(setq linum-relative-backend 'display-line-numbers-mode)

Specifically, (linum-relative-mode) doesn't work when launching emacs.

To recreate, set the file above as your init.el / .emacs file and launch emacs. Notice that there are no relative line numbers. Now run M-x eval-buffer and see that it adds the buffer just fine. My question is why launching emacs is not evaluating the .emacs file as it should?

  • 2
    Please don't just post your init file. Narrow it down, removing everything that's just noise - unnecessary to show/reproduce the problem you want to ask about. And please provide a step-by-step recipe to reproduce the problem. Thx. – Drew Jan 8 at 18:31
  • Edited as best as I could, thanks. – J Vossen Jan 8 at 18:35
  • Native relative line numbers are built-in to Emacs 26+, with no additional packages needed. – lawlist Jan 8 at 19:01
  • Thanks for narrowing it down. – Drew Jan 9 at 2:09

linum-relative-mode will be a buffer-local mode, just like linum-mode. Hence when you evaluate the code, it activates for the current buffer (only).

Regular linum provides a global mode global-linum-mode, so try global-linum-relative-mode ?

or, as lawlist points out, if you are on Emacs 26+ then you should definitely use global-display-line-numbers-mode instead (and see M-x customize-group RET display-line-numbers for options).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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