diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index dc3126934..d5c855bac 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]] @@ -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 diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 6c97ca6b4..77dd06479 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 @@ -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))) ;; 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)) 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