emacs/config/formatting.org
2026-02-04 15:53:11 -06:00

2.6 KiB

Blocks, Parentheses and Formatting Oh My!

Parentheses, and Structural Editing

Sometimes if I delete a parenthesis out of hand I spend the next minute or two kicking myself as I count the parentheses here and there. Well no more! With Parinfer structural editing, and taming parentheses becomes a breeze.

(use-package parinfer-rust-mode
  :ensure t
  :init
  (setq parinfer-rust-auto-download t)
  :hook
  emacs-lisp-mode
  clojure-ts-mode)

I also have smart-parens for parentheses matching in modes where parinfer would be overkill.

(use-package smartparens
  :ensure t
  :hook (prog-mode text-mode markdown-mode)
  :config
  (require 'smartparens-config))

Might as well highlight the parentheses to make them easier to spot.

(use-package indent-bars
  :ensure t
  :hook ((emacs-lisp-mode 
          c-ts-mode
          c++-ts-mode 
          clojure-ts-mode
          elisp-mode
          lisp-mode 
          rust-ts-mode 
          ruby-ts-mode) . indent-bars-mode)
  :custom
  ;; Character used for the bar (for terminal or if stipples are disabled)
  (indent-bars-char "|") 
  ;; The width of the bar (0.1 to 1.0)
  (indent-bars-width-frac 0.1)
  ;; How "offset" the bar is from the left
  (indent-bars-pad-frac 0.1)
  ;; Whether to draw bars on the first level of indentation
  (indent-bars-starting-column 0)
  ;; Tree-sitter support (highly recommended for C, Rust, and Ruby)
  (indent-bars-treesit-support t)
  ;; Optimization: don't draw bars in strings/comments
  (indent-bars-no-descend-lists t)
  :config
  (setq
    indent-bars-color '(highlight :face-bg t :blend 0.15)
    indent-bars-pattern "."
    indent-bars-width-frac 0.1
    indent-bars-pad-frac 0.1
    indent-bars-zigzag nil
    indent-bars-color-by-depth '(:regexp "outline-\\([0-9]+\\)" :blend 1) ; blend=1: blend with BG only
    indent-bars-highlight-current-depth '(:blend 0.5) ; pump up the BG blend on current
    indent-bars-display-on-blank-lines t))

Apheleia

Aphelia tries to use the right formatting for any file and applies it asynchronously.

(use-package apheleia
  :config
  (apheleia-global-mode +1))

Indentation Level

;; Indent guides
(use-package highlight-indent-guides
  :defer t
  :hook (prog-mode . highlight-indent-guides-mode))

List, and String Improvements

(use-package dash :ensure t)
(use-package s :ensure t)