linum-relative works again

This commit is contained in:
MitchMarq42 2022-08-11 06:26:14 -08:00
parent 7cc736abfa
commit 55da62fbd6

View File

@ -235,54 +235,57 @@ targets."
:after (embark consult))
;; SORTA WORKING: Relative line numbers with stuff
; (use-package linum-relative
; :diminish
; :init
; (require 'cl-lib)
; (require 'linum-relative)
; (setq linum-relative-current-symbol "")
; (defun mitch/get-total-width ()
; "set up linum relative variables per buffer."
; (let ((total-lines (count-lines (point-min) (point-max))))
; (setq-local total-width (ceiling (log total-lines 10)))))
; ;; (defvar total-width 4)
; (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 line-number)))
; (- (mitch/get-total-width) symbol-width)))
; (defun mitch/right-pad (line-number)
; "Pad the line number to the right."
; (let* ((spacing (- (mitch/get-total-width) (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)
(use-package linum-relative
:diminish
:init
(require 'cl-lib)
(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)
(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 line-number)))
(- 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)
; :custom
; (linum-relative-current-symbol "")
; )
(setq display-line-numbers-mode 'relative)
(add-hook 'prog-mode-hook #'linum-relative-mode)
(add-hook 'minibuffer-exit-hook #'linum-relative-on)
:custom
(linum-relative-current-symbol "")
)
;; (setq display-line-numbers-mode 'relative)
;; broken terminal that doesn't compile but at least it's fast when it does
(use-package vterm