Skip to content

refactor(format): replace with apheleia #6369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 85 commits into from
Sep 13, 2023

Conversation

elken
Copy link
Contributor

@elken elken commented May 5, 2022

Replace format-all with apheleia to grealy simplify the formatting setup.

For the most part, this is a low degree of ready the only thing missing is documentation and more granular testing on each module.

I've also had a recent thought on how to handle LSP formatters, previously I ignored them in favour of apheleia but I might forward-port the same logic here for the new module.

@elken elken requested a review from hlissner as a code owner May 5, 2022 14:48
@elken elken marked this pull request as draft May 5, 2022 14:49
@iyefrat iyefrat added is:feature Adds or requests new features, or extends existing ones module:editor/format Pertains to Doom's :editor format module is:refactor Code changes with little/no effect on user-facing behavior labels May 6, 2022
@elken elken force-pushed the feature/editor-format-refactor branch 2 times, most recently from 9476d25 to 0ce5b74 Compare May 16, 2022 06:52
@elken elken force-pushed the feature/editor-format-refactor branch 2 times, most recently from 2db3b18 to 9fb9872 Compare May 27, 2022 05:56
@elken elken force-pushed the feature/editor-format-refactor branch 3 times, most recently from 25448d5 to 0061b26 Compare June 3, 2022 09:56
@elken elken force-pushed the feature/editor-format-refactor branch 7 times, most recently from 613dccd to 6b70908 Compare June 20, 2022 07:52
@elken elken force-pushed the feature/editor-format-refactor branch 2 times, most recently from cf8bbe4 to 4b43b59 Compare July 11, 2022 10:31
@elken elken force-pushed the feature/editor-format-refactor branch 2 times, most recently from a586625 to af77f7d Compare July 27, 2022 11:30
@elken elken force-pushed the feature/editor-format-refactor branch 2 times, most recently from 4b07aec to 9e11279 Compare August 9, 2022 08:29
@elken elken force-pushed the feature/editor-format-refactor branch 5 times, most recently from 645f902 to 0e94af6 Compare August 15, 2022 04:58
@fosskers
Copy link
Contributor

@yufengwang As mentioned in the new documentation for the format module, region formatting is not currently supported by Apheleia.

@ladieman217
Copy link

ladieman217 commented Sep 15, 2023

okay, is there any workaround? because i highly depend on format/region on a very old codebase @fosskers

@liaowang11
Copy link
Contributor

liaowang11 commented Sep 15, 2023

okay, is there any workaround? because i highly depend on format/region on a very old codebase @fosskers

With this tweak, it seems to be working for me. Note, the set-buffer-modified-p maybe irrelevant.

@@ -8,7 +8,7 @@
 
 (defun +format-region (start end &optional callback)
   "Format from START to END with `apheleia'."
-  (when-let* ((command (apheleia--get-formatter-command
+  (when-let* ((command (apheleia--get-formatters
                         (if current-prefix-arg
                             'prompt
                           'interactive)))
@@ -23,7 +23,7 @@
       ;; Ensure this temp buffer seems as much like the origin buffer as
       ;; 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 origin-buffer))
+               in (cl-remove-if-not #'listp (buffer-local-variables cur-buffer))
                ;; Making enable-multibyte-characters buffer-local causes an
                ;; error.
                unless (eq var 'enable-multibyte-characters)
@@ -45,7 +45,9 @@
              ;; restore indentation without affecting new
              ;; indentation
              (indent-rigidly (point-min) (point-max)
-                             (max 0 (- indent (+format--current-indentation))))))
+                             (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)

@elken elken deleted the feature/editor-format-refactor branch September 15, 2023 06:21
@elken
Copy link
Contributor Author

elken commented Sep 15, 2023

In future, please use issues when reporting issues.

As for this change, I've tested it locally and it seems to "kind of" work but since as pointed out it's not supported upstream, if you're happy with this fix I'll PR it in.

@offbyone
Copy link
Contributor

@elken thank you for the work on this; it's working well for me, and I'm glad to have it in main.

@ladieman217
Copy link

@elken thanks for your hard work

cpackard added a commit to cpackard/doom-emacs-config that referenced this pull request Sep 20, 2023
Doom-provided formatting tools now support `prettier` out-of-the-box as
of doomemacs/doomemacs#6369
@johalun
Copy link

johalun commented Sep 22, 2023

@yufengwang

Hey! Please tell me how you got region formatting working. If I don't modify any settings SPC c f formats incorrectly (not using my .clang-format).

If I add (setq +format-with-lsp nil) I get the error Symbol’s function definition is void: apheleia--get-formatter-command for region formatting but full buffer formatting works.

I'm on latest master and the doom code does contain the changes above.

@elken
Copy link
Contributor Author

elken commented Sep 23, 2023

a) if you're having issues, report them through the proper channels
b) if you were using the latest master, you'd have #7427 which resolves that error so please update to the latest master

@ladieman217
Copy link

@johalun I have submit a new issue, it still has bugs, #7438

kenranunderscore pushed a commit to kenranunderscore/doomemacs that referenced this pull request Oct 16, 2023
`apheleia--indent-lisp-buffer` does not exist.

Ref: doomemacs#6369
Zetagon pushed a commit to Zetagon/doom-emacs that referenced this pull request Oct 17, 2023
`apheleia--indent-lisp-buffer` does not exist.

Ref: doomemacs#6369


;;
;;; Commands

(defun +format--org-region (beg end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elken You may have removed the +format--org-region for some reason, but this is quite handy and, as far as I am concerned, I use it every day. Can i add it back in this module?

lroolle added a commit to lroolle/doom-emacs that referenced this pull request Jan 4, 2024
lroolle added a commit to lroolle/doom-emacs that referenced this pull request Feb 20, 2024
lroolle added a commit to lroolle/doom-emacs that referenced this pull request May 27, 2024
lroolle added a commit to lroolle/doom-emacs that referenced this pull request Jul 10, 2024
lroolle added a commit to lroolle/doom-emacs that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:feature Adds or requests new features, or extends existing ones is:refactor Code changes with little/no effect on user-facing behavior module:editor/format Pertains to Doom's :editor format module
Projects
None yet
Development

Successfully merging this pull request may close these issues.