Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've derived this answer from my previous answer to <a href="https://stackoverflow.com/questions/6874516/relative-line-numbers-in-emacs/6928112#6928112">Relative Line Numbers In Emacs</a>, as it deals with the same issue of remembering the current line number during the linum format process.</p> <p>I'm inheriting from the <code>linum</code> face, but using the background colour from <code>hl-line</code>. If the foreground and background don't match nicely, you can assign a foreground colour explicitly with<br> <kbd>M-x</kbd> <code>customize-face</code> <kbd>RET</kbd> <code>my-linum-hl</code> <kbd>RET</kbd></p> <pre class="lang-el prettyprint-override"><code>(require 'hl-line) (defface my-linum-hl `((t :inherit linum :background ,(face-background 'hl-line nil t))) "Face for the current line number." :group 'linum) (defvar my-linum-format-string "%3d") (add-hook 'linum-before-numbering-hook 'my-linum-get-format-string) (defun my-linum-get-format-string () (let* ((width (1+ (length (number-to-string (count-lines (point-min) (point-max)))))) (format (concat "%" (number-to-string width) "d"))) (setq my-linum-format-string format))) (defvar my-linum-current-line-number 0) (setq linum-format 'my-linum-format) (defun my-linum-format (line-number) (propertize (format my-linum-format-string line-number) 'face (if (eq line-number my-linum-current-line-number) 'my-linum-hl 'linum))) (defadvice linum-update (around my-linum-update) (let ((my-linum-current-line-number (line-number-at-pos))) ad-do-it)) (ad-activate 'linum-update) </code></pre> <p>As with that other answer, this is more efficient in generating the dynamic width than the default <code>dynamic</code> format, but you can use a static width for maximum speed by commenting out the line <code>(add-hook linum-before-numbering-hook 'my-linum-get-format-string)</code> (and optionally modify the initial value of <code>my-linum-format-string</code> to set your preferred width).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload