doomemacs/modules/editor/format/config.el
Henrik Lissner cb5c9cc9ea
Don't autoformat emacs-lisp-mode buffers on save
This is much too unpredictable, considering the variable nature of elisp
indentation, and the possibility that certain functions and their indent
behavior may not be defined/declared when the file is being formatted.
2018-08-29 12:46:24 +02:00

34 lines
1.2 KiB
EmacsLisp

;;; editor/format/config.el -*- lexical-binding: t; -*-
(defvar +format-on-save-enabled-modes '(not emacs-lisp-mode)
"A list of major modes in which to enable `format-all-mode'.
This mode will auto-format buffers when you save them.
If this list begins with `not', then it negates the list.
If it is `t', it is enabled in all modes.
If nil, it is disabled in all modes, the same as if the +onsave flag wasn't
used at all.")
;;
;; Plugins
;;
(defun +format|enable-on-save-maybe ()
"Enable formatting on save in certain major modes.
This is controlled by `+format-on-save-enabled-modes'."
(unless (or (eq major-mode 'fundamental-mode)
(cond ((booleanp +format-on-save-enabled-modes)
(null +format-on-save-enabled-modes))
((eq (car +format-on-save-enabled-modes) 'not)
(memq major-mode (cdr +format-on-save-enabled-modes)))
((not (memq major-mode +format-on-save-enabled-modes))))
(not (require 'format-all nil t))
(equal (format-all-probe) (list nil nil)))
(add-hook 'before-save-hook #'+format|buffer nil t)))
(when (featurep! +onsave)
(add-hook 'after-change-major-mode-hook #'+format|enable-on-save-maybe))