dotfiles/emacs.d/editing.el
2024-12-14 19:37:14 -05:00

178 lines
6.7 KiB
EmacsLisp

;; (use-package corfu
;; :ensure t
;; :hook (after-init . global-corfu-mode)
;; :bind (:map corfu-map ("<tab>" . corfu-complete))
;; :config
;; (setq tab-always-indent 'complete)
;; (setq corfu-preview-current nil)
;; (setq corfu-min-width 20)
;; (setq corfu-popupinfo-delay '(1.25 . 0.5))
;; (corfu-popupinfo-mode 1) ; shows documentation after 'corfu-popupinfo-delay'
;; ;; sort by input history
;; (with-eval-after-load 'savehist
;; (corfu-history-mode 1)
;; (add-to-list 'savehist-additional-variables 'corfu-history)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Fucking tabs, man ....
;;
;; <rant>
;;
;; Tabs for indentation, Spaces for alignment. This is *always* the correct
;; method, and will always be the correct method as long as there are space
;; heathens out there who see nothing wrong with enforcing their preferred
;; indentation size (by way of it being fixed in stone by being in spaces
;; instead of tabs) on everyone else. But, after trying to do "tabs for
;; indentation, spaces for alignment" in Emacs for a little bit now, and also
;; seeing how Emacs handles tabs out of the box, I understand a little tiny bit
;; more why so many people might want to advocate spaces-only, even if I very
;; strongly disagree with it. Emacs has some pretty horrific behaviour if you
;; try to switch tabs to be actual tabs instead of spaces. I actually think that
;; when it comes to tabs, Emacs may very well be one of the worst editors I've
;; seen. I think this is mainly due to the fact that Emacs overloads the
;; behaviour of the tab key, where it actually performs some kind of
;; auto-magical "indent to the correct level" behaviour (which is of fairly
;; questionable effectiveness from what I've witnessed), combined with the
;; typical Emacs completion configuration being *also* bound to the tab key! It
;; really is quite maddening. And un-fucking this behaviour is also quite
;; maddeninng, which is why I said before that I think Emacs might very well be
;; one of the worst editors I've seen when it comes to configuring tab key
;; behaviour. The configuration is just stupidly complicated and hard to figure
;; out. There may very well be a "correct" way to fix this that keeps tabs for
;; indentation and works well for all language modes, and keeps the default
;; Emacs tab key binding ... but good fucking luck find this configuration.
;;
;; I am an adult, and I am quite capable of hitting the tab key until I get to
;; the correct indentation level. Yes, maybe sometimes I might have to hit the
;; tab key twice, or three times maybe. Big fucking deal. I don't need some
;; dumb "auto-magical-indent" key unless it is actually proven to work out of
;; the box with sane defaults across all language modes. Emacs does *not* fit
;; into this restriction, thus the only sane thing to do is to bind the tab
;; key to insert tabs (or spaces, of course) only and not to try to do any
;; auto-indent behaviour at all. Just insert tabs or spaces according to
;; `indent-tabs-mode` and DO NOTHING ELSE.
;;
;; </rant>
;; this extra var just so that we always have it around and won't ever be
;; rebound by some other mode
(setq my-preferred-tab-width 4)
(setq-default tab-width my-preferred-tab-width)
(setq-default indent-tabs-mode t)
;;(setq-default tab-always-indent t)
(setq-default electric-indent-inhibit t)
(setq backward-delete-char-untabify-method 'hungry)
(defun gered/enable-tabs ()
(interactive)
(message "gered/enable-tabs for %s" (buffer-name))
(local-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq-local tab-width my-preferred-tab-width)
(setq-local indent-tabs-mode t))
(defun gered/disable-tabs (&optional override-tab-width)
(interactive)
(message "gered/disable-tabs for %s" (buffer-name))
(local-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq-local tab-width (or override-tab-width my-preferred-tab-width))
(setq-local indent-tabs-mode nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-set-key (kbd "C->") 'indent-rigidly-right-to-tab-stop)
(global-set-key (kbd "C-<") 'indent-rigidly-left-to-tab-stop)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package corfu
:ensure t
:hook (after-init . global-corfu-mode)
;; :bind
;; ( :map corfu-map
;; ("<tab>" . corfu-complete))
:config
;;(setq tab-always-indent 'complete)
(setq corfu-auto t)
(setq corfu-auto-delay 0.5)
(setq corfu-auto-prefix 2)
(setq corfu-preview-current nil)
(setq corfu-min-width 20))
(use-package corfu-popupinfo
:ensure nil
:after corfu
:hook (corfu-mode . corfu-popupinfo-mode)
:custom
(corfu-popupinfo-delay '(0.25 . 0.1))
(corfu-popupinfo-hide nil)
:config
(corfu-popupinfo-mode))
(use-package corfu-terminal
:ensure t
:if (not (display-graphic-p))
:config
(corfu-terminal-mode))
(use-package cape
:ensure t
:init
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
(add-to-list 'completion-at-point-functions #'cape-file))
(use-package delsel
:ensure nil
:hook (after-init . delete-selection-mode))
(use-package expand-region
:ensure t
:bind
(("M-<S-up>" . er/expand-region)
("M-<S-down>" . er/contract-region)))
(use-package dtrt-indent
:ensure t
:config
(setq dtrt-indent-verbosity 3)
(setq dtrt-indent-min-quality 75.0)
(setq dtrt-indent-run-after-smie t)
(setq dtrt-indent-hook-mapping-list
(append
;; TODO: override more of these. it may be best to write some generic function
;; that pre-adds `tab-width` to every single value in this list, and only
;; then go and add the missing modes?
;; list ref: https://github.com/jscheid/dtrt-indent/blob/master/dtrt-indent.el#L328
'((js-ts-mode javascript (js-indent-level tab-width))
(yaml-ts-mode default (yaml-indent-offset tab-width))
(php-mode c/c++/java (c-basic-offset tab-width))
(nxml-mode sgml (nxml-child-indent tab-width))
)
(eval 'dtrt-indent-hook-mapping-list)))
(dtrt-indent-global-mode t))
(use-package paredit
:ensure t
:bind
( :map paredit-mode-map
("M-s" . nil) ; conflicts with preferred consult key binds
)
:config
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
;; wtf?
;;(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode))
(use-package emacs
:ensure nil
:hook ((prog-mode . electric-pair-mode)))
;; (use-package idle-highlight-mode
;; :ensure t
;; :hook ((prog-mode . idle-highlight-mode)))