Fix line numbers! They are relative, they work, do not mess with them!

(also switch back to vertico because ivy does too much)
This commit is contained in:
MitchMarq42 2022-07-16 18:03:19 -08:00
parent 5e656cf5b4
commit d268caa38a
2 changed files with 126 additions and 88 deletions

View File

@ -90,10 +90,11 @@ Made solely to reduce lines in the init file."
"A tiny wrapper around `display-line-numbers-mode' or `linum'.
For use in hooks."
(interactive)
(if display-line-numbers-mode
(if (bound-and-true-p display-line-numbers-mode)
(display-line-numbers-mode -1))
(linum-mode -1)
(linum-relative-mode -1))
(if (fboundp #'linum-relative-mode)
(linum-relative-mode -1)))
(defun mitch/terminal-setup ()
"A batch of commands to run when opening anything that looks like a terminal.
@ -111,6 +112,7 @@ For instance:
For use with `vterm'."
(setq default-directory path))
;; This one line cost me over an hour of frustration...
(provide 'mitch-defuns)

View File

@ -114,52 +114,88 @@
:diminish)
;; Completion framework...
(use-package ivy
:diminish
:custom
(ivy-auto-shrink-minibuffer-alist '((t . t)))
:config (ivy-mode t)
:general
(general-define-key
:keymaps 'ivy-minibuffer-map
"TAB" 'ivy-alt-done))
(use-package counsel
:diminish
:config (counsel-mode))
;; (use-package vertico
;; :custom (vertico-resize t)
;; :config (vertico-mode))
;; (use-package consult
;; :after vertico)
;; (use-package ivy
;; :diminish
;; :custom
;; (ivy-auto-shrink-minibuffer-alist '((t . t)))
;; :config (ivy-mode t)
;; :general
;; (general-define-key
;; :keymaps 'ivy-minibuffer-map
;; "TAB" 'ivy-alt-done))
;; (use-package counsel
;; :diminish
;; :config (counsel-mode))
(use-package vertico
:custom (vertico-resize t)
:config (vertico-mode)
(add-hook 'minibuffer-setup-hook 'turn-off-line-numbers))
(use-package consult
:after vertico)
;; Minibuffer generic stuff
(use-package savehist
:straight (:type built-in)
:after ivy
:init (savehist-mode))
(use-package marginalia
:after ivy
;; :after ivy
:custom (marginalia-separator " ")
:init (marginalia-mode))
;; (use-package orderless
;; ;; :after vertico
;; ;; :config
;; ;; (setq completion-category-defaults nil
;; ;; completion-category-overrides nil)
(use-package orderless
;; :after vertico
;; :config
;; (setq completion-category-defaults nil
;; completion-category-overrides nil)
;; :commands 'execute-extended-command
;; :custom
;; (completion-styles '(orderless partial-completion basic))
;; (completion-category-defaults nil)
;; ;; (completion-category-overrides '((file (styles basic partial-completion))))
;; (completion-category-overrides nil)
;; )
:custom
(completion-styles '(orderless partial-completion basic))
(completion-category-defaults nil)
;; (completion-category-overrides '((file (styles basic partial-completion))))
(completion-category-overrides nil)
)
;; BROKEN: Relative line numbers with stuff
(use-package linum-relative
:diminish
:init
(require 'cl-lib)
(require 'linum-relative)
(setq linum-relative-current-symbol "")
(defvar total-lines (count-lines (point-min) (point-max)))
(defvar total-width 4)
;; (defun mitch/get-total-width ()
;; (+ 2 (round (log total-lines 10))))
(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)))
(- total-width symbol-width)))
(defun mitch/right-pad (line-number)
"Pad the line number to the right."
(let* (
(spacing (- 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)
:custom
(linum-relative-current-symbol "")
(linum-relative-backend 'display-line-numbers-mode)
:init
(linum-relative-global-mode 1))
)
;; broken terminal that doesn't compile but at least it's fast when it does
(use-package vterm
@ -486,15 +522,15 @@
((t (:background "#afafaf" :extend t)))))
;; epic drop-down completion
(use-package company
:diminish
:custom ;(company-require-match nil)
(company-tooltip-align-annotations t)
:hook (prog-mode . company-mode))
(use-package company-lsp
:after (lsp company)
:config
(push 'company-lsp company-backends))
;; (use-package company
;; :diminish
;; :custom ;(company-require-match nil)
;; (company-tooltip-align-annotations t)
;; :hook (prog-mode . company-mode))
;; (use-package company-lsp
;; :after (lsp company)
;; :config
;; (push 'company-lsp company-backends))
;; (use-package company-fuzzy
;; :diminish
;; :hook (company-mode . company-fuzzy-mode)
@ -505,46 +541,46 @@
;; (company-fuzzy-history-backends '(company-yasnippet))
;; (company-fuzzy-trigger-symbols '("." "->" "<" "\"" "'" "@"))
;; (company-fuzzy-passthrough-backends '(company-capf)))
;; (use-package corfu
;; :custom
;; (completion-cycle-threshold 3)
;; (tab-always-indent 'complete)
;; (corfu-auto t)
;; (corfu-quit-no-match t)
;; (corfu-count (- (window-total-height) 10))
;; ;; (corfu-separator ";")
;; :init (global-corfu-mode)
;; ;; (defun corfu-enable-always-in-minibuffer ()
;; ;; "Enable Corfu in the minibuffer if Vertico/Mct are not active."
;; ;; (unless (or (bound-and-true-p mct--active)
;; ;; (bound-and-true-p vertico--input))
;; ;; (setq-local corfu-auto nil) ;; Enable/disable auto completion
;; ;; (corfu-mode 1)
;; ;; (minibuffer-complete)))
;; ;; (add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
;; ;; (defun corfu-kill-in-minibuffer ()
;; ;; "Kill corfu and minibuffer. To be bound to Esc."
;; ;; (interactive)
;; ;; (setq-local inhibit-debugger t)
;; ;; (corfu-quit)
;; ;; (exit-minibuffer)
;; ;; )
;; (defun corfu-send-shell (&rest _)
;; "Send completion candidate when inside comint/eshell."
;; (cond
;; ((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
;; (eshell-send-input))
;; ((and (derived-mode-p 'comint-mode) (fboundp 'comint-send-input))
;; (comint-send-input))))
;; :general
;; (general-define-key
;; :prefix-map 'corfu-map
;; "C-n" 'corfu-next
;; "C-p" 'corfu-previous
;; "RET" 'corfu-insert
;; "ESC" 'corfu-kill-in-minibuffer
;; )
(use-package corfu
:custom
(completion-cycle-threshold 3)
(tab-always-indent 'complete)
(corfu-auto t)
(corfu-quit-no-match t)
(corfu-count (- (window-total-height) 10))
;; (corfu-separator ";")
:init (global-corfu-mode)
;; (defun corfu-enable-always-in-minibuffer ()
;; "Enable Corfu in the minibuffer if Vertico/Mct are not active."
;; (unless (or (bound-and-true-p mct--active)
;; (bound-and-true-p vertico--input))
;; (setq-local corfu-auto nil) ;; Enable/disable auto completion
;; (corfu-mode 1)
;; (minibuffer-complete)))
;; (add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
;; (defun corfu-kill-in-minibuffer ()
;; "Kill corfu and minibuffer. To be bound to Esc."
;; (interactive)
;; (setq-local inhibit-debugger t)
;; (corfu-quit)
;; (exit-minibuffer)
;; )
(defun corfu-send-shell (&rest _)
"Send completion candidate when inside comint/eshell."
(cond
((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
(eshell-send-input))
((and (derived-mode-p 'comint-mode) (fboundp 'comint-send-input))
(comint-send-input))))
:general
(general-define-key
:prefix-map 'corfu-map
"C-n" 'corfu-next
"C-p" 'corfu-previous
"RET" 'corfu-insert
"ESC" 'corfu-kill-in-minibuffer
)
)
(use-package popon
:straight