Separate linum-relative mods into a real fork. See the URL in commit.

This commit is contained in:
MitchMarq42 2022-10-11 10:45:16 -08:00
parent 5531d5f0c0
commit eae0d246e6

View File

@ -283,50 +283,14 @@ targets."
;; SORTA WORKING: Relative line numbers with stuff ;; SORTA WORKING: Relative line numbers with stuff
(use-package linum-relative (use-package linum-relative
:straight (:type git
:host "https://git.mitchmarq42.xyz/mitch/linum-relative-justify.el")
:diminish :diminish
:custom (linum-relative-current-symbol "")
:init :init
(require 'cl-lib) (require 'cl-lib)
(require 'linum-relative) (require 'linum-relative)
(setq linum-relative-current-symbol "")
(defun display-line-numbers-equalize ()
"Equalize The width. Taken from https://emacs.stackexchange.com/questions/55165/uneven-line-numbers-with-display-line-numbers/55166#55166"
(setq display-line-numbers-width
(1+ (length (number-to-string (line-number-at-pos (point-max)))))))
(add-hook 'prog-mode-hook #'display-line-numbers-equalize) (add-hook 'prog-mode-hook #'display-line-numbers-equalize)
(defun mitch/symbol-width (symbol)
(+ 1 (floor (log symbol 10))))
(defun mitch/linum-get-left-pad (symbol)
"Get the number of spaces to add before the current relative line number."
(let* ((symbol-width (mitch/symbol-width symbol)))
(- display-line-numbers-width symbol-width)))
(defun mitch/right-pad (line-number)
"Pad the line number to the right."
(let* ((spacing (- (display-line-numbers-equalize)
(mitch/symbol-width line-number)))
(spacer (make-string spacing (string-to-char " "))))
(format (concat "%s" spacer) line-number)))
(defun mitch/left-pad (line-number)
"Pad the line number to the left."
(let ((spacing
(make-string (mitch/linum-get-left-pad line-number)
(string-to-char " "))))
(format (concat spacing "%s") line-number)))
(defun linum-relative (line-number)
(let* ((diff1 (abs (- line-number linum-relative-last-pos)))
(diff (if (cl-minusp diff1)
diff1
(+ diff1 linum-relative-plusp-offset)))
(current-p (= diff linum-relative-plusp-offset))
(current-symbol (if (and linum-relative-current-symbol current-p)
(if (string= "" linum-relative-current-symbol)
(mitch/right-pad line-number)
linum-relative-current-symbol)
(mitch/left-pad diff)))
(face (if current-p 'linum-relative-current-face 'linum)))
(propertize (format linum-relative-format current-symbol) 'face face)))
;; (linum-relative-global-mode 1)
;; (mitch/linum-rel-setup)
;; (linum-relative 282)
(add-hook 'prog-mode-hook #'linum-relative-mode) (add-hook 'prog-mode-hook #'linum-relative-mode)
(add-hook 'minibuffer-exit-hook #'linum-relative-on) (add-hook 'minibuffer-exit-hook #'linum-relative-on)
:custom :custom