0

I am trying to setup Emacs to have relative line numbering enabled by default via this plugin.

According to the readme file

Relative line numbering should already be enabled by default (by installing this package), following linum-on

I have included (linum-on) in my .emacs file but it doesn't work. M-x linum-relative-mode works, but I have to do it every time.

My full .emacs file at present is below:

(if (display-graphic-p)
    (progn
      (setq initial-frame-alist
            '((tool-bar-lines . 0)
              (width . 106)
              (height . 60)))
      (setq default-frame-alist
            '((tool-bar-lines . 0)
              (width . 106)
              (height . 60))))
  (progn
    (setq initial-frame-alist '((tool-bar-lines . 0)))
    (setq default-frame-alist '((tool-bar-lines . 0)))))
(setq package-list
      '(use-package evil helm js2-mode monokai-theme linum-relative org
        powerline rainbow-delimiters projectile helm-projectile flycheck))
(require 'package)
(setq package-archives '(("melpa"        . "http://melpa.org/packages/")
                         ("MELPA stable" . "https://stable.melpa.org/packages/")
                         ("gnu"          . "http://elpa.gnu.org/packages/")
                         ("marmalade"    . "http://marmalade-repo.org/packages/")))
(package-initialize)
(unless package-archive-contents (package-refresh-contents))
(dolist (package package-list)
  (unless (package-installed-p package) (package-install package))) 
(setq evil-want-C-u-scroll t)
(require 'evil)
(evil-mode 1)

;; Use `display-line-number-mode` as linum-mode's backend for smooth performance
(setq linum-relative-backend 'display-line-numbers-mode)
(require 'linum-relative)
(linum-on)
(require 'helm-config)
(set-face-attribute 'default nil :height 140)
(load-theme 'monokai t)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(require 'powerline)
(powerline-default-theme)
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
(linum-relative-mode)
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages
   (quote
    (flycheck rainbow-delimiters powerline linum-relative doom-themes moe-theme cyberpunk-theme monokai-theme helm evil))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
  • 1
    On a side note, if you're on Emacs 26, you should switch to display-line-numbers-mode. (It is a lot more efficient than linum-mode). (setq display-line-numbers-type 'relative) ;; Make relative line numbers appear for all programming buffers. (add-hook 'prog-mode-hook 'display-line-numbers-mode) – Edward Minnix Jun 15 '18 at 12:38
  • Rather than just dump your init file here, please consider paring it down to just the code that's essential to reproduce your problem. – Drew Jun 15 '18 at 16:22
  • @Drew noted; I'll bear that in mind for the future. – Ben Wainwright Jun 16 '18 at 9:49
1

linum-on acts on the current buffer only. That is not what you want in an init file.

You actually want the action of global-linum-mode which switches on linum-mode in all buffers where it is appropriate.

So replace (linum-on) with (global-linum-mode). You can also directly use

(linum-relative-global-mode)

instead.

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.