From 2648f8384ff8710811b7d3dc104c9ded9d1eff8c Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Wed, 30 Nov 2022 12:27:13 -0900 Subject: [PATCH] Switch to nlinum from linum. Avoids `linum deprecated` message. --- lisp/mitch-packages.el | 46 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index 2a2ecab..d1d6156 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -307,23 +307,37 @@ targets." :after (embark consult)) ;; SORTA WORKING: Relative line numbers with stuff -;; (use-package nlinum-relative -;; :custom -;; (nlinum-format "%s ") -;; (nlinum-relative-redisplay-delay 0)) -(use-package linum-relative - :straight (:host nil - :type git - :repo - "https://git.mitchmarq42.xyz/mitch/linum-relative-justify.el") - :diminish - :custom (linum-relative-current-symbol "") +(use-package nlinum-relative + :custom + (nlinum-relative-redisplay-delay 0) + :hook (prog-mode . nlinum-relative-mode) :init - (require 'cl-lib) - (require 'linum-relative) - (add-hook 'prog-mode-hook #'display-line-numbers-equalize) - (add-hook 'prog-mode-hook #'linum-relative-mode) - (add-hook 'minibuffer-exit-hook #'linum-relative-on)) + (defun mitch/nlinum-buffer-setup () + (setq nlinum-format-function + (lambda (line width) + (let* ((line-display (abs (- line nlinum-relative--current-line))) + (is-current-line? (eq line-display 0)) + (line-display (if is-current-line? + nlinum-relative--current-line + (+ nlinum-relative-offset line-display))) + (numwidth (length (number-to-string line-display))) + (spaces (make-string (- width numwidth) ?\ )) + (nlinum-format (if is-current-line? + (format "%%d%s" spaces) + (format "%s%%d" spaces))) + (str (if (and (not (string-equal + nlinum-relative-current-symbol "")) + is-current-line?) + nlinum-relative-current-symbol + (format nlinum-format line-display)))) + (if is-current-line? + (put-text-property + 0 width 'face 'nlinum-relative-current-face str) + (put-text-property 0 width 'face 'linum str)) + str))) + (setq-local nlinum--width (length (number-to-string + (line-number-at-pos (point-max)))))) + (add-hook 'prog-mode-hook #'mitch/nlinum-buffer-setup)) ;; broken terminal that doesn't compile but at least it's fast when it does (use-package vterm