New :editor format module
Centralized code formatting with built-in support for a variety of languages. Provides the set-formatter! function for defining your own. Still experimental and needs more testing!
This commit is contained in:
parent
c7e6cb981b
commit
f51f2948af
7 changed files with 194 additions and 6 deletions
32
modules/editor/format/config.el
Normal file
32
modules/editor/format/config.el
Normal file
|
@ -0,0 +1,32 @@
|
|||
;;; editor/format/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +format-on-save-enabled-modes t
|
||||
"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 `format-all-mode' in buffers. See `+format-on-save-enabled-modes' to
|
||||
control which major modes to target."
|
||||
(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))))
|
||||
(require 'format-all nil t)
|
||||
(not (format-all-probe)))
|
||||
(format-all-mode +1)))
|
||||
|
||||
(when (featurep! +onsave)
|
||||
(add-hook 'after-change-major-mode-hook #'+format|enable-on-save-maybe))
|
Loading…
Add table
Add a link
Reference in a new issue