initial work at un-fucking emacs tabs and indentation

there is still more work to be done
This commit is contained in:
Gered 2024-12-14 19:37:14 -05:00
parent df8a78d257
commit 76083bf8eb
2 changed files with 123 additions and 15 deletions

View file

@ -15,9 +15,77 @@
;; (corfu-history-mode 1)
;; (add-to-list 'savehist-additional-variables 'corfu-history)))
(setq-default tab-width 4)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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 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
@ -68,8 +136,21 @@
(use-package dtrt-indent
:ensure t
:config
(setq dtrt-indent-verbosity 0)
(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

View file

@ -1,3 +1,10 @@
;; for the most part, we want to use tabs for indentation
(add-hook 'prog-mode-hook 'gered/enable-tabs)
(add-hook 'text-mode-hook 'gered/enable-tabs)
(add-hook 'conf-mode-hook 'gered/enable-tabs)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package treesit-auto
:ensure t
:custom
@ -8,14 +15,11 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package emacs-lisp-mode
:hook ((emacs-lisp-mode . gered/on-emacs-lisp-mode))
:init
(defun gered/on-emacs-lisp-mode ()
(lambda ()
;; TODO: is this even necessary or was i seeing something odd caused by my own (prior) mistakes?
(setq-local indent-tabs-mode nil)
(setq-local tab-width 2))))
(defun gered/on-lispy-mode ()
(gered/disable-tabs 2))
(add-hook 'emacs-lisp-mode-hook 'gered/on-lispy-mode)
(add-hook 'lisp-mode-hook 'gered/on-lispy-mode)
(use-package lisp-extra-font-lock
:ensure t
@ -27,7 +31,15 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package yaml-mode
:ensure t)
:ensure t
:config
(setq yaml-indent-offset 2))
(defun gered/on-yaml-mode ()
(gered/disable-tabs yaml-indent-offset))
(add-hook 'yaml-mode-hook 'gered/on-yaml-mode)
(add-hook 'yaml-ts-mode-hook 'gered/on-yaml-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -63,19 +75,21 @@
(use-package js
:config
(setq js-indent-level tab-width))
(setq js-indent-level my-preferred-tab-width))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package lua-mode
:ensure t)
:ensure t
:config
(setq lua-indent-level my-preferred-tab-width))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package c-ts-mode
:config
(setq-default c-ts-mode-indent-style 'linux)
(setq-default c-ts-mode-indent-offset tab-width))
(setq-default c-ts-mode-indent-offset my-preferred-tab-width))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -102,3 +116,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package sgml-mode
:config
(setq sgml-basic-offset my-preferred-tab-width))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package nxml-mode
:config
(setq nxml-child-indent my-preferred-tab-width)
(setq nxml-attribute-indent my-preferred-tab-width)
(setq nxml-slash-auto-complete-flag t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;