From cdbf97b4e9f64e189010edb73e3cc4b24ff4185f Mon Sep 17 00:00:00 2001 From: John Goff Date: Thu, 16 Nov 2023 12:37:46 -0500 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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) From 9c3d1951e3d125b9dadd348f6c1c46f26c4a3a24 Mon Sep 17 00:00:00 2001 From: Patrick Norton <36009535+PatrickNorton@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:08:36 -0800 Subject: [PATCH 8/9] fix(swift): don't load lsp-sourcekit with eglot The `use-package!` declaration for lsp-sourcekit in `config.el` did not match the `package!` declaration in `packages.el`: this resulted in `lsp-sourcekit` being loaded but never installed. The removal of this package also resulted in there no longer being a proper LSP client with eglot--this has also been fixed. --- modules/lang/swift/config.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/lang/swift/config.el b/modules/lang/swift/config.el index 8de47b3ce..5fc4d9888 100644 --- a/modules/lang/swift/config.el +++ b/modules/lang/swift/config.el @@ -4,7 +4,9 @@ (set-repl-handler! 'swift-mode #'run-swift) (when (modulep! +lsp) - (add-hook 'swift-mode-local-vars-hook #'lsp! 'append)) + (add-hook 'swift-mode-local-vars-hook #'lsp! 'append) + (when (modulep! :tools lsp +eglot) + (set-eglot-client! swift-mode 'swift-mode '("sourcekit-lsp")))) (when (modulep! +tree-sitter) (add-hook 'swift-mode-local-vars-hook #'tree-sitter! 'append))) @@ -25,7 +27,7 @@ (use-package! lsp-sourcekit - :when (modulep! +lsp) + :when (and (modulep! +lsp) (not (modulep! :tools lsp +eglot))) :after swift-mode :init (add-hook 'swift-mode-local-vars-hook #'lsp! 'append) :config From c2818bcfaa5dc1a0139d1deff7d77bf42a08eede Mon Sep 17 00:00:00 2001 From: Maoli Date: Fri, 24 Nov 2023 14:24:40 +0800 Subject: [PATCH 9/9] fix(latex): avoid stealing focus after compilation Current LaTeX module uses `TeX-command-run-all` for compilation, which by default opens the compiled document in a viewer. This behavior causes a loss of focus from the Emacs window. We address this by adding a custom compilation function. --- modules/lang/latex/config.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/lang/latex/config.el b/modules/lang/latex/config.el index 3bc13b18b..ed8e59fd5 100644 --- a/modules/lang/latex/config.el +++ b/modules/lang/latex/config.el @@ -102,16 +102,23 @@ If no viewer is found, `latex-preview-pane-mode' is used.") (add-hook! '(tex-mode-local-vars-hook latex-mode-local-vars-hook) :append #'lsp!)) + ;; Define a function to compile the project. + (defun +latex/compile () + (interactive) + (TeX-save-document (TeX-master-file)) + (TeX-command TeX-command-default 'TeX-master-file -1)) (map! :localleader :map latex-mode-map :desc "View" "v" #'TeX-view - :desc "Compile" "c" #'TeX-command-run-all + :desc "Compile" "c" #'+latex/compile + :desc "Run all" "a" #'TeX-command-run-all :desc "Run a command" "m" #'TeX-command-master) (map! :after latex :localleader :map LaTeX-mode-map :desc "View" "v" #'TeX-view - :desc "Compile" "c" #'TeX-command-run-all + :desc "Compile" "c" #'+latex/compile + :desc "Run all" "a" #'TeX-command-run-all :desc "Run a command" "m" #'TeX-command-master))