From cdbf97b4e9f64e189010edb73e3cc4b24ff4185f Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 12:37:46 -0500 Subject: [PATCH 1/7] fix(format): align behaviour and documentation `+format-on-save-disabled-modes` documentation was referencing behaviour that no longer exists, as well as documenting behaviour that was not implemented. --- modules/editor/format/config.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 6c97ca6b4..4b02bf22d 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -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 @@ -39,6 +38,7 @@ select buffers.") 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))))) From 9b718f8a5aff68dc63a6ece8d44db4ee77fcc511 Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 17:16:14 -0500 Subject: [PATCH 2/7] docs(format): document +format-on-save-disabled-modes in README --- modules/editor/format/README.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index dc3126934..21dcced27 100644 --- a/modules/editor/format/README.org +++ b/modules/editor/format/README.org @@ -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]] From 85d20f71ca45112af897931b20dac2cab2c89ebb Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 17:18:47 -0500 Subject: [PATCH 3/7] docs(format): fix name of doom-package --- modules/editor/format/README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index 21dcced27..3c45f3e5b 100644 --- a/modules/editor/format/README.org +++ b/modules/editor/format/README.org @@ -117,7 +117,7 @@ formatted on save, but can still be formatted by manually invoking the commands ** 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 From 9d8f657b37f14a75eff6900bd9441c47083d5b01 Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 17:21:09 -0500 Subject: [PATCH 4/7] refactor(format): describe what hook does --- modules/editor/format/config.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 4b02bf22d..e73159b73 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -33,8 +33,8 @@ 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)) @@ -46,7 +46,7 @@ This is controlled by `+format-on-save-disabled-modes'." (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))) ;; From 9da33cf9e7e853fb66781cf66f74d6986aba0e50 Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 17:24:29 -0500 Subject: [PATCH 5/7] docs(format): describe interaction between +onsave and LSP --- modules/editor/format/config.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index e73159b73..91584d1a3 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -21,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.") From c076b1237f0b89a1c2ae95df8bda3c4a44e99450 Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 17:31:37 -0500 Subject: [PATCH 6/7] docs(format): reasoning for using +format/buffer --- modules/editor/format/README.org | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index 3c45f3e5b..d5c855bac 100644 --- a/modules/editor/format/README.org +++ b/modules/editor/format/README.org @@ -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,7 +114,7 @@ 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 From fbd00b6a08300b453c15410e693823078c9015af Mon Sep 17 00:00:00 2001 From: John Goff Date: Tue, 21 Nov 2023 14:46:02 -0500 Subject: [PATCH 7/7] fix(format): correct name of feature --- modules/editor/format/config.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 91584d1a3..77dd06479 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -43,7 +43,7 @@ This is controlled by `+format-on-save-disabled-modes'." (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)