Browse Source

emacs: much better handling of tabs

master
Alison Watson 3 months ago
parent
commit
1bd440514b
2 changed files with 20 additions and 73 deletions
  1. +7
    -33
      emacs/data.el
  2. +13
    -40
      emacs/init.el

+ 7
- 33
emacs/data.el View File

@@ -9,15 +9,6 @@
(defvar-local agw-no-fixes nil
"Fixes files before save if nil in this buffer.")

(defvar-local agw-no-tabs nil
"Disables tabs in this buffer.")

(defvar-local agw-no-tabs-width 2
"The width of non-hardware tabs with `agw-no-tabs'.")

(defvar-local agw-work nil
"Changes functionality for a work environment.")

(define-minor-mode agw-key-map-mode
"Minor mode for key bindings."
:global t
@@ -29,17 +20,22 @@

(defun agw-fp-mode ()
"Sets up lisp and other functional language major modes."
(setq-local agw-no-tabs t))
(setq-local indent-tabs-mode nil))

(defun agw-org-mode ()
"Sets up `org-mode'."
(setq-local agw-no-tabs t)
(setq-local indent-tabs-mode nil)
(define-key evil-normal-state-map (kbd "TAB") 'org-cycle))

(defun agw-cc-mode ()
"Sets up `c-mode' and `c++-mode'."
(c-toggle-electric-state -1))

(defun agw-maybe-smart-tabs-mode ()
"Enables `smart-tabs-mode' sometimes."
(when indent-tabs-mode
(smart-tabs-mode-enable)))

(defun agw-before-save ()
"Hook to be run before saving a file."
(unless agw-no-fixes
@@ -64,28 +60,6 @@
((eq selection 'screen-line) "ʌ")
((eq selection 'block) "Λ"))))

(defun agw-prog-mode ()
"Sets up `prog-mode' and `text-mode'."
(setq-local tab-always-indent t)
(when agw-work
(setq-local agw-no-tabs t
agw-no-tabs-width 4))
(if agw-no-tabs
(progn
(setq-local indent-tabs-mode nil
standard-indent agw-no-tabs-width
tab-width agw-no-tabs-width)
(smart-tabs-mode 0))
(progn
(setq-local indent-tabs-mode t
standard-indent 3
tab-width 3)
(smart-tabs-mode 1))))

(defun agw-after-local-vars ()
(if (or (derived-mode-p 'prog-mode) (derived-mode-p 'text-mode))
(agw-prog-mode)))

;; Lithium dialogues mode
(setq agw-lithdlg-highlights
(let* (( keywords '("dialogue" "terminal" "program" "page" "failure"


+ 13
- 40
emacs/init.el View File

@@ -29,9 +29,6 @@
(add-hook 'text-mode-hook #'agw-flyspell-prog-mode)
(add-hook 'text-mode-hook #'subword-mode)

;; `hack-local-variables'
(add-hook 'hack-local-variables-hook #'agw-after-local-vars)

;; macros
(setq initial-buffer-choice
(lambda ()
@@ -118,11 +115,13 @@
(defvaralias 'cmake-tab-width 'tab-width))

(use-package powershell
:hook (powershell-mode . agw-maybe-smart-tabs-mode)
:ensure t
:init
(defvaralias 'powershell-indent 'tab-width))

(use-package js
:hook (js-mode . agw-maybe-smart-tabs-mode)
:init
(defvaralias 'js-indent-level 'tab-width))

@@ -131,6 +130,7 @@
(defvaralias 'css-indent-offset 'tab-width))

(use-package lua-mode
:hook (lua-mode . agw-maybe-smart-tabs-mode)
:ensure t
:init
(setq lua-indent-nested-block-content-align nil))
@@ -146,14 +146,10 @@
:init
(defvaralias 'nim-indent-offset 'tab-width))

(use-package mmm-mode
(use-package poly-markdown
:ensure t)
(use-package poly-org
:ensure t)

(use-package mmm-auto
:init
(setq mmm-submode-decoration-level 0)
:config
(mmm-add-mode-ext-class 'ruby-mode nil 'here-doc))

(use-package python
:init
@@ -161,7 +157,9 @@

(use-package cc-mode
:hook (( c-mode . agw-cc-mode)
(c++-mode . agw-cc-mode))
( c-mode . agw-maybe-smart-tabs-mode)
(c++-mode . agw-cc-mode)
(c++-mode . agw-maybe-smart-tabs-mode))
:mode (("\\.zsc\\'" . c-mode)
("\\.zc\\'" . c-mode)
("\\.build\\'" . c++-mode))
@@ -172,11 +170,13 @@
(defvaralias 'c-basic-offset 'tab-width))

(use-package fish-mode
:hook (fish-mode . agw-maybe-smart-tabs-mode)
:ensure t
:init
(defvaralias 'fish-indent-offset 'tab-width))

(use-package glsl-mode
:hook (glsl-mode . agw-maybe-smart-tabs-mode)
:ensure t)

(use-package haskell-mode
@@ -198,6 +198,7 @@
(setq ruby-insert-encoding-magic-comment nil))

(use-package rust-mode
:hook (rust-mode . agw-maybe-smart-tabs-mode)
:ensure t
:init
(defvaralias 'rust-indent-offset 'tab-width))
@@ -277,14 +278,7 @@
((c-indent-line . c-basic-offset)
(c-indent-region . c-basic-offset)))
(smart-tabs-add-language-support lua lua-mode-hook
((lua-indent-line . lua-indent-level)))
(smart-tabs-insinuate
'c
'fish
'glsl
'javascript
'lua
'rust))
((lua-indent-line . lua-indent-level))))

(use-package ialign
:ensure t
@@ -444,27 +438,6 @@

(use-package subword)

(use-package dim
:ensure t
:after (editorconfig
eldoc
rainbow-mode
simple
subword
undo-tree
whitespace)
:config
(dim-minor-names
'((abbrev-mode "Ab")
(editorconfig-mode "Ec")
(eldoc-mode "El")
(isearch-mode "Is")
(subword-mode "Sw")
(undo-tree-mode "Ut")
(whitespace-mode "Ws")
(flyspell-mode "Fs")
(rainbow-mode "Rb"))))

(use-package rainbow-mode
:ensure t
:hook ((prog-mode . rainbow-mode)


Loading…
Cancel
Save