3

Is there a way to set the background color of the line numbering to the same color of the line highlighting background color?

So far I have to put the line numbering background color manually and of course that works really bad when I change my color theme. The code is:

    (custom-set-faces
      '(linum ((t (:inherit (shadow default) :background "#073642" :foreground "#586e75")))))

The idea is to get something like this from my old Vim setup that works consistently across different color themes in Emacs: vim setup

4
  • Are you using hl-line-mode and linum-mode, and asking whether the current line can match the background color used by hl-line-mode? And are you also asking that this be programmatically so smart that it automatically adjusts as you switch between the various themes that may also set faces that are different for both of the above-mentioned minor-modes? phils wrote up a solution a few years ago that highlights the current line in linum-mode: stackoverflow.com/a/10593165/2112489 In terms of the second question, it doesn't sound like that is easily accomplished.
    – lawlist
    Commented Dec 7, 2015 at 18:29
  • The thing is, hl-line get's the background value automatically from something in the color theme configuration. Something that fits nicely with the rest of the theme. So, what I'm trying to figure out is what is the name of that variable and how to apply that to the line number column.
    – jbssm
    Commented Dec 7, 2015 at 18:46
  • 1
    M-x find-library RET hl-line RET -- it is only 270 lines and the face hl-line-face is the sixth definition down from the top. See also hl-line face (fifth from the top). The default is the highlight face.
    – lawlist
    Commented Dec 7, 2015 at 18:53
  • Ok, I've figured it out. I still can't understand where hl-line is getting the color, but I've managed the rest of it. Thank you!
    – jbssm
    Commented Dec 7, 2015 at 19:32

1 Answer 1

1

After some answers I got it. The answers in other threads didn't work right away in Spacemacs (I'm really new to Emacs world so I don't know why), but mixing parts of them I managed to do it.

It's still not perfect. I would prefer to get the color from Emacs theme instead of using the color that hl-line figures out it should use, but I don't understand how to do it.

Thank you all for your help!

(defun dotspacemacs/user-config ()

  (global-linum-mode t)
  (unless window-system
    (add-hook 'linum-before-numbering-hook
              (lambda ()
                (setq-local linum-format-fmt
                            (let ((w (length (number-to-string
                                              (count-lines (point-min) (point-max))))))
                              (concat "%" (number-to-string w) "d"))))))

  (defface my-linum-hl
    `((t :inherit linum :background ,(face-background 'hl-line nil t)))
    "Face for the current line number."
    :group 'linum)

  (defun my-linum-format-func (line)
    (concat
     ;; (propertize (format linum-format-fmt line) 'face 'linum)
     (propertize (format linum-format-fmt line) 'face 'my-linum-hl)
     (propertize " " 'face 'mode-line)))

  (unless window-system
      (setq linum-format 'my-linum-format-func)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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