From b08c2c745fd206becece48162ccc39e94d95d381 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 02:57:29 -0400 Subject: [PATCH 01/33] module: remove :ui hydra This module has been deprecated for some time because it is too trivially small, and it's always been unclear how hydra fits into Doom's vision for its UI, but I intend to lean into either transient or Embark in the future. --- modules/ui/hydra/README.org | 62 ---------------------------- modules/ui/hydra/autoload/windows.el | 49 ---------------------- modules/ui/hydra/config.el | 15 ------- modules/ui/hydra/packages.el | 4 -- templates/init.example.el | 1 - 5 files changed, 131 deletions(-) delete mode 100644 modules/ui/hydra/README.org delete mode 100644 modules/ui/hydra/autoload/windows.el delete mode 100644 modules/ui/hydra/config.el delete mode 100644 modules/ui/hydra/packages.el diff --git a/modules/ui/hydra/README.org b/modules/ui/hydra/README.org deleted file mode 100644 index 688bf4f4b..000000000 --- a/modules/ui/hydra/README.org +++ /dev/null @@ -1,62 +0,0 @@ -#+title: :ui hydra -#+subtitle: Discount modality for mythological beast hunters -#+created: October 29, 2019 -#+since: 2.0.0 - -#+begin_quote -  *This module is deprecated.* The module is too trivially small, and it's - always been unclear how hydra fits into Doom's vision for its UI. It's been - decided that Doom will head toward Embark, transient, or hercules instead. -#+end_quote - -* Description :unfold: -This module adds hydra to Doom Emacs, as well as a few custom built hydras to -start with: - -- A hydra to control windows ~+hydra/window-nav/body~. -- A hydra to control text zoom level ~+hydra/text-zoom/body~. - -** Maintainers -/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]] - -** Module flags -/This module has no flags./ - -** Packages -- [[doom-package:hydra]] - -** Hacks -/No hacks documented for this module./ - -** TODO Changelog -# This section will be machine generated. Don't edit it by hand. -/This module does not have a changelog yet./ - -* Installation -[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] - -/This module has no external requirements./ - -* TODO Usage -#+begin_quote - 󱌣 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] -#+end_quote - -* TODO Configuration -#+begin_quote - 󱌣 /This module's configuration documentation is incomplete./ [[doom-contrib-module:][Complete it?]] -#+end_quote - -Configuring this module is only setting bindings to the provided hydra, or -creating your own ones! - -* Troubleshooting -/There are no known problems with this module./ [[doom-report:][Report one?]] - -* Frequently asked questions -/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] - -* TODO Appendix -#+begin_quote - 󱌣 This module has no appendix yet. [[doom-contrib-module:][Write one?]] -#+end_quote diff --git a/modules/ui/hydra/autoload/windows.el b/modules/ui/hydra/autoload/windows.el deleted file mode 100644 index d39286d80..000000000 --- a/modules/ui/hydra/autoload/windows.el +++ /dev/null @@ -1,49 +0,0 @@ -;;; ui/hydra/autoload/windows.el -*- lexical-binding: t; -*- - -;;;###autoload (autoload '+hydra/text-zoom/body "ui/hydra/autoload/windows" nil t) -(defhydra +hydra/text-zoom (:hint nil :color red) - " - Text zoom: _j_:zoom in, _k_:zoom out, _0_:reset -" - ("j" doom/increase-font-size "in") - ("k" doom/decrease-font-size "out") - ("0" doom/reset-font-size "reset")) - -;;;###autoload (autoload '+hydra/window-nav/body "ui/hydra/autoload/windows" nil t) -(defhydra +hydra/window-nav (:hint nil) - " - Split: _v_ert _s_:horz - Delete: _c_lose _o_nly - Switch Window: _h_:left _j_:down _k_:up _l_:right _u_:undo _r_:redo - Buffers: _p_revious _n_ext _b_:select _f_ind-file - Resize: _H_:splitter left _J_:splitter down _K_:splitter up _L_:splitter right - Move: _a_:up _z_:down _i_menu -" - ("z" scroll-up-line) - ("a" scroll-down-line) - ("i" idomenu) - - ("h" windmove-left) - ("j" windmove-down) - ("k" windmove-up) - ("l" windmove-right) - ("u" winner-undo) - ("r" winner-redo) - - ("p" previous-buffer) - ("n" next-buffer) - ("b" switch-to-buffer) - ("f" find-file) - - ("s" split-window-below) - ("v" split-window-right) - - ("c" delete-window) - ("o" delete-other-windows) - - ("H" hydra-move-splitter-left) - ("J" hydra-move-splitter-down) - ("K" hydra-move-splitter-up) - ("L" hydra-move-splitter-right) - - ("q" nil)) diff --git a/modules/ui/hydra/config.el b/modules/ui/hydra/config.el deleted file mode 100644 index 225943a74..000000000 --- a/modules/ui/hydra/config.el +++ /dev/null @@ -1,15 +0,0 @@ -;;; ui/hydra/config.el -*- lexical-binding: t; -*- - -(use-package! hydra-examples - :commands (hydra-move-splitter-up - hydra-move-splitter-down - hydra-move-splitter-right - hydra-move-splitter-left)) - -;;;###package hydra -(setq lv-use-separator t) - -(defadvice! +hydra--inhibit-window-switch-hooks-a (fn) - :around #'lv-window - (let (doom-switch-window-hook) - (funcall fn))) diff --git a/modules/ui/hydra/packages.el b/modules/ui/hydra/packages.el deleted file mode 100644 index 2b6fa4cbf..000000000 --- a/modules/ui/hydra/packages.el +++ /dev/null @@ -1,4 +0,0 @@ -;; -*- no-byte-compile: t; -*- -;;; ui/hydra/packages.el - -(package! hydra :pin "317e1de33086637579a7aeb60f77ed0405bf359b") diff --git a/templates/init.example.el b/templates/init.example.el index e1b3dc6e6..80142384f 100644 --- a/templates/init.example.el +++ b/templates/init.example.el @@ -35,7 +35,6 @@ ;;doom-quit ; DOOM quit-message prompts when you quit Emacs ;;(emoji +unicode) ; 🙂 hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW - ;;hydra ;;indent-guides ; highlighted indent columns ;;ligatures ; ligatures and symbols to make your code pretty again ;;minimap ; show a map of the code on the side From d81f1862f733a596b97320860251b01c997db20a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 17:53:55 -0400 Subject: [PATCH 02/33] refactor(php): remove php-cs-fixer This removes the php-cs-fixer.el package. This is not a breaking change because the package hasn't been this module's default formatter since 4ecd616. It has since been replaced by phpcbf (provided by squizlabs/php_codesniffer). Amend: 4ecd616cd8f6 --- modules/lang/php/README.org | 9 ++------- modules/lang/php/packages.el | 3 --- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/modules/lang/php/README.org b/modules/lang/php/README.org index a0de2d973..d2ea8b398 100644 --- a/modules/lang/php/README.org +++ b/modules/lang/php/README.org @@ -41,7 +41,6 @@ This module adds support for PHP 5.3+ (including PHP8) to Doom Emacs. - [[doom-package:async]] - [[doom-package:hack-mode]] if [[doom-module:+hack]] - [[doom-package:psysh]] -- [[doom-package:php-cs-fixer]] if [[doom-package::editor format]] - [[doom-package:php-extras]] - [[doom-package:php-mode]] - [[doom-package:php-refactor-mode]] @@ -121,7 +120,7 @@ The others have to be installed manually and added to your =$PATH=. - ~pysh~ (REPL) - ~phpctags~ (better code completion) - ~phpunit~ (unit test commands) -- ~php-cs-fixer~ and ~@prettier/plugin-php~ (for code formatting) +- ~phpcbf~, provided by ~squizlabs/php_codesniffer~ (for code formatting) + ~phpactor~ (for LSP if intelephense isn't desired) #+begin_src sh @@ -129,12 +128,8 @@ composer global require \ psy/psysh \ phpunit/phpunit \ techlivezheng/phpctags \ - friendsofphp/php-cs-fixer \ + squizlabs/php_codesniffer \ phpactor/phpactor - -# Needed by php-cs-fixer, otherwise you'll get "Couldn't resolve parser -# 'php'" errors -npm install -g @prettier/plugin-php #+end_src You must ensure that =$HOME/.composer/vendor/bin= is in =$PATH=, so these diff --git a/modules/lang/php/packages.el b/modules/lang/php/packages.el index 4816f3992..2b3f312fe 100644 --- a/modules/lang/php/packages.el +++ b/modules/lang/php/packages.el @@ -20,8 +20,5 @@ (when (modulep! :completion company) (package! company-phpactor :pin "6b5269ff82785a9bd1e648b2f91e5128353d5a67"))) -(when (modulep! :editor format) - (package! php-cs-fixer :pin "efe4368d891f1eec6311363cfd6be3e9eadb5e0a")) - ;; For building php-extras (package! async :pin "cff2bd0be3c78a2eb76717eed60302972fe9b8c5") From b7954f927f7832a1f6a1e726a481e9a5d870e2b8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 18:02:34 -0400 Subject: [PATCH 03/33] refactor!(org): remove ob-ipython BREAKING CHANGE: This commit removes the ob-ipython package; it's been deprecated for some time because the upstream package is no longer maintained and is broken on most, common versions of Python anyway. Jupyter is a superior alternative, in any case. --- modules/lang/org/README.org | 7 +- modules/lang/org/autoload/contrib-ipython.el | 152 ------------------- modules/lang/org/config.el | 4 +- modules/lang/org/contrib/ipython.el | 41 ----- modules/lang/org/packages.el | 2 - 5 files changed, 4 insertions(+), 202 deletions(-) delete mode 100644 modules/lang/org/autoload/contrib-ipython.el delete mode 100644 modules/lang/org/contrib/ipython.el diff --git a/modules/lang/org/README.org b/modules/lang/org/README.org index 6e84b5645..46626d900 100644 --- a/modules/lang/org/README.org +++ b/modules/lang/org/README.org @@ -19,8 +19,8 @@ intuitive out of the box: org files to reveal.js slideshows. - Drag-and-drop support for images (with inline preview) and media files (drops a file icon and a short link) (requires [[doom-module:+dragndrop]] flag). -- Integration with pandoc, ipython, jupyter, reveal.js, beamer, and others - (requires flags). +- Integration with pandoc, jupyter, reveal.js, beamer, and others (requires + flags). - Export-to-clipboard functionality, for copying text into formatted html, markdown or rich text to the clipboard (see fn:+org/export-to-clipboard and fn:+org/export-to-clipboard-as-rich-text). @@ -58,8 +58,6 @@ https://www.mfoot.com/blog/2015/11/22/literate-emacs-configuration-with-org-mode - +hugo :: Enable integration with [[https://gohugo.io][hugo]] to export from Emacs well-formed ([[https://github.com/russross/blackfriday][blackfriday]]) markdown. -- +ipython :: - (**DEPRECATED**) Enable ipython integration for babel. - +journal :: Enable [[doom-package:org-journal]] integration. - +jupyter :: @@ -95,7 +93,6 @@ https://www.mfoot.com/blog/2015/11/22/literate-emacs-configuration-with-org-mode - [[doom-package:ob-async]] - [[doom-package:ob-crystal]] if [[doom-module::lang crystal]] - [[doom-package:ob-go]] if [[doom-module::lang go]] -- [[doom-package:ob-ipython]] if [[doom-module:+ipython]] - [[doom-package:ob-nim]] if [[doom-module::lang nim]] - [[doom-package:ob-racket]] if [[doom-module::lang racket]] - [[doom-package:ob-restclient]] if [[doom-module::lang rest]] diff --git a/modules/lang/org/autoload/contrib-ipython.el b/modules/lang/org/autoload/contrib-ipython.el deleted file mode 100644 index 2399a159a..000000000 --- a/modules/lang/org/autoload/contrib-ipython.el +++ /dev/null @@ -1,152 +0,0 @@ -;;; lang/org/autoload/contrib-ipython.el -*- lexical-binding: t; -*- -;;;###if (modulep! +ipython) - -;;;###autoload -(defun +org-ob-ipython-initiate-session-a (&optional session params) - "Create a session named SESSION according to PARAMS." - (if (string= session "none") - (error - "ob-ipython currently only supports evaluation using a session. -Make sure your src block has a :session param.") - (when (not (string-suffix-p ".json" session t)) - (ob-ipython--create-kernel - (ob-ipython--normalize-session - session) - (cdr (assoc :kernel params)))) - (ob-ipython--create-repl - (ob-ipython--normalize-session - session) - params))) - -(defun +org--ob-ipython-generate-local-path-from-remote (session host params) - "Given a remote SESSION with PARAMS and corresponding HOST, copy remote config to local, start a jupyter console to generate a new one." - (let* ((runtime-dir - (cdr - (doom-call-process "ssh " host "jupyter" "--runtime-dir"))) - (runtime-file (concat runtime-dir "/" "kernel-" session ".json")) - (tramp-path (concat "/ssh:" host ":" runtime-file)) - (tramp-copy (concat (or +ob-ipython-local-runtime-dir - (cdr (doom-call-process "jupyter" "--runtime-dir"))) - "/remote-" host "-kernel-" session ".json")) - (local-path - (concat - "Python:ob-ipython-" - (file-name-sans-extension (file-name-nondirectory tramp-copy)) - "-ssh.json"))) - ;; scp remote file to local - (copy-file tramp-path tramp-copy t) - ;; connect to remote use new config - (let* ((python-shell-interpreter-interactive-arg " console --simple-prompt") - (python-shell-prompt-detect-enabled nil) - (python-shell-completion-native-enable nil) - (buf (python-shell-make-comint - (concat ob-ipython-command - " console --simple-prompt --existing " - tramp-copy " --ssh " host) - (concat "" local-path) - t)) - (proc (get-buffer-process buf)) - (dir (cdr (assoc :pydir params)))) - (sleep-for 3) - (when dir - (with-current-buffer buf - (setq-local default-directory dir))) - (format "*%s*" proc)))) - -;;;###autoload -(defun +org-ob-ipython-create-repl-a (name &optional params) - "Create repl based on NAME and PARAMS. -If PARAMS specifies remote kernel, copy the kernel config from remote server and -create a repl connecting to remote session." - (let ((cmd (string-join (ob-ipython--kernel-repl-cmd name) " "))) - (cond ((string= "default" name) - (run-python cmd nil nil) - (format "*%s*" python-shell-buffer-name)) - ((string-match "^remote-.*ssh.json" name) - (when (not (ignore-errors - (process-live-p - (get-process - (format - "Python:ob-ipython-%s" - name))))) - (let* ((remote (s-split "-" name)) - (remote-host (nth 1 remote)) - (remote-session (nth 3 remote))) - (+org--ob-ipython-generate-local-path-from-remote - remote-session - remote-host - params)))) - ((let* ((process-name (format "Python:ob-ipython-%s" name)) - (python-shell-prompt-detect-enabled nil) - (python-shell-completion-native-enable nil) - (buf (python-shell-make-comint cmd process-name t)) - (dir (cdr (assoc :pydir params)))) - (if dir - (with-current-buffer buf - (setq-local default-directory dir))) - (sleep-for 1) - (format "*%s*" process-name)))))) - -;;;###autoload -(defun +org-babel-execute:ipython-a (body params) - "Execute a BODY of IPython code with PARAMS in org-babel. -This function is called by `org-babel-execute-src-block'." - (message default-directory) - (org-babel-ipython-initiate-session (cdr (assoc :session params)) - params)) - - -;; -;; * org-src-edit - -;;;###autoload -(defun +org-babel-edit-prep:ipython-a (info) - (let* ((params (nth 2 info)) - (session (cdr (assoc :session params)))) - (org-babel-ipython-initiate-session session params)) - ;; Support for python.el's "send-code" commands within edit buffers. - (setq-local python-shell-buffer-name - (format "Python:ob-ipython-%s" - (ob-ipython--normalize-session - (cdr (assoc :session (nth 2 info)))))) - (setq-local default-directory - (format "%s" - (ob-ipython--normalize-session - (cdr (assoc :pydir (nth 2 info)))))) - (ob-ipython-mode 1) - ;; hack on company mode to use company-capf rather than company-anaconda - (when (modulep! :completion company) - (setq-local company-backends - '(company-capf - company-dabbrev - company-files - company-yasnippet)) - (setq-local company-idle-delay nil)) - (when (featurep 'lpy) - (setq lispy-python-proc - (format "Python:ob-ipython-%s" - (ob-ipython--normalize-session - (cdr (assoc :session (nth 2 info))))) - lispy--python-middleware-loaded-p nil) - (lispy--python-middleware-load))) - - -;; -;; * retina - -(defun +org--ob-ipython-mac-2x-image-file-name (filename &optional scale) - "Return the name of high-resolution image file for FILENAME. -The optional arg SCALE is scale factor, and defaults to 2." - (let ((pos (or (string-match "\\.[^./]*\\'" filename) (length filename)))) - (format "%s@%dx%s" - (substring filename 0 pos) - (or scale 2) - (substring filename pos)))) - -;;;###autoload -(defun +org-ob-ipython-write-base64-string-a (oldfunc &rest args) - (let ((file (car args)) - (b64-string (cdr args))) - (let ((file2x (+org--ob-ipython-mac-2x-image-file-name file))) - (apply oldfunc file2x b64-string) - (shell-command (concat "convert " file2x " -resize 50% " file))))) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index a10421257..608164188 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -289,8 +289,8 @@ Also adds support for a `:sync' parameter to override `:async'." initialize) args)) - ;; Refresh inline images after executing src blocks (useful for plantuml or - ;; ipython, where the result could be an image) + ;; Refresh inline images after executing src blocks (useful for plantuml, + ;; where the result could be an image) (add-hook! 'org-babel-after-execute-hook (defun +org-redisplay-inline-images-in-babel-result-h () (unless (or diff --git a/modules/lang/org/contrib/ipython.el b/modules/lang/org/contrib/ipython.el deleted file mode 100644 index 9b2016bc0..000000000 --- a/modules/lang/org/contrib/ipython.el +++ /dev/null @@ -1,41 +0,0 @@ -;;; lang/org/contrib/babel.el -*- lexical-binding: t; -*- -;;;###if (modulep! +ipython) - -(use-package! ob-ipython - :defer t - :init - (defvar +ob-ipython-local-runtime-dir nil) - - (setq ob-ipython-resources-dir ".ob-ipython-resrc") - - (add-hook! '+org-babel-load-functions - (defun +org-babel-load-ipython-h (lang) - (and (string-prefix-p "jupyter-" (symbol-name lang)) - (require 'ob-ipython nil t)))) - - (after! org-src - (add-to-list 'org-src-lang-modes '("ipython" . python))) - (after! ox-latex - (add-to-list 'org-latex-minted-langs '(ipython "python"))) - :config - (set-popup-rules! - '(("\\*ob-ipython.*" - :slot 2 :side right :size 100 :height 0.2 - :select nil :quit nil :ttl nil) - ("^ \\*Python" - :slot 0 :side right :size 100 - :select nil :quit nil :ttl nil))) - - ;; advices for remote kernel and org-src-edit - (advice-add #'ob-ipython--create-repl :override #'+org-ob-ipython-create-repl-a) - (advice-add #'org-babel-edit-prep:ipython :override #'+org-babel-edit-prep:ipython-a) - (advice-add #'org-babel-execute:ipython :before #'+org-babel-execute:ipython-a) - (advice-add #'org-babel-ipython-initiate-session :override #'+org-ob-ipython-initiate-session-a) - - ;; retina resolution image hack - (when (featurep :system 'macos) - (advice-add #'ob-ipython--write-base64-string :around #'+org-ob-ipython-write-base64-string-a)) - - ;; ipython has its own async keyword, disable ipython in ob-async. - (after! ob-async - (add-to-list 'ob-async-no-async-languages-alist "ipython"))) diff --git a/modules/lang/org/packages.el b/modules/lang/org/packages.el index 39ac5456a..82ef4feb7 100644 --- a/modules/lang/org/packages.el +++ b/modules/lang/org/packages.el @@ -78,8 +78,6 @@ (when (modulep! +gnuplot) (package! gnuplot :pin "7138b139d2dca9683f1a81325c643b2744aa1ea3") (package! gnuplot-mode :pin "601f6392986f0cba332c87678d31ae0d0a496ce7")) -(when (modulep! +ipython) ; DEPRECATED - (package! ob-ipython :pin "7147455230841744fb5b95dcbe03320313a77124")) (when (modulep! +jupyter) (package! jupyter :pin "b279c90295ed7ef89832d655cf8d9077233f1098")) (when (modulep! +journal) From 934141a01e48d041c6abc9a2281f7a11e5f4eb4d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 16:54:24 -0400 Subject: [PATCH 04/33] refactor!(python): remove lsp-python-ms BREAKING CHANGE: This removes the lsp-python-ms package (along with it, lsp-python-ms support), since the package no longer works in recent versions of Python and is no longer maintained upstream. --- modules/lang/python/README.org | 10 ++++------ modules/lang/python/config.el | 18 +++++------------- modules/lang/python/packages.el | 5 ++--- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/modules/lang/python/README.org b/modules/lang/python/README.org index cb70cb9e1..977365736 100644 --- a/modules/lang/python/README.org +++ b/modules/lang/python/README.org @@ -10,7 +10,7 @@ This module adds [[https://www.python.org/][Python]] support to Doom Emacs. - Snippets - Run tests ([[doom-package:nose]], [[doom-package:pytest]]) - Auto-format (with ~black~, requires [[doom-module::editor format]]) -- LSP integration (=mspyls=, =pyls=, or =pyright=) +- LSP integration (=pyls=, =jedi=, =ruff=, or =pyright=) ** Maintainers - [[doom-user:][@hlissner]] @@ -23,15 +23,15 @@ This module adds [[https://www.python.org/][Python]] support to Doom Emacs. - +cython :: Enable support for Cython files support. - +lsp :: - Enable LSP support for ~python-mode~. Requires [[doom-module::tools lsp]] and a langserver - (supports mspyls, pyls, and pyright). + Enable LSP support for ~python-mode~. Requires [[doom-module::tools lsp]] and a + langserver (=pyls=, =jedi=, =ruff=, or =pyright=). - +poetry :: Enable Python packaging, dependency management, and virtual environment support via [[https://python-poetry.org/][Poetry]]. - +pyenv :: Enable Python virtual environment support via [[https://github.com/pyenv/pyenv][pyenv]] - +pyright :: - Use the pyright LSP server instead of mspyls or pyls (requires [[doom-module:+lsp]]). + Add support for the pyright LSP server (requires [[doom-module:+lsp]]). - +tree-sitter :: Leverages tree-sitter for better syntax highlighting and structural text editing. Requires [[doom-module::tools tree-sitter]]. @@ -53,8 +53,6 @@ This module adds [[https://www.python.org/][Python]] support to Doom Emacs. - if [[doom-module:+lsp]] - if [[doom-module:+pyright]] - [[doom-package:lsp-pyright]] - - else - - [[doom-package:lsp-python-ms]] ** Hacks - [[doom-package:anaconda-mode]] is configured to activate when [[doom-package:lsp-mode]] (or [[doom-package:eglot]]) don't -- or diff --git a/modules/lang/python/config.el b/modules/lang/python/config.el index 373f580b6..58d496644 100644 --- a/modules/lang/python/config.el +++ b/modules/lang/python/config.el @@ -342,16 +342,8 @@ ;; ;;; LSP -(eval-when! (and (modulep! +lsp) - (not (modulep! :tools lsp +eglot))) - - (use-package! lsp-python-ms - :unless (modulep! +pyright) - :after lsp-mode - :preface - (after! python - (setq lsp-python-ms-python-executable-cmd python-shell-interpreter))) - - (use-package! lsp-pyright - :when (modulep! +pyright) - :after lsp-mode)) +(use-package! lsp-pyright + :when (modulep! +lsp) + :when (modulep! +pyright) + :when (not (modulep! :tools lsp +eglot)) + :after lsp-mode) diff --git a/modules/lang/python/packages.el b/modules/lang/python/packages.el index 12eaf1a8c..5fefb1d85 100644 --- a/modules/lang/python/packages.el +++ b/modules/lang/python/packages.el @@ -11,9 +11,8 @@ ;; LSP (when (modulep! +lsp) (unless (modulep! :tools lsp +eglot) - (if (modulep! +pyright) - (package! lsp-pyright :pin "cc6df06aeaee3053eb800a24193483387b7b545b") - (package! lsp-python-ms :pin "7bda327bec7b219d140c34dab4b1e1fbd41bc516")))) + (when (modulep! +pyright) + (package! lsp-pyright :pin "cc6df06aeaee3053eb800a24193483387b7b545b")))) ;; Programming environment (package! anaconda-mode :pin "79fa9b4d2bda9f69857aeffb30c75276848a2810") From 528986110921c3032dcabc8f9fee28a95df055f7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 16:59:41 -0400 Subject: [PATCH 05/33] refactor(workspaces): +workspace/delete: rename to +workspace/kill To be more consistent with other uses of the verb in the Emacs ecosystem. Also done in preparation for a new +workspaces/delete command for #7869. Ref: #7869 --- modules/app/calendar/autoload.el | 2 +- modules/app/irc/autoload/irc.el | 2 +- modules/app/rss/autoload.el | 2 +- modules/config/default/+emacs-bindings.el | 2 +- modules/config/default/+evil-bindings.el | 4 ++-- modules/email/mu4e/autoload/email.el | 2 +- modules/email/notmuch/autoload.el | 2 +- modules/ui/workspaces/README.org | 4 ++-- modules/ui/workspaces/autoload/evil.el | 4 ++-- modules/ui/workspaces/autoload/workspaces.el | 24 ++++++++++---------- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/app/calendar/autoload.el b/modules/app/calendar/autoload.el index 3dc9efb1e..155d04f5b 100644 --- a/modules/app/calendar/autoload.el +++ b/modules/app/calendar/autoload.el @@ -36,7 +36,7 @@ (interactive) (if (modulep! :ui workspaces) (when (+workspace-exists-p +calendar-workspace-name) - (+workspace/delete +calendar-workspace-name)) + (+workspace/kill +calendar-workspace-name)) (when (window-configuration-p +calendar--wconf) (set-window-configuration +calendar--wconf)) (setq +calendar--wconf nil)) diff --git a/modules/app/irc/autoload/irc.el b/modules/app/irc/autoload/irc.el index 16bca925b..bba6d1e3e 100644 --- a/modules/app/irc/autoload/irc.el +++ b/modules/app/irc/autoload/irc.el @@ -60,7 +60,7 @@ workspace for it." (mapc #'kill-buffer (doom-buffers-in-mode 'circe-mode (buffer-list) t)) (when (modulep! :ui workspaces) (when (equal (+workspace-current-name) +irc--workspace-name) - (+workspace/delete +irc--workspace-name))))) + (+workspace/kill +irc--workspace-name))))) ;;;###autoload (defun +irc/jump-to-channel (&optional this-server) diff --git a/modules/app/rss/autoload.el b/modules/app/rss/autoload.el index 0a651b68c..c1717afdb 100644 --- a/modules/app/rss/autoload.el +++ b/modules/app/rss/autoload.el @@ -109,7 +109,7 @@ (mapc #'kill-buffer show-buffers)) (if (and (modulep! :ui workspaces) (+workspace-exists-p +rss-workspace-name)) - (+workspace/delete +rss-workspace-name) + (+workspace/kill +rss-workspace-name) (when (window-configuration-p +rss--wconf) (set-window-configuration +rss--wconf)) (setq +rss--wconf nil) diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 18f45574f..1b0394eea 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -412,7 +412,7 @@ :desc "Rename workspace" "r" #'+workspace/rename :desc "Create workspace" "c" #'+workspace/new :desc "Create named workspace" "C" #'+workspace/new-named - :desc "Delete workspace" "k" #'+workspace/delete + :desc "Delete workspace" "k" #'+workspace/kill :desc "Save workspace" "S" #'+workspace/save :desc "Switch to other workspace" "o" #'+workspace/other :desc "Switch to left workspace" "p" #'+workspace/switch-left diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 56f847c18..08b00882c 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -379,8 +379,8 @@ :desc "New named workspace" "N" #'+workspace/new-named :desc "Load workspace from file" "l" #'+workspace/load :desc "Save workspace to file" "s" #'+workspace/save - :desc "Delete session" "x" #'+workspace/kill-session - :desc "Delete this workspace" "d" #'+workspace/delete + :desc "Kill session" "x" #'+workspace/kill-session + :desc "Kill this workspace" "d" #'+workspace/kill :desc "Rename workspace" "r" #'+workspace/rename :desc "Restore last session" "R" #'+workspace/restore-last-session :desc "Next workspace" "]" #'+workspace/switch-right diff --git a/modules/email/mu4e/autoload/email.el b/modules/email/mu4e/autoload/email.el index f9efcbf74..9fe270bd0 100644 --- a/modules/email/mu4e/autoload/email.el +++ b/modules/email/mu4e/autoload/email.el @@ -365,7 +365,7 @@ When otherwise called, open a dired buffer and enable `dired-mu4e-attach-ctrl-c- ;; (prolusion-mail-hide) (cond ((and (modulep! :ui workspaces) (+workspace-exists-p +mu4e-workspace-name)) - (+workspace/delete +mu4e-workspace-name)) + (+workspace/kill +mu4e-workspace-name)) (+mu4e--old-wconf (set-window-configuration +mu4e--old-wconf) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index dfebce7fa..b7a27834d 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -32,7 +32,7 @@ ;; (+popup/close (get-buffer-window "*notmuch-hello*")) (doom-kill-matching-buffers "^\\*notmuch") (when (modulep! :ui workspaces) - (+workspace/delete +notmuch-workspace-name))) + (+workspace/kill +notmuch-workspace-name))) (defun +notmuch-get-sync-command () "Return a shell command string to synchronize your notmuch mail with." diff --git a/modules/ui/workspaces/README.org b/modules/ui/workspaces/README.org index d99f4ea1b..d15137fd5 100644 --- a/modules/ui/workspaces/README.org +++ b/modules/ui/workspaces/README.org @@ -86,7 +86,7 @@ in [[../../editor/evil/+commands.el][config/default/+evil-commands.el]]). | ~+workspace/other~ | [[kbd:][SPC TAB `]] | Switch to last workspace | | ~+workspace/switch-left~ | [[kbd:][SPC TAB []] / [[kbd:][[ w]] / [[kbd:][gT]] | Switch to previous workspace | | ~+workspace/switch-right~ | [[kbd:][SPC TAB ]]] / [[kbd:][] w]] / [[kbd:][gt]] | Switch to next workspace | -| ~+workspace/delete~ | [[kbd:][SPC TAB d]] | Delete the current workspace | +| ~+workspace/kill~ | [[kbd:][SPC TAB d]] | Delete the current workspace | | ~+workspace/kill-session~ | [[kbd:][SPC TAB x]] / [[kbd:][:sclear]] | Clears the current session (kills all windows and buffers) | * TODO Configuration @@ -120,6 +120,6 @@ in [[../../editor/evil/+commands.el][config/default/+evil-commands.el]]). + ~+workspace-save-session NAME~ + ~+workspace-new NAME~ + ~+workspace-rename NAME NEW-NAME~ -+ ~+workspace-delete NAME &optional INHIBIT-KILL-P~ ++ ~+workspace-kill NAME &optional INHIBIT-KILL-P~ + ~+workspace-switch NAME &optional AUTO-CREATE-P~ + ~+workspace-protected-p NAME~ -> bool diff --git a/modules/ui/workspaces/autoload/evil.el b/modules/ui/workspaces/autoload/evil.el index 32e559d5a..bb904e540 100644 --- a/modules/ui/workspaces/autoload/evil.el +++ b/modules/ui/workspaces/autoload/evil.el @@ -23,8 +23,8 @@ ;;;###autoload (autoload '+workspace:delete "ui/workspaces/autoload/evil" nil t) (evil-define-command +workspace:delete () - "Ex wrapper around `+workspace/delete'." - (interactive) (+workspace/delete (+workspace-current-name))) + "Ex wrapper around `+workspace/kill'." + (interactive) (+workspace/kill (+workspace-current-name))) ;;;###autoload (autoload '+workspace:switch-next "ui/workspaces/autoload/evil" nil t) (evil-define-command +workspace:switch-next (&optional count) diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index 4cca0c7a8..d83c9d5da 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -150,10 +150,10 @@ success, nil otherwise." (persp-rename new-name (+workspace-get name))) ;;;###autoload -(defun +workspace-delete (workspace &optional inhibit-kill-p) - "Delete the workspace denoted by WORKSPACE, which can be the name of a perspective -or its hash table. If INHIBIT-KILL-P is non-nil, don't kill this workspace's -buffers." +(defun +workspace-kill (workspace &optional inhibit-kill-p) + "Kill the workspace denoted by WORKSPACE, which can be the name of a +perspective or its hash table. If INHIBIT-KILL-P is non-nil, don't kill this +workspace's buffers." (unless (stringp workspace) (setq workspace (persp-name workspace))) (when (+workspace--protected-p workspace) @@ -231,14 +231,14 @@ workspace." ('error (+workspace-error ex t)))) ;;;###autoload -(defun +workspace/delete (name) +(defun +workspace/kill (name) "Delete this workspace. If called with C-u, prompts you for the name of the workspace to delete." (interactive (let ((current-name (+workspace-current-name))) (list (if current-prefix-arg - (completing-read (format "Delete workspace (default: %s): " current-name) + (completing-read (format "Kill workspace (default: %s): " current-name) (+workspace-list-names) nil nil nil nil current-name) current-name)))) @@ -250,9 +250,9 @@ workspace to delete." (cond ((delq (selected-frame) (persp-frames-with-persp (get-frame-persp))) (user-error "Can't close workspace, it's visible in another frame")) ((not (equal (+workspace-current-name) name)) - (+workspace-delete name)) + (+workspace-kill name)) ((cdr workspaces) - (+workspace-delete name) + (+workspace-kill name) (+workspace-switch (if (+workspace-exists-p +workspace--last) +workspace--last @@ -262,7 +262,7 @@ workspace to delete." (t (+workspace-switch +workspaces-main t) (unless (string= (car workspaces) +workspaces-main) - (+workspace-delete name)) + (+workspace-kill name)) (doom/kill-all-buffers (doom-buffer-list)))) (+workspace-message (format "Deleted '%s' workspace" name) 'success))) ('error (+workspace-error ex t)))) @@ -275,7 +275,7 @@ workspace to delete." (persps (length (+workspace-list-names))) (buffers 0)) (let ((persp-autokill-buffer-on-remove t)) - (unless (cl-every #'+workspace-delete (+workspace-list-names)) + (unless (cl-every #'+workspace-kill (+workspace-list-names)) (+workspace-error "Could not clear session"))) (+workspace-switch +workspaces-main t) (setq buffers (doom/kill-all-buffers (buffer-list))) @@ -401,7 +401,7 @@ the next." (let ((frame-persp (frame-parameter nil 'workspace))) (if (string= frame-persp (+workspace-current-name)) (delete-frame) - (+workspace/delete current-persp-name)))) + (+workspace/kill current-persp-name)))) ((+workspace-error "Can't delete last workspace" t))))))) @@ -490,7 +490,7 @@ created." (setq frame (selected-frame))) (let ((frame-persp (frame-parameter frame 'workspace))) (when (string= frame-persp (+workspace-current-name)) - (+workspace/delete frame-persp))))) + (+workspace/kill frame-persp))))) ;;;###autoload (defun +workspaces-associate-frame-fn (frame &optional _new-frame-p) From f44309cb635b4d3fd01080096477a02f40e5d660 Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Fri, 5 Jul 2024 17:57:40 -0500 Subject: [PATCH 06/33] fix(default): replace void function +yas-active-p --- modules/config/default/+evil-bindings.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 08b00882c..5564192ec 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -46,7 +46,8 @@ (doom-lookup-key (kbd "TAB") overriding-terminal-local-map)) cmd) ,@(when (modulep! :editor snippets) - '(((+yas-active-p) + '(((memq (bound-and-true-p yas--active-field-overlay) + (overlays-in (1- (point)) (1+ (point)))) #'yas-next-field-or-maybe-expand) ((yas-maybe-expand-abbrev-key-filter 'yas-expand) #'yas-expand))) From 6e69b29084e17afb2c92a321f9f26dc10dd71faf Mon Sep 17 00:00:00 2001 From: woochica Date: Sat, 6 Jul 2024 00:58:18 +0200 Subject: [PATCH 07/33] fix(lib): reset font size before setting big font mode Calling (doom-adjust-font-size 1) repeatedly would keep increase the font size because an increment is passed. When loading themes, the doom-big-font-mode minor mode gets loaded again therefore it causes the font to get increased. Fix: #7845 --- lisp/lib/fonts.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/lib/fonts.el b/lisp/lib/fonts.el index 04f289f12..250eb09f9 100644 --- a/lisp/lib/fonts.el +++ b/lisp/lib/fonts.el @@ -177,4 +177,5 @@ Also resizees `doom-variable-pitch-font' and `doom-serif-font'." (font-get (doom-normalize-font doom-big-font) :size)) t `((doom-font . ,doom-big-font))) ;; Resize the current font + (doom-adjust-font-size nil) (doom-adjust-font-size (if doom-big-font-mode doom-big-font-increment)))) From b767beaca61efa4413b7844259f651de1c434659 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 19:35:40 -0400 Subject: [PATCH 08/33] fix(lib): don't call doom-adjust-font-size twice When doom-big-font-mode is deactivated. --- lisp/lib/fonts.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/lib/fonts.el b/lisp/lib/fonts.el index 250eb09f9..139e153d4 100644 --- a/lisp/lib/fonts.el +++ b/lisp/lib/fonts.el @@ -178,4 +178,5 @@ Also resizees `doom-variable-pitch-font' and `doom-serif-font'." t `((doom-font . ,doom-big-font))) ;; Resize the current font (doom-adjust-font-size nil) - (doom-adjust-font-size (if doom-big-font-mode doom-big-font-increment)))) + (when doom-big-font-mode + (doom-adjust-font-size doom-big-font-increment)))) From 2bfb7821b6e0474d9f818adff8ee30c6ecf9703b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 20:05:38 -0400 Subject: [PATCH 09/33] refactor(evil): +evil--window-swap: no-op if on edge Also error checks DIRECTION, just in case. --- modules/editor/evil/autoload/evil.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/editor/evil/autoload/evil.el b/modules/editor/evil/autoload/evil.el index 0f602752e..dfb0748ee 100644 --- a/modules/editor/evil/autoload/evil.el +++ b/modules/editor/evil/autoload/evil.el @@ -44,28 +44,32 @@ replacing its contents." If there are no windows there and there is only one window, split in that direction and place this window there. If there are no windows and this isn't the only window, use evil-window-move-* (e.g. `evil-window-move-far-left')." + (unless (memq direction '(left right up down)) + (user-error "Invalid direction: %s" direction)) (when (window-dedicated-p) (user-error "Cannot swap a dedicated window")) (let* ((this-window (selected-window)) - (this-buffer (current-buffer)) (that-window (window-in-direction direction nil this-window)) (that-buffer (window-buffer that-window))) (when (or (minibufferp that-buffer) (window-dedicated-p this-window)) (setq that-buffer nil that-window nil)) (if (not (or that-window (one-window-p t))) - (funcall (pcase direction - ('left #'evil-window-move-far-left) - ('right #'evil-window-move-far-right) - ('up #'evil-window-move-very-top) - ('down #'evil-window-move-very-bottom))) + (if (and (window-at-side-p + this-window (pcase direction ('up 'top) ('down 'bottom) (_ direction))) + (not (cl-loop for dir in (if (memq direction '(left right)) + '(up down) '(left right)) + if (window-in-direction dir nil this-window) + return t))) + (user-error "Window is already at the edge") + (call-interactively + (pcase direction + ('left #'evil-window-move-far-left) + ('right #'evil-window-move-far-right) + ('up #'evil-window-move-very-top) + ('down #'evil-window-move-very-bottom)))) (unless that-window - (setq that-window - (split-window this-window nil - (pcase direction - ('up 'above) - ('down 'below) - (_ direction)))) + (setq that-window (split-window this-window nil direction)) (with-selected-window that-window (switch-to-buffer (doom-fallback-buffer))) (setq that-buffer (window-buffer that-window))) From 7bb5df4cd4ae3a0916616dd7e50566b3caa9c931 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Jul 2024 20:06:28 -0400 Subject: [PATCH 10/33] fix(zig): update zls download URL Fix: #7873 Ref: zigtools/zls#1879 --- modules/tools/lsp/+lsp.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/tools/lsp/+lsp.el b/modules/tools/lsp/+lsp.el index ecb2907d8..8ea2eda5e 100644 --- a/modules/tools/lsp/+lsp.el +++ b/modules/tools/lsp/+lsp.el @@ -54,6 +54,10 @@ Can be a list of backends; accepts any value `company-backends' accepts.") lsp-xml-jar-file (expand-file-name "org.eclipse.lsp4xml-0.3.0-uber.jar" lsp-server-install-dir) lsp-groovy-server-file (expand-file-name "groovy-language-server-all.jar" lsp-server-install-dir)) + ;; REVIEW: Remove when zigtools/zls#1879 is resolved. + (unless (featurep :system 'windows) + (setq lsp-zig-download-url-format "https://github.com/zigtools/zls/releases/latest/download/zls-%s-%s.tar.xz")) + (add-hook! 'doom-escape-hook (defun +lsp-signature-stop-maybe-h () "Close the displayed `lsp-signature'." From b0e16dc24332f7334a8b2aee9cad342079a63676 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 2 Jul 2024 02:19:26 -0400 Subject: [PATCH 11/33] fix(org): reload org-mode in half-loaded capture buffers Fix: #5411 --- modules/lang/org/config.el | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 608164188..84e87380f 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -767,10 +767,9 @@ mutating hooks on exported output, like formatters." (defun +org--restart-mode-h () "Restart `org-mode', but only once." + (remove-hook 'doom-switch-buffer-hook #'+org--restart-mode-h 'local) (quiet! (org-mode-restart)) (delq! (current-buffer) org-agenda-new-buffers) - (remove-hook 'doom-switch-buffer-hook #'+org--restart-mode-h - 'local) (run-hooks 'find-file-hook)) (add-hook! 'org-agenda-finalize-hook @@ -796,16 +795,16 @@ can grow up to be fully-fledged org-mode buffers." (add-hook 'doom-switch-buffer-hook #'+org--restart-mode-h nil 'local)))))) - (defadvice! +org--restart-mode-before-indirect-buffer-a (base-buffer &rest _) + (defadvice! +org--restart-mode-before-indirect-buffer-a (&optional buffer _) "Restart `org-mode' in buffers in which the mode has been deferred (see `+org-defer-mode-in-agenda-buffers-h') before they become the base buffer for an indirect buffer. This ensures that the buffer is fully functional not only when the *user* visits it, but also when some code interacts with it via an indirect buffer as done, e.g., by `org-capture'." - :before #'make-indirect-buffer - (with-current-buffer base-buffer - (when (memq #'+org--restart-mode-h doom-switch-buffer-hook) - (+org--restart-mode-h)))) + :before #'org-capture-get-indirect-buffer + (with-current-buffer (or buffer (current-buffer)) + (when (memq #'+org--restart-mode-h doom-switch-buffer-hook) + (+org--restart-mode-h)))) (defvar recentf-exclude) (defadvice! +org--optimize-backgrounded-agenda-buffers-a (fn file) From 8072762de8dd9bf43651a8676642081d92027782 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 19:54:55 -0400 Subject: [PATCH 12/33] refactor(format): redesign module Rather than wrap Apheleia in custom formatting logic, I now use Apheleia's own machinary to integrate into LSP and Eglot, which is less complexity to maintain. It also makes settings +format-with a more reliable option for per-project or per-file configuration. This also adds a +format/org-src-block command, which I'll incorporate into the org module in a follow-up commit. Ref: #7685 --- modules/editor/format/autoload/format.el | 114 +++++++--------------- modules/editor/format/config.el | 118 +++++++++++------------ 2 files changed, 90 insertions(+), 142 deletions(-) diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index d0379c6a7..5428d8ec4 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -6,6 +6,9 @@ (skip-chars-forward " \t\n") (current-indentation))) +;;;###autoload (autoload 'apheleia--get-formatters "apheleia-formatters") + +;;;###autoload (defun +format-region (start end &optional callback) "Format from START to END with `apheleia'." (when-let* ((command (apheleia--get-formatters @@ -42,15 +45,16 @@ (lambda () (with-current-buffer formatted-buffer (when (> indent 0) - ;; restore indentation without affecting new - ;; indentation + ;; restore indentation without affecting new indentation (indent-rigidly (point-min) (point-max) (max 0 (- indent (+format--current-indentation))))) (set-buffer-modified-p nil)) (with-current-buffer cur-buffer (delete-region start end) - (insert-buffer-substring-no-properties formatted-buffer) - (when callback (funcall callback)) + (goto-char start) + (save-excursion + (insert-buffer-substring-no-properties formatted-buffer) + (when callback (funcall callback))) (kill-buffer formatted-buffer))))))) @@ -58,22 +62,17 @@ ;;; Commands ;;;###autoload -(defun +format/buffer (&optional arg) - "Reformat the current buffer using LSP or `format-all-buffer'." - (interactive "P") - (or (run-hook-with-args-until-success '+format-functions (point-min) (point-max) 'buffer) - (call-interactively #'apheleia-format-buffer))) +(defalias '+format/buffer #'apheleia-format-buffer) ;;;###autoload -(defun +format/region (beg end &optional arg) +(defun +format/region (beg end &optional _arg) "Runs the active formatter on the lines within BEG and END. WARNING: this may not work everywhere. It will throw errors if the region contains a syntax error in isolation. It is mostly useful for formatting snippets or single lines." (interactive "rP") - (or (run-hook-with-args-until-success '+format-functions beg end 'region) - (+format-region beg end))) + (+format-region beg end)) ;;;###autoload (defun +format/region-or-buffer () @@ -85,72 +84,29 @@ is selected)." #'+format/region #'+format/buffer))) - -;; -;;; Specialized formatters - ;;;###autoload -(defun +format-with-lsp-fn (beg end op) - "Format the region/buffer using any available lsp-mode formatter. - -Does nothing if `+format-with-lsp' is nil or the active server doesn't support -the requested feature." - (and +format-with-lsp - (bound-and-true-p lsp-mode) - (pcase op - ('buffer (condition-case _ - ;; Avoid lsp-feature? checks for this, since - ;; `lsp-format-buffer' does its own, and allows clients - ;; without formatting support (but with rangeFormatting, - ;; for some reason) to work. - (always (lsp-format-buffer)) - ('lsp-capability-not-supported nil))) - ('region (if (lsp-feature? "textDocument/rangeFormatting") - (always (lsp-format-region beg end)))) - (_ (error "Invalid formatter operation: %s" op))))) - -;;;###autoload -(defun +format-with-eglot-fn (beg end op) - "Format the region/buffer using any available eglot formatter. - -Does nothing if `+format-with-lsp' is nil or the active server doesn't support -the requested feature." - (and +format-with-lsp - (bound-and-true-p eglot--managed-mode) - (pcase op - ('buffer (if (eglot--server-capable :documentFormattingProvider) - (always (eglot-format-buffer)))) - ('region (if (eglot--server-capable :documentRangeFormattingProvider) - (always (eglot-format beg end)))) - (_ (error "Invalid formatter operation: %s" op))))) - -;;;###autoload -(defun +format-in-org-src-blocks-fn (beg end _op) - "Reformat org src blocks with apheleia as if they were independent buffers." - (when (derived-mode-p 'org-mode) - (goto-char beg) - (while (re-search-forward org-babel-src-block-regexp end t) - (let* ((element (org-element-at-point)) - (block-beg (save-excursion - (goto-char (org-babel-where-is-src-block-head element)) - (line-beginning-position 2))) - (block-end (save-excursion - (goto-char (org-element-property :end element)) - (skip-chars-backward " \t\n") - (line-beginning-position))) - (beg (max beg block-beg)) - (end (min end block-end)) - (lang (org-element-property :language element)) - (major-mode (org-src-get-lang-mode lang))) +(defun +format/org-block (point) + "Reformat the org src block at POINT with a mode approriate formatter." + (interactive (list (point))) + (unless (derived-mode-p 'org-mode) + (user-error "Not an org-mode buffer!")) + (let ((element (org-element-at-point point))) + (unless (org-in-src-block-p nil element) + (user-error "Not in an org src block")) + (cl-destructuring-bind (beg end _) (org-src--contents-area element) + (let* ((lang (org-element-property :language element)) + (mode (org-src-get-lang-mode lang))) (save-excursion - (if (eq major-mode 'org-mode) - (user-error "Cannot reformat an org src block in org-mode") - ;; Determine formatter based on language and format the region - (let ((formatter (apheleia--get-formatters 'interactive))) - (unless formatter - (setq formatter (apheleia--get-formatters 'prompt)) - (unless formatter - (user-error "No formatter configured for language: %s" lang))) - (let ((apheleia-formatter formatter)) - (+format-region beg end))))))) - t)) + (if (provided-mode-derived-p mode 'org-mode) + (user-error "Cannot reformat an org-mode or org-derived src block") + (let* ((major-mode mode) + (after-change-functions + ;; HACK: Silence excessive and unhelpful warnings about + ;; 'org-element-at-point being used in non-org-mode + ;; buffers'. + (remq 'org-indent-refresh-maybe after-change-functions)) + (apheleia-formatter + (or (apheleia--get-formatters 'interactive) + (apheleia--get-formatters 'prompt) + (user-error "No formatter configured for language: %s" lang)))) + (+format-region beg end)))))))) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 8f4826c8d..76ca73ae6 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -1,87 +1,79 @@ ;;; editor/format/config.el -*- lexical-binding: t; -*- -(defvar +format-on-save-disabled-modes +(defcustom +format-on-save-disabled-modes '(sql-mode ; sqlformat is currently broken tex-mode ; latexindent is broken latex-mode org-msg-edit-mode) ; doesn't need a formatter "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 - "If non-nil, the leading indentation is preserved when formatting the whole -buffer. This is particularly useful for partials. +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." + :type '(list symbol)) -Indentation is always preserved when formatting regions.") - -(defvar +format-with-lsp t +(defcustom +format-with-lsp t "If non-nil, format with LSP formatter if it's available. +LSP formatter is provided by either `lsp-mode' or `eglot'. + This can be set buffer-locally with `setq-hook!' to disable LSP formatting in -select buffers. -This has no effect on the +onsave flag, apheleia will always be used there.") +select buffers, from a project's .dir-locals.el file, or as a file-local +variable." + :type 'boolean + :safe 'booleanp) -(defvaralias '+format-with 'apheleia-formatter - "Set this to explicitly use a certain formatter for the current buffer.") +(defvaralias '+format-with 'apheleia-formatter) -(defvar +format-functions - '(+format-in-org-src-blocks-fn - +format-with-lsp-fn - +format-with-eglot-fn) - "A list of functions to run when formatting a buffer or region. - -Each function is given three arguments: the starting point, end point, and a -symbol indicating the type of operation being requested (as a symbol: either -`region' or `buffer'). - -The first function to return non-nil will abort all functions after it, -including Apheleia itself.") ;; ;;; Bootstrap -(when (modulep! +onsave) - (add-hook 'doom-first-file-hook #'apheleia-global-mode)) - -(defun +format-maybe-inhibit-h () - "Check if formatting should be disabled for current buffer. +(use-package! apheleia + :defer t + :init + (when (modulep! +onsave) + (add-hook 'doom-first-file-hook #'apheleia-global-mode) + ;; apheleia autoloads `apheleia-inhibit-functions' so it will be immediately + ;; available to mutate early. + (add-hook! 'apheleia-inhibit-functions + (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))))) + (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 + :config (add-to-list 'doom-debug-variables '(apheleia-log-only-errors . nil)) - (when (modulep! +onsave) - (add-to-list 'apheleia-inhibit-functions #'+format-maybe-inhibit-h))) + ;; Use the formatter provided by lsp-mode and eglot, if they are available and + ;; `+format-with-lsp' is non-nil. + (cond ((modulep! :tools lsp +eglot) + (add-to-list 'apheleia-formatters '(eglot . +format-eglot-buffer)) + (add-hook 'eglot-managed-hook #'+format-toggle-eglot-formatter-h)) + ((modulep! :tools lsp) + (add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)) + (add-hook 'lsp-configure-hook #'+format-enable-lsp-formatter-h) + (add-hook 'lsp-unconfigure-hook #'+format-disable-lsp-formatter-h))) + (defadvice! +format--inhibit-reformat-on-prefix-arg-a (orig-fn &optional arg) + "Make it so \\[save-buffer] with prefix arg inhibits reformatting." + :around #'save-buffer + (let ((apheleia-mode (and apheleia-mode (memq arg '(nil 1))))) + (funcall orig-fn))) -;; -;;; Hacks - -(defadvice! +format--inhibit-reformat-on-prefix-arg-a (orig-fn &optional arg) - "Make it so \\[save-buffer] with prefix arg inhibits reformatting." - :around #'save-buffer - (let ((apheleia-mode (and apheleia-mode (memq arg '(nil 1))))) - (funcall orig-fn))) - -(add-hook! - 'apheleia-post-format-hook - ;; HACK `web-mode' doesn't update syntax highlighting after arbitrary buffer - ;; modifications, so we must trigger refontification manually. - (defun +format--fix-web-mode-fontification-h () - (when (eq major-mode 'web-mode) - (setq web-mode-fontification-off nil) - (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) - (save-excursion - (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) - - (defun +format--refresh-vc-gutter-h () - (when (fboundp '+vc-gutter-update-h) - (+vc-gutter-update-h)))) + ;; HACK: Apheleia suppresses notifications that the current buffer has + ;; changed, so plugins that listen for them need to be manually informed: + (add-hook! + 'apheleia-post-format-hook + (defun +format--update-web-mode-h () + (when (eq major-mode 'web-mode) + (setq web-mode-fontification-off nil) + (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) + (save-excursion + (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) + (defun +format--update-vc-gutter-h () + (when (fboundp '+vc-gutter-update-h) + (+vc-gutter-update-h))))) From f6e65c4010c8507e93dfc689feb4a65d4d2498b7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 19:58:27 -0400 Subject: [PATCH 13/33] feat(org): add +org/reformat-at-point command A DWIM command to reformat a src block, table, or paragraph at point. Ref: #7685 --- modules/lang/org/autoload/org.el | 18 ++++++++++++++++++ modules/lang/org/config.el | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/lang/org/autoload/org.el b/modules/lang/org/autoload/org.el index f1c033344..87085b434 100644 --- a/modules/lang/org/autoload/org.el +++ b/modules/lang/org/autoload/org.el @@ -334,6 +334,24 @@ see how ARG affects this command." (org-clock-in)) ((org-clock-in-last arg)))) +;;;###autoload +(defun +org/reformat-at-point () + "Reformat the element at point. + +If in an org src block, invokes `+format/org-block' if the ':editor format' + module is enabled. +If in an org table, realign the cells with `org-table-align'. +Otherwise, falls back to `org-fill-paragraph' to reflow paragraphs." + (interactive) + (let ((element (org-element-at-point))) + (cond ((org-in-src-block-p nil element) + (unless (modulep! :editor format) + (user-error ":editor format module is disabled, ignoring reformat...")) + (call-interactively #'+format/org-block)) + ((org-at-table-p) + (save-excursion (org-table-align))) + ((call-interactively #'org-fill-paragraph))))) + ;;; Folds ;;;###autoload diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 84e87380f..d344d57b1 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -1222,7 +1222,7 @@ between the two." :m "[l" #'org-previous-link :m "]c" #'org-babel-next-src-block :m "[c" #'org-babel-previous-src-block - :n "gQ" #'org-fill-paragraph + :n "gQ" #'+org/reformat-at-point ;; sensible vim-esque folding keybinds :n "za" #'+org/toggle-fold :n "zA" #'org-shifttab From cc358a60c41e60d0204659d3593cb263cfddae8e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 20:07:14 -0400 Subject: [PATCH 14/33] refactor(org): remove unused hooks These hooks had the potential to be too expensive (in larger Org files) to be enabled by default. --- modules/lang/org/autoload/org-tables.el | 9 --------- modules/lang/org/autoload/org.el | 7 ------- modules/lang/org/config.el | 5 +---- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/modules/lang/org/autoload/org-tables.el b/modules/lang/org/autoload/org-tables.el index f231562cd..8ac85d087 100644 --- a/modules/lang/org/autoload/org-tables.el +++ b/modules/lang/org/autoload/org-tables.el @@ -53,15 +53,6 @@ re-align the table if necessary. (Necessary because org-mode has a (if org-table-may-need-update (org-table-align)) (goto-char pt)))) -;;;###autoload -(defun +org-enable-auto-reformat-tables-h () - "Realign tables & update formulas when exiting insert mode (`evil-mode'). -Meant for `org-mode-hook'." - (when (featurep 'evil) - (add-hook 'evil-insert-state-exit-hook #'+org-realign-table-maybe-h nil t) - (add-hook 'evil-replace-state-exit-hook #'+org-realign-table-maybe-h nil t) - (advice-add #'evil-replace :after #'+org-realign-table-maybe-a))) - ;;;###autoload (defun +org-delete-backward-char-and-realign-table-maybe-h () "Ensure deleting characters with backspace doesn't deform the table cell." diff --git a/modules/lang/org/autoload/org.el b/modules/lang/org/autoload/org.el index 87085b434..499b1dddb 100644 --- a/modules/lang/org/autoload/org.el +++ b/modules/lang/org/autoload/org.el @@ -538,10 +538,3 @@ All my (performant) foldings needs are met between this and `org-show-subtree' (when org-occur-highlights (org-remove-occur-highlights) t)) - -;;;###autoload -(defun +org-enable-auto-update-cookies-h () - "Update statistics cookies when saving or exiting insert mode (`evil-mode')." - (when (bound-and-true-p evil-local-mode) - (add-hook 'evil-insert-state-exit-hook #'org-update-parent-todo-statistics nil t)) - (add-hook 'before-save-hook #'org-update-parent-todo-statistics nil t)) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index d344d57b1..1c9bb3f06 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -1305,10 +1305,7 @@ between the two." ;; `org-indent-mode', so we turn off show-paren-mode altogether #'doom-disable-show-paren-mode-h ;; disable `show-trailing-whitespace'; shows a lot of false positives - #'doom-disable-show-trailing-whitespace-h - ;; #'+org-enable-auto-reformat-tables-h - ;; #'+org-enable-auto-update-cookies-h - ) + #'doom-disable-show-trailing-whitespace-h) (add-hook! 'org-load-hook #'+org-init-org-directory-h From 1cc83dce358afc729e7b0db0b304d903155ab928 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 20:13:38 -0400 Subject: [PATCH 15/33] fix(cli): wrong-number-of-args error on choosing 'abort' Fix: #7917 --- lisp/cli/packages.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/cli/packages.el b/lisp/cli/packages.el index d6ab5572e..4167fd13c 100644 --- a/lisp/cli/packages.el +++ b/lisp/cli/packages.el @@ -769,7 +769,7 @@ original state.") (let ((doom-output-indent 0)) (terpri) (print! (warn "Aborted"))) - (doom-cli--exit 1)) + (doom-cli--exit 1 doom-cli--context)) (nreverse options))) (prompt (format! "How to proceed? (%s%s) " From d7075b24205ad4e85f1855c23d7efa47878fa7f4 Mon Sep 17 00:00:00 2001 From: 132ikl <132@ikl.sh> Date: Sat, 6 Jul 2024 20:16:59 -0400 Subject: [PATCH 16/33] tweak(lib): doom-project-find-file: use transient project If DIR is not a project and does not have root markers, create a transient project instead. This ensures that `project-find-file-in`, and by extension vertico, is still used in non-project directories instead of falling back to `find-file` Ref: 1b0af3bfc747 --- lisp/lib/projects.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/lib/projects.el b/lisp/lib/projects.el index a1655f314..16c592e65 100644 --- a/lisp/lib/projects.el +++ b/lisp/lib/projects.el @@ -152,11 +152,12 @@ If DIR is not a project, it will be indexed (but not cached)." ((and (bound-and-true-p ivy-mode) (fboundp 'counsel-file-jump)) (call-interactively #'counsel-file-jump)) - ((when-let ((pr (project-current nil dir))) - (project-find-file-in nil nil pr))) ((and (bound-and-true-p helm-mode) (fboundp 'helm-find-files)) (call-interactively #'helm-find-files)) + ((when-let ((project-current-directory-override t) + (pr (project-current t dir))) + (project-find-file-in nil nil pr))) ((call-interactively #'find-file))))) ;;;###autoload From d330642c2e6b0f443a2cfccb4827c9df25ee3fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 6 Jul 2024 20:31:40 -0400 Subject: [PATCH 17/33] feat(literate): add +literate/find-heading command A command for jumping to an Org heading in your literate org config file. Close: #7716 --- modules/config/default/+evil-bindings.el | 2 ++ modules/config/literate/autoload.el | 35 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 5564192ec..f6c32c68f 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -485,6 +485,8 @@ :desc "Browse emacs.d" "E" #'doom/browse-in-emacsd :desc "Find file" "f" #'find-file :desc "Find file from here" "F" #'+default/find-file-under-here + (:when (modulep! :config literate) + :desc "Open heading in literate config" "h" #'+literate/find-heading) :desc "Locate file" "l" #'locate :desc "Find file in private config" "p" #'doom/find-file-in-private-config :desc "Browse private config" "P" #'doom/open-private-config diff --git a/modules/config/literate/autoload.el b/modules/config/literate/autoload.el index 0da5f0867..7ea7996b3 100644 --- a/modules/config/literate/autoload.el +++ b/modules/config/literate/autoload.el @@ -106,6 +106,41 @@ ;;;###autoload (defalias '+literate/reload #'doom/reload) +(defun +literate--flatten-imenu-index (index &optional prefix) + "Flatten an org-mode imenu index." + (let ((flattened '())) + (dolist (item index flattened) + (let* ((name (propertize (car item) 'face (intern (format "org-level-%d" (if prefix (+ 2 (cl-count ?/ prefix)) 1))))) + (prefix (if prefix (concat prefix "/" name) name))) + (if (imenu--subalist-p item) + (setq flattened (append flattened (+literate--flatten-imenu-index (cdr item) prefix))) + (push (cons prefix (cdr item)) flattened)))) + (nreverse flattened))) + +(defvar imenu-auto-rescan) +;;;###autoload +(defun +literate/find-heading (&optional level) + "Jump to a heading in your literate org config file." + (interactive "P") + (let* ((buffer (or (find-buffer-visiting +literate-config-file) + (find-file-noselect +literate-config-file t)))) + (with-current-buffer buffer + (let* ((imenu-auto-rescan t) + (org-imenu-depth (or level 8)) + (index (+literate--flatten-imenu-index (imenu--make-index-alist)))) + (let ((c (current-window-configuration)) + (result nil)) + (unwind-protect + (progn + (switch-to-buffer buffer) + (if (modulep! :completion vertico) + (setq result (consult-outline level)) + (let ((entry (assoc (completing-read "Go to heading: " index nil t) index))) + (setq result entry) + (imenu entry)))) + (unless result + (set-window-configuration c)))))))) + ;; ;;; Hooks From 4e795c3a558c7c2247e9e339db41c7e622ca2e39 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 20:38:16 -0400 Subject: [PATCH 18/33] tweak(org): use consult-outline instead of imenu Ref: #7716 --- modules/lang/org/config.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 1c9bb3f06..8473f7c6d 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -871,6 +871,9 @@ between the two." [remap doom/backward-to-bol-or-indent] #'org-beginning-of-line [remap doom/forward-to-last-non-comment-or-eol] #'org-end-of-line + (:when (modulep! :completion vertico) + [remap imenu] #'consult-outline) + :localleader "#" #'org-update-statistics-cookies "'" #'org-edit-special From 17d4aaace33e7323639deb5878e24d31cf2dc3c7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 21:03:12 -0400 Subject: [PATCH 19/33] fix(format): add lsp functions Forgot to include these functions in 8072762. Oops. Amend: 8072762de8dd --- modules/editor/format/autoload/lsp.el | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 modules/editor/format/autoload/lsp.el diff --git a/modules/editor/format/autoload/lsp.el b/modules/editor/format/autoload/lsp.el new file mode 100644 index 000000000..3ccb6836f --- /dev/null +++ b/modules/editor/format/autoload/lsp.el @@ -0,0 +1,67 @@ +;;; editor/format/autoload/lsp.el -*- lexical-binding: t; -*- +;;;###if (modulep! :tools lsp) + +(defvar +format-with--last nil) + +;;;###autoload +(defun +format-enable-lsp-formatter-h () + "TODO" + (when (and +format-with-lsp (null +format-with)) + (when (or (lsp-feature? "textDocument/formatting") + (lsp-feature? "textDocument/rangeFormatting")) + (setq-local +format-with--last +format-with + +format-with 'lsp)))) + +;;;###autoload +(defun +format-disable-lsp-formatter-h () + "TODO" + (when (local-variable-p '+format-with--last) + (kill-local-variable '+format-with--last) + (setq-local +format-with +format-with--last))) + +;;;###autoload +(defun +format-toggle-eglot-formatter-h () + "TODO" + (if (bound-and-true-p eglot--managed-mode) + (when (and +format-with-lsp (null +format-with)) + (when (or (eglot--server-capable :documentFormattingProvider) + (eglot--server-capable :documentRangeFormattingProvider)) + (setq-local +format-with--last +format-with + +format-with 'eglot))) + (when +format-with--last + (kill-local-variable '+format-with--last) + (setq-local +format-with +format-with--last)))) + + +;; +;;; Apheleia formatters + +;;;###autoload +(cl-defun +format-lsp-buffer (&key buffer scratch callback &allow-other-keys) + "Format the current buffer with any available lsp-mode formatter." + (with-current-buffer buffer + (let ((edits + (cond + ((lsp-feature? "textDocument/formatting") + (lsp-request "textDocument/formatting" (lsp--make-document-formatting-params))) + ((lsp-feature? "textDocument/rangeFormatting") + (lsp-request "textDocument/rangeFormatting" + (lsp--make-document-range-formatting-params + (point-min) (point-max))))))) + (unless (seq-empty-p edits) + (with-current-buffer scratch + (lsp--apply-text-edits edits 'format)))) + (funcall callback))) + +;;;###autoload +(cl-defun +format-eglot-buffer (&key buffer scratch callback &allow-other-keys) + "Format the current buffer with any available eglot formatter." + (with-current-buffer scratch + (setq-local eglot--cached-server + (with-current-buffer buffer + (eglot-current-server))) + (let ((buffer-file-name (buffer-file-name buffer))) + (eglot-format-buffer)) + (funcall callback))) + +;;; lsp.el ends here From 21a427c33b57ab66eb7caa2830c0dfe930509318 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 6 Jul 2024 21:18:34 -0400 Subject: [PATCH 20/33] fix(format): eglot-managed{,-mode}-hook hook --- 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 76ca73ae6..31ac0f6c3 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -52,7 +52,7 @@ This is controlled by `+format-on-save-disabled-modes'." ;; `+format-with-lsp' is non-nil. (cond ((modulep! :tools lsp +eglot) (add-to-list 'apheleia-formatters '(eglot . +format-eglot-buffer)) - (add-hook 'eglot-managed-hook #'+format-toggle-eglot-formatter-h)) + (add-hook 'eglot-managed-mode-hook #'+format-toggle-eglot-formatter-h)) ((modulep! :tools lsp) (add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)) (add-hook 'lsp-configure-hook #'+format-enable-lsp-formatter-h) From 3cd605182f362bb05d4064b4bd088a43b6f0c14b Mon Sep 17 00:00:00 2001 From: jman-schief <82455740+jman-schief@users.noreply.github.com> Date: Sun, 7 Jul 2024 19:37:02 +0200 Subject: [PATCH 21/33] fix(mu4e): remove stray +workspace-delete invokation In commit 528986110921c3032dcabc8f9fee28a95df055f7 `+workspace-delete` was replaced by `+workspace-kill`. The changes were not complete, though, and mu4e does not start anymore. This patch completes the changes and should restore mu4e. Amend: 528986110921 --- modules/email/mu4e/autoload/email.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/email/mu4e/autoload/email.el b/modules/email/mu4e/autoload/email.el index 9fe270bd0..15c99096d 100644 --- a/modules/email/mu4e/autoload/email.el +++ b/modules/email/mu4e/autoload/email.el @@ -65,7 +65,7 @@ default/fallback account." ;; as otherwise you can accumulate empty workspaces (progn (unless (+workspace-buffer-list) - (+workspace-delete (+workspace-current-name))) + (+workspace-kill (+workspace-current-name))) (+workspace-switch +mu4e-workspace-name t)) (setq +mu4e--old-wconf (current-window-configuration)) (delete-other-windows) From a99863a76f927cabdbd903a610db11646fe1ec73 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sun, 7 Jul 2024 13:35:40 -0500 Subject: [PATCH 22/33] bump: :tools magit magit/forge@4adb94d23c8f -> magit/forge@0102834bb7c8 magit/magit@ea0f07e54967 -> magit/magit@9d1f8db507e0 - Includes an update for forge to accommodate changes to closql's interface. Ref: magit/forge@fb272bd93bf1 --- modules/tools/magit/packages.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/tools/magit/packages.el b/modules/tools/magit/packages.el index 703503f3c..cfe52c8b2 100644 --- a/modules/tools/magit/packages.el +++ b/modules/tools/magit/packages.el @@ -1,9 +1,9 @@ ;; -*- no-byte-compile: t; -*- ;;; tools/magit/packages.el -(when (package! magit :pin "ea0f07e54967197ac0b072a69ba314314a4080c1") +(when (package! magit :pin "9d1f8db507e080e032943a3ed1445bd8d9aaa9fc") (when (modulep! +forge) - (package! forge :pin "4adb94d23c8f28ea3b15757936c2203b3376586a") + (package! forge :pin "0102834bb7c872c8a3f77cabf5221e8199346c43") (package! code-review :recipe (:host github :repo "doomelpa/code-review" From c45c8cee355a22bfa9c7eb87f05537aa7458288a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 05:11:10 -0400 Subject: [PATCH 23/33] tweak(beancount): +beancount/balance w/ prefix arg Without the prefix arg, it will only display the balance of Assets and Liabilities. With it, the balance of all accounts will be shown. --- modules/lang/beancount/autoload.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/lang/beancount/autoload.el b/modules/lang/beancount/autoload.el index 599620ca3..5b2729f67 100644 --- a/modules/lang/beancount/autoload.el +++ b/modules/lang/beancount/autoload.el @@ -120,11 +120,13 @@ If REVERSE (the prefix arg) is non-nil, sort the transactions in reverst order." (defvar compilation-read-command) ;;;###autoload -(defun +beancount/balance () +(defun +beancount/balance (&optional all-accounts) "Display a balance report with bean-report (bean-report bal)." - (interactive) - (let (compilation-read-command) - (beancount--run "bean-report" buffer-file-name "bal"))) + (interactive "P") + (let ((args (unless all-accounts '("-e" "Assets|Liabilities"))) + compilation-read-command + current-prefix-arg) + (apply #'beancount--run "bean-report" buffer-file-name "balances" args))) ;;;###autoload (defun +beancount/clone-transaction () From deb59ca4ad774d62975a8b6926bcd5faccd14409 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 14:21:29 -0400 Subject: [PATCH 24/33] fix(format): LSP formatters before Apheleia is loaded --- modules/editor/format/config.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 31ac0f6c3..e1ceb7db1 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -45,19 +45,20 @@ This is controlled by `+format-on-save-disabled-modes'." (eq +format-on-save-disabled-modes t) (not (null (memq major-mode +format-on-save-disabled-modes))))))) - :config - (add-to-list 'doom-debug-variables '(apheleia-log-only-errors . nil)) - ;; Use the formatter provided by lsp-mode and eglot, if they are available and ;; `+format-with-lsp' is non-nil. (cond ((modulep! :tools lsp +eglot) - (add-to-list 'apheleia-formatters '(eglot . +format-eglot-buffer)) (add-hook 'eglot-managed-mode-hook #'+format-toggle-eglot-formatter-h)) ((modulep! :tools lsp) - (add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)) (add-hook 'lsp-configure-hook #'+format-enable-lsp-formatter-h) (add-hook 'lsp-unconfigure-hook #'+format-disable-lsp-formatter-h))) + :config + (add-to-list 'doom-debug-variables '(apheleia-log-only-errors . nil)) + + (add-to-list 'apheleia-formatters '(eglot . +format-eglot-buffer)) + (add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)) + (defadvice! +format--inhibit-reformat-on-prefix-arg-a (orig-fn &optional arg) "Make it so \\[save-buffer] with prefix arg inhibits reformatting." :around #'save-buffer From 5e78ed09114fb1a22e2a050522b96c6f0d6df9e3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 14:28:59 -0400 Subject: [PATCH 25/33] refactor(format): use eglot-server-capable eglot--server-capable was deprecated. --- modules/editor/format/autoload/lsp.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/editor/format/autoload/lsp.el b/modules/editor/format/autoload/lsp.el index 3ccb6836f..a3cd82505 100644 --- a/modules/editor/format/autoload/lsp.el +++ b/modules/editor/format/autoload/lsp.el @@ -24,8 +24,8 @@ "TODO" (if (bound-and-true-p eglot--managed-mode) (when (and +format-with-lsp (null +format-with)) - (when (or (eglot--server-capable :documentFormattingProvider) - (eglot--server-capable :documentRangeFormattingProvider)) + (when (or (eglot-server-capable :documentFormattingProvider) + (eglot-server-capable :documentRangeFormattingProvider)) (setq-local +format-with--last +format-with +format-with 'eglot))) (when +format-with--last From c5c7f0bc9917bbf9014a8bd8a16ab9afb26e3a1c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 16:31:24 -0400 Subject: [PATCH 26/33] feat(format): add +format-inhibit alias I want both `apheleia-formatter` and `apheleia-inhibit` exposed for easy setting from directory/file-local variables (like .dir-locals.el), but I'd like to abstract away the implementation (Apheleia) a little, hence these aliases. This way, whether or not we're still using Apheleia in a year or three, `+format-with` and `+format-inhibit` should always work. --- modules/editor/format/config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index e1ceb7db1..6bce65f92 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -24,6 +24,7 @@ variable." :safe 'booleanp) (defvaralias '+format-with 'apheleia-formatter) +(defvaralias '+format-inhibit 'apheleia-inhibit) ;; From 9224ac56f0ff47aa5fb9160f8bddde6ded174ae3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 20:39:32 -0400 Subject: [PATCH 27/33] tweak(default): bind ' g U' to magit-unstage-buffer-file The former command, magit-unstable-file, would prompt the user to select a file to unstage, but the intention of this keybind was always to "unstage *this* file". magit-unstage-buffer-file didn't exist at the time this keybind was created, so I settled on magit-unstage-file as a compromise, which is no longer necessary. --- modules/config/default/+evil-bindings.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index f6c32c68f..826ad31d9 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -525,7 +525,7 @@ :desc "Magit fetch" "F" #'magit-fetch :desc "Magit buffer log" "L" #'magit-log-buffer-file :desc "Git stage this file" "S" #'magit-stage-buffer-file - :desc "Git unstage this file" "U" #'magit-unstage-file + :desc "Git unstage this file" "U" #'magit-unstage-buffer-file (:prefix ("f" . "find") :desc "Find file" "f" #'magit-find-file :desc "Find gitconfig file" "g" #'magit-find-git-config-file From d648bfda40e6a15448c9131e8dba95896b70b6c4 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 20:41:03 -0400 Subject: [PATCH 28/33] docs(format): revise docstrings and comments --- modules/editor/format/autoload/format.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index 5428d8ec4..9b6b4c4f4 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -27,10 +27,10 @@ ;; possible, in case the formatter is an elisp function, like `gofmt'. (cl-loop for (var . val) in (cl-remove-if-not #'listp (buffer-local-variables cur-buffer)) - ;; Making enable-multibyte-characters buffer-local causes an - ;; error. + ;; `enable-multibyte-characters' can change how Emacs reads the + ;; buffer's contents (or writes them to the formatters), which + ;; can cause errors. unless (eq var 'enable-multibyte-characters) - ;; Using setq-local would quote var. do (set (make-local-variable var) val)) ;; (insert-buffer-substring-no-properties cur-buffer start end) @@ -66,18 +66,17 @@ ;;;###autoload (defun +format/region (beg end &optional _arg) - "Runs the active formatter on the lines within BEG and END. + "Format the selected region. -WARNING: this may not work everywhere. It will throw errors if the region -contains a syntax error in isolation. It is mostly useful for formatting -snippets or single lines." +WARNING: if the formatter doesn't support partial formatting, this command tries +to pretend the active selection is the contents of a standalone file, but this +may not always work. Keep your undo keybind handy!" (interactive "rP") (+format-region beg end)) ;;;###autoload (defun +format/region-or-buffer () - "Runs the active formatter on the selected region (or whole buffer, if nothing -is selected)." + "Format the selected region, or whole buffer if nothing is selected." (interactive) (call-interactively (if (doom-region-active-p) From cca40c0277198a13500a375be5e944d337f4fcba Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 20:51:24 -0400 Subject: [PATCH 29/33] tweak(format): doom-debug-variables: add apheleia-log-debug-info --- modules/editor/format/config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 6bce65f92..88d6d58b3 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -56,6 +56,7 @@ This is controlled by `+format-on-save-disabled-modes'." :config (add-to-list 'doom-debug-variables '(apheleia-log-only-errors . nil)) + (add-to-list 'doom-debug-variables '(apheleia-log-debug-info . t)) (add-to-list 'apheleia-formatters '(eglot . +format-eglot-buffer)) (add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)) From fd1941b95f22ce3649ef7c5b28b9b5c982586bb4 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 20:44:33 -0400 Subject: [PATCH 30/33] refactor!(format): simplify & gate lsp/eglot impl behind +lsp BREAKING CHANGE: This commit introduces two changes, a breaking, one not. The breaking change: `+format-with-lsp` used to control lsp-mode/eglot integration for this module, but it is now gated behind a new +lsp flag. Users will need to add it to their `doom!` blocks (in $DOOMDIR/init.el) to restore the integration. The other change: I've merged the former `lsp` and `eglot` formatters into a single `lsp` formatter that dispatches to the appropriate backend, as well as wrapping this integration in a `+format-with-lsp-mode` minor mode, so it can be toggled at will; mainly to assist in debugging formatter behavior. A unified formatter makes it easier for folks to configure `+format-with` on a per-project/directory/file basis, without needing to know what backend this module uses, and opens us up to integrating other LSP backends in the future (like lsp-bridge). --- modules/editor/format/README.org | 3 + modules/editor/format/autoload/lsp.el | 99 ++++++++++++++++----------- modules/editor/format/config.el | 27 +++----- 3 files changed, 70 insertions(+), 59 deletions(-) diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index d5c855bac..7be3facdc 100644 --- a/modules/editor/format/README.org +++ b/modules/editor/format/README.org @@ -27,6 +27,9 @@ be formatted and returned to the buffer using Enable reformatting of a buffer when it is saved. See [[var:+format-on-save-disabled-modes]] to disable format on save for certain major modes. +- +lsp :: + Use ~lsp-mode~'s or ~eglot~'s formatters, instead of Apheleia's, if the active + client has the capabilities. ** Packages - [[doom-package:apheleia]] diff --git a/modules/editor/format/autoload/lsp.el b/modules/editor/format/autoload/lsp.el index a3cd82505..0235b0763 100644 --- a/modules/editor/format/autoload/lsp.el +++ b/modules/editor/format/autoload/lsp.el @@ -1,67 +1,86 @@ ;;; editor/format/autoload/lsp.el -*- lexical-binding: t; -*- ;;;###if (modulep! :tools lsp) -(defvar +format-with--last nil) +(defvar +format-lsp--last nil) ;;;###autoload -(defun +format-enable-lsp-formatter-h () - "TODO" - (when (and +format-with-lsp (null +format-with)) - (when (or (lsp-feature? "textDocument/formatting") - (lsp-feature? "textDocument/rangeFormatting")) - (setq-local +format-with--last +format-with - +format-with 'lsp)))) +(define-minor-mode +format-with-lsp-mode + "Toggles `lsp-mode'/`eglot' integration with `apheleia-mode' in this buffer. + +When enabled, it changes `+format-with' to `lsp', and back to its old value when +disabled. Use `+format-wtih-lsp-maybe-h' to activate it, to ensure it only +activates if lsp-mode/eglot are on and connected to a valid client, and so this +mode won't conflict with pre-existing user config on `+format-with'." + :init-value nil + (unless (local-variable-p '+format-lsp--last) + (setq-local +format-lsp--last +format-with)) + (setq-local +format-with + (if +format-with-lsp-mode + (cl-remove-duplicates (cons 'lsp +format-with) :test #'eq) + (prog1 (remq 'lsp (ensure-list +format-lsp--last)) + (kill-local-variable '+format-lsp--last))))) + +(defvar +format--lsp-alist + '((lsp-managed-mode . +format--with-lsp-mode) + (eglot--managed-mode . +format--with-eglot)) + "A list of LSP formatter functions to try on `+format-lsp-buffer'.") + +(defun +format--lsp-fn () + (cl-loop for (sym . fn) in +format--lsp-alist + if (and (boundp sym) (symbol-value sym)) + return fn)) ;;;###autoload -(defun +format-disable-lsp-formatter-h () - "TODO" - (when (local-variable-p '+format-with--last) - (kill-local-variable '+format-with--last) - (setq-local +format-with +format-with--last))) +(defun +format-with-lsp-toggle-h () + "Toggle `+format-with-lsp-mode' depending on the state of lsp-mode/eglot. -;;;###autoload -(defun +format-toggle-eglot-formatter-h () - "TODO" - (if (bound-and-true-p eglot--managed-mode) - (when (and +format-with-lsp (null +format-with)) - (when (or (eglot-server-capable :documentFormattingProvider) - (eglot-server-capable :documentRangeFormattingProvider)) - (setq-local +format-with--last +format-with - +format-with 'eglot))) - (when +format-with--last - (kill-local-variable '+format-with--last) - (setq-local +format-with +format-with--last)))) +Does not activate the mode if `+format-with' is already set. To activate the +mode unconditionally, call `+format-with-lsp-mode' instead." + (when (or (null +format-with) +format-with-lsp-mode) + (+format-with-lsp-mode (if (+format--lsp-fn) +1 -1)))) ;; ;;; Apheleia formatters ;;;###autoload -(cl-defun +format-lsp-buffer (&key buffer scratch callback &allow-other-keys) +(cl-defun +format-lsp-buffer (&rest plist &key callback &allow-other-keys) + "Format the current buffer with any available lsp-mode or eglot formatter." + (if-let* ((fn (+format--lsp-fn)) + ((apply fn plist))) + (funcall callback) + (funcall callback "LSP server doesn't support formatting"))) + +(cl-defun +format--with-lsp-mode (&key buffer scratch &allow-other-keys) "Format the current buffer with any available lsp-mode formatter." (with-current-buffer buffer (let ((edits (cond ((lsp-feature? "textDocument/formatting") - (lsp-request "textDocument/formatting" (lsp--make-document-formatting-params))) + (lsp-request "textDocument/formatting" + (lsp--make-document-formatting-params))) ((lsp-feature? "textDocument/rangeFormatting") (lsp-request "textDocument/rangeFormatting" (lsp--make-document-range-formatting-params - (point-min) (point-max))))))) - (unless (seq-empty-p edits) - (with-current-buffer scratch - (lsp--apply-text-edits edits 'format)))) - (funcall callback))) + (point-min) (point-max)))) + (:err)))) + (unless (eq edits :err) + (unless (seq-empty-p edits) + (with-current-buffer scratch + (lsp--apply-text-edits edits 'format))) + t)))) -;;;###autoload -(cl-defun +format-eglot-buffer (&key buffer scratch callback &allow-other-keys) +(cl-defun +format--with-eglot (&key buffer scratch &allow-other-keys) "Format the current buffer with any available eglot formatter." (with-current-buffer scratch - (setq-local eglot--cached-server - (with-current-buffer buffer - (eglot-current-server))) - (let ((buffer-file-name (buffer-file-name buffer))) - (eglot-format-buffer)) - (funcall callback))) + (when (setq-local + eglot--cached-server + (with-current-buffer buffer + (when (or (eglot-server-capable :documentFormattingProvider) + (eglot-server-capable :documentRangeFormattingProvider)) + (eglot-current-server)))) + (let ((buffer-file-name (buffer-file-name buffer))) + (eglot-format-buffer)) + t))) ;;; lsp.el ends here diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 88d6d58b3..bef0b8737 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -12,17 +12,6 @@ If it is t, it is disabled in all modes, the same as if the +onsave flag wasn't If nil, formatting is enabled in all modes." :type '(list symbol)) -(defcustom +format-with-lsp t - "If non-nil, format with LSP formatter if it's available. - -LSP formatter is provided by either `lsp-mode' or `eglot'. - -This can be set buffer-locally with `setq-hook!' to disable LSP formatting in -select buffers, from a project's .dir-locals.el file, or as a file-local -variable." - :type 'boolean - :safe 'booleanp) - (defvaralias '+format-with 'apheleia-formatter) (defvaralias '+format-inhibit 'apheleia-inhibit) @@ -46,19 +35,19 @@ This is controlled by `+format-on-save-disabled-modes'." (eq +format-on-save-disabled-modes t) (not (null (memq major-mode +format-on-save-disabled-modes))))))) - ;; Use the formatter provided by lsp-mode and eglot, if they are available and - ;; `+format-with-lsp' is non-nil. - (cond ((modulep! :tools lsp +eglot) - (add-hook 'eglot-managed-mode-hook #'+format-toggle-eglot-formatter-h)) - ((modulep! :tools lsp) - (add-hook 'lsp-configure-hook #'+format-enable-lsp-formatter-h) - (add-hook 'lsp-unconfigure-hook #'+format-disable-lsp-formatter-h))) + ;; Use the formatter provided by lsp-mode and eglot, if available. + (when (modulep! +lsp) + (add-hook 'eglot-managed-mode-hook #'+format-with-lsp-maybe-h) + (add-hook 'lsp-managed-mode-hook #'+format-with-lsp-maybe-h)) :config (add-to-list 'doom-debug-variables '(apheleia-log-only-errors . nil)) (add-to-list 'doom-debug-variables '(apheleia-log-debug-info . t)) - (add-to-list 'apheleia-formatters '(eglot . +format-eglot-buffer)) + ;; A psuedo-formatter that dispatches to the appropriate LSP client (via + ;; `lsp-mode' or `eglot') that is capable of formatting. Without +lsp, users + ;; must manually set `+format-with' to `lsp' to use it, or activate + ;; `+format-with-lsp-mode' in the appropriate modes. (add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)) (defadvice! +format--inhibit-reformat-on-prefix-arg-a (orig-fn &optional arg) From f104f10c5b145c3a89ea86ea82837b8d8c67804a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 21:33:56 -0400 Subject: [PATCH 31/33] docs(format): revise README.org To reflect recent changes and for clarity. --- modules/editor/format/README.org | 150 +++++++++++++++++++------------ 1 file changed, 95 insertions(+), 55 deletions(-) diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index 7be3facdc..1f3b32e52 100644 --- a/modules/editor/format/README.org +++ b/modules/editor/format/README.org @@ -35,12 +35,13 @@ be formatted and returned to the buffer using - [[doom-package:apheleia]] ** Hacks -As of writing this, apheleia doesn't /yet/ support regions or similar kinds of -buffers, so there are a couple of hacks to attempt to rectify this. - -For the most part, things should work as expected. However, because the -formatting occurs on an isolated version of the buffer; lisp/scheme or similarly -indentation-based languages may produce poor results. +- Apheleia -- and many formatters -- don't support partial formatting (i.e. the + opposite of whole-file formatting), so a couple of hacks are in place to + /force/ them to support this when you run [[fn:+format/region]]. This works by + copying the selection into a fake, standalone file and operating on that. This + works in many cases, but makes no guarantees that it will work with all + formatters. Lisp, Scheme, Python, or similarly indentation-based languages are + most likely to see strange results. ** TODO Changelog # This section will be machine generated. Don't edit it by hand. @@ -68,7 +69,6 @@ or =apheleia-format-buffer= is called. The difference between them is =+format/buffer= will use a LSP server if configured and available. * Configuration - Detailed configuration can be found [[https://github.com/radian-software/apheleia/#user-guide][upstream]], but for most purposes here we provide a simple macro that looks like the below: @@ -88,70 +88,110 @@ an =after!= form, eg below to override Clojure's with =zprint=: There are a few bonus symbols that apheleia uses (for example =npx= will be replaced by a correct path to npx) which are all documented in the link above. -** Disabling formatters -*** Permanently -To permanently disable a particular formatter with no provided alternative +** Selecting or disabling a specific formatter +:PROPERTIES: +:ID: ab7008f6-0d6e-4465-9980-adee2055aa16 +:END: +Doom exposes a couple variables and functions to help you configure this module's behavior: -#+begin_src emacs-lisp -(setq apheleia-formatters (delq (assoc 'csharpier apheleia-formatters) apheleia-formatters)) -#+end_src +- [[var:+format-with]] :: What formatter(s) to use for the current buffer. +- [[var:+format-inhibit]] :: If non-nil, formatting-on-save behavior is disabled, + regardless of ~apehelia-global-mode~. +- [[var:+format-on-save-disabled-modes]] :: A list of major modes to disable + format-on-save behavior in. These buffers can still be formatted by calling + the ~+format/buffer~ or ~+format/region~ commands, manually. +- [[fn:set-formatter!]] :: A helper function for configuring registered formatters + (or adding some of your own) and assigning them to major modes. + +Here are some ways to use them: -*** Per-buffer -If you want to save without formatting, this is done by first passing the -universal argument thus; =SPC u SPC f s= for evil users, =C-u C-x C-s= for non-evil -users. +1. In a project's =.dir-locals.el= file: + #+begin_src emacs-lisp + ((js2-mode . (+format-with . lsp)) + (python-mode . (+format-with . (isort black))) -If you want to save more than a handful of time, you can set -[[var:apheleia-inhibit]] to disable even if =apheleia-global-mode= is on. + ;; If +format-inhibit is non-nil, formatting-on-save behavior will be + ;; disabled, regardless of apheleia-global-mode. + (rustic-mode . (+format-inhibit . t))) + #+end_src -*** Onsave only -This behaviour is controlled via [[var:+format-on-save-disabled-modes]] thus; +2. With a file-local variable. E.g. At the top of a file: + #+begin_src js + // -*- +format-with: prettier -*- + #+end_src -#+begin_src emacs-lisp -(setq +format-on-save-disabled-modes - '(emacs-lisp-mode ; elisp's mechanisms are good enough - sql-mode ; sqlformat is currently broken - tex-mode ; latexindent is broken - latex-mode)) -#+end_src + Or at the bottom of a file + #+begin_src python + # Local Variables: + # +format-with: (isort black) + # End: + #+end_src -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 -=+format/buffer= or =apheleia-format-buffer=. +3. From your Doom configuration: + #+begin_src emacs-lisp + ;;; add to $DOOMDIR/config.el + (setq-hook! 'python-mode-hook +format-with 'black) -** 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:apheleia]]'s formatter. + ;; Or set it to `nil' to fallback to Apheleia's default + (setq-hook! 'python-mode-hook +format-with nil) -+ To disable this behavior universally use: ~(setq +format-with-lsp nil)~ -+ To disable this behavior in one mode: ~(setq-hook! 'python-mode-hook - +format-with-lsp nil)~ + ;; Disable format-on-save behavior in Emacs Lisp buffers + (setq-hook! 'emacs-lisp-mode-hook +format-inhibit t) -** Selecting a specific formatter for a particular buffer -Set the buffer-local variable ~+format-with~ to the name of the formatter to -use. e.g. -#+begin_src emacs-lisp -;; Overrides `apheleia-mode-alist` -(setq-hook! 'python-mode-hook +format-with 'html-tidy) + ;; To permenantly disable a formatter: + (after! csharp-mode + (set-formatter! 'csharpier nil)) -;; Or set it to `nil' to fallback to `apheleia-mode-alist` -(setq-hook! 'python-mode-hook +format-with nil) -#+end_src + ;; To define new formatters: + ;; From modules/tools/docker/config.el: + (after! dockerfile-mode + (set-formatter! 'dockfmt '("dockfmt" "fmt" filepath) :modes '(dockerfile-mode))) + + ;; From modules/lang/sh/config.el: + (after! sh-script + (set-formatter! 'shfmt '("shfmt" "-ci" + (unless indent-tabs-mode + (list "-i" (number-to-string tab-width)))))) + + (setq +format-on-save-disabled-modes + '(emacs-lisp-mode ; elisp's mechanisms are good enough + sql-mode ; sqlformat is currently broken + tex-mode ; latexindent is broken + latex-mode)) + #+end_src Formatters are referred to by the name they were defined with. They can be -looked up in the ~apheleia-mode-alist~ hash table. +looked up in the ~apheleia-mode-alist~ hash table (with [[kbd: v]]). + +** One-off ~save-buffer~ without auto-formatting +To save the buffer without formatting just once, pass the universal argument to +~save-buffer~ ([[kbd:][SPC u]] for evil users, [[kbd:][C-u]] for non-evil users). For example: + +- Evil: [[kbd:][SPC u SPC f s]] +- Without evil: [[kbd:][C-u C-x C-s]] + +** Using ~lsp-mode~ or ~eglot~'s formatter +If you have a buffer open with [[doom-package:lsp-mode]] or [[doom-package:eglot]] +enabled, and the running server supports =textDocument/formatting= or +=textDocument/rangeFormatting=, it can be used instead of +[[doom-package:apheleia]]'s (or Doom's) default formatters by enabling this module +with its =+lsp= flag or manually activating the [[fn:+format-with-lsp-mode]] minor +mode (though it's a better idea to use [[fn:+format-with-lsp-maybe-h]] if you're +looking for a function to use with mode hooks; this function will respect +pre-existing modifications to [[var:+format-with]]). + +To enable this formatter selectively, see the next section. * Troubleshooting -There are a few fail-safes apheleia has to prevent accidental code wipe, -included silently failing if the command errors or doesn't exist. +There are a few fail-safes [[doom-package:apheleia]] has to prevent accidental code +wipe, included silently failing if the command errors or doesn't exist. Check +that the command you've specified runs fine in a terminal first before reporting +issues. -Check that the command you've specified runs fine in a terminal first before -reporting this as an issue. +If any errors are reported from the command, run =apheleia-goto-error= to jump +to the error buffer and handle any problems raised. -If any errors are reported from the command, run =apheleia-goto-error= to jump to -the error buffer and handle any problems raised there. - -Any issues specific to apheleia should most often be reported upstream [[https://github.com/radian-software/apheleia/issues][here]]. +Any issues specific to Apheleia should most often be reported upstream [[https://github.com/radian-software/apheleia/issues][here]]. * Frequently asked questions /This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] From 6b526b1b475ca95415d87b1c52c5c68aa7b1457f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Jul 2024 21:34:33 -0400 Subject: [PATCH 32/33] refactor(format): +format/org-block: make arg optional --- modules/editor/format/autoload/format.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index 9b6b4c4f4..fe2492d2e 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -84,7 +84,7 @@ may not always work. Keep your undo keybind handy!" #'+format/buffer))) ;;;###autoload -(defun +format/org-block (point) +(defun +format/org-block (&optional point) "Reformat the org src block at POINT with a mode approriate formatter." (interactive (list (point))) (unless (derived-mode-p 'org-mode) From 6e19452f749a577d117e447194f3f26a09bf09f1 Mon Sep 17 00:00:00 2001 From: Keenan Sanchez Date: Mon, 8 Jul 2024 01:33:28 -0400 Subject: [PATCH 33/33] fix(python): missing labels for keybind prefixes Use the `(PREFIX . DESCRIPTION)` syntax for the python mode map. --- modules/lang/python/config.el | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/lang/python/config.el b/modules/lang/python/config.el index 58d496644..a44b56011 100644 --- a/modules/lang/python/config.el +++ b/modules/lang/python/config.el @@ -134,7 +134,7 @@ (add-hook 'anaconda-mode-hook #'evil-normalize-keymaps)) (map! :localleader :map anaconda-mode-map - :prefix "g" + :prefix ("g" . "conda") "d" #'anaconda-mode-find-definitions "h" #'anaconda-mode-show-doc "a" #'anaconda-mode-find-assignments @@ -148,10 +148,10 @@ (map! :after python :map python-mode-map :localleader - (:prefix ("i" . "imports") - :desc "Insert missing imports" "i" #'pyimport-insert-missing - :desc "Remove unused imports" "R" #'pyimport-remove-unused - :desc "Optimize imports" "o" #'+python/optimize-imports))) + :prefix ("i" . "imports") + :desc "Insert missing imports" "i" #'pyimport-insert-missing + :desc "Remove unused imports" "R" #'pyimport-remove-unused + :desc "Optimize imports" "o" #'+python/optimize-imports)) (use-package! py-isort @@ -161,8 +161,8 @@ :map python-mode-map :localleader (:prefix ("i" . "imports") - :desc "Sort imports" "s" #'py-isort-buffer - :desc "Sort region" "r" #'py-isort-region))) + :desc "Sort imports" "s" #'py-isort-buffer + :desc "Sort region" "r" #'py-isort-region))) (use-package! nose :commands nose-mode @@ -176,7 +176,7 @@ (map! :localleader :map nose-mode-map - :prefix "t" + :prefix ("t" . "test") "r" #'nosetests-again "a" #'nosetests-all "s" #'nosetests-one @@ -220,7 +220,7 @@ (:description . "Run Python script"))) (map! :map python-mode-map :localleader - :prefix "e" + :prefix ("e" . "pipenv") :desc "activate" "a" #'pipenv-activate :desc "deactivate" "d" #'pipenv-deactivate :desc "install" "i" #'pipenv-install