merge: pull request #7549 from John-Goff/master
This commit is contained in:
commit
3cdf67ccce
2 changed files with 18 additions and 16 deletions
|
@ -25,8 +25,8 @@ be formatted and returned to the buffer using
|
|||
** Module flags
|
||||
- +onsave ::
|
||||
Enable reformatting of a buffer when it is saved. See
|
||||
[[var:+format-on-save-disabled-modes]] to control what major modes to (or not to)
|
||||
format on save.
|
||||
[[var:+format-on-save-disabled-modes]] to disable format on save for certain
|
||||
major modes.
|
||||
|
||||
** Packages
|
||||
- [[doom-package:apheleia]]
|
||||
|
@ -60,8 +60,9 @@ When this flag is enabled, you shouldn't need to do anything other than write
|
|||
code and save it.
|
||||
|
||||
** Without +onsave
|
||||
Without the flag, formatting will only occur when either =apheleia-format-buffer=
|
||||
or =+format/buffer= is called.
|
||||
Without the flag, formatting will only occur when either =+format/buffer=
|
||||
or =apheleia-format-buffer= is called. The difference between them is
|
||||
=+format/buffer= will use a LSP server if configured and available.
|
||||
|
||||
* Configuration
|
||||
|
||||
|
@ -113,11 +114,11 @@ This behaviour is controlled via [[var:+format-on-save-disabled-modes]] thus;
|
|||
|
||||
In this case, =emacs-lisp-mode=, =sql-mode=, =tex-mode= and =latex-mode= will not be
|
||||
formatted on save, but can still be formatted by manually invoking the commands
|
||||
=apheleia-format-buffer= or =+format/buffer=.
|
||||
=+format/buffer= or =apheleia-format-buffer=.
|
||||
|
||||
** Disabling the LSP formatter
|
||||
If you are in a buffer with ~lsp-mode~ enabled and a server that supports
|
||||
=textDocument/formatting=, it will be used instead of [[doom-package:format-all]]'s formatter.
|
||||
=textDocument/formatting=, it will be used instead of [[doom-package:apheleia]]'s formatter.
|
||||
|
||||
+ To disable this behavior universally use: ~(setq +format-with-lsp nil)~
|
||||
+ To disable this behavior in one mode: ~(setq-hook! 'python-mode-hook
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
tex-mode ; latexindent is broken
|
||||
latex-mode
|
||||
org-msg-edit-mode) ; doesn't need a formatter
|
||||
"A list of major modes in which to reformat the buffer upon saving.
|
||||
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.
|
||||
"A list of major modes in which to not reformat the buffer upon saving.
|
||||
If it is t, it is disabled in all modes, the same as if the +onsave flag
|
||||
wasn't used at all.
|
||||
If nil, formatting is enabled in all modes.
|
||||
Irrelevant if you do not have the +onsave flag enabled for this module.")
|
||||
|
||||
(defvar +format-preserve-indentation t
|
||||
|
@ -22,7 +21,8 @@ Indentation is always preserved when formatting regions.")
|
|||
"If non-nil, format with LSP formatter if it's available.
|
||||
|
||||
This can be set buffer-locally with `setq-hook!' to disable LSP formatting in
|
||||
select buffers.")
|
||||
select buffers.
|
||||
This has no effect on the +onsave flag, apheleia will always be used there.")
|
||||
|
||||
(defvaralias '+format-with 'apheleia-formatter
|
||||
"Set this to explicitly use a certain formatter for the current buffer.")
|
||||
|
@ -34,19 +34,20 @@ select buffers.")
|
|||
(when (modulep! +onsave)
|
||||
(add-hook 'doom-first-file-hook #'apheleia-global-mode))
|
||||
|
||||
(defun +format-inhibit-maybe-h ()
|
||||
"Enable formatting on save in certain major modes.
|
||||
(defun +format-maybe-inhibit-h ()
|
||||
"Check if formatting should be disabled for current buffer.
|
||||
This is controlled by `+format-on-save-disabled-modes'."
|
||||
(or (eq major-mode 'fundamental-mode)
|
||||
(string-blank-p (buffer-name))
|
||||
(eq +format-on-save-disabled-modes t)
|
||||
(not (null (memq major-mode +format-on-save-disabled-modes)))))
|
||||
|
||||
|
||||
(after! apheleia-core
|
||||
(after! apheleia
|
||||
(add-to-list 'doom-debug-variables '(apheleia-log-only-errors . nil))
|
||||
|
||||
(when (modulep! +onsave)
|
||||
(add-to-list 'apheleia-inhibit-functions #'+format-inhibit-maybe-h)))
|
||||
(add-to-list 'apheleia-inhibit-functions #'+format-maybe-inhibit-h)))
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue