lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
619 stars 107 forks source link

Error: (error "Don’t know how to format org-mode code") #100

Closed oatmealm closed 4 years ago

oatmealm commented 4 years ago

Hi, there! Wanted to report that I'm seeing this error message when saving org-mode buffers... There are NO source code blocks in the buffer that's being saved, and I DO see this error when saving buffer with org file which do have some source code blocks.

Debugger entered--Lisp error: (error "Don’t know how to format org-mode code")
  signal(error ("Don’t know how to format org-mode code"))
  error("Don't know how to format %S code" org-mode)
  format-all-buffer()
  funcall-interactively(format-all-buffer)
  call-interactively(format-all-buffer)
  (if (and (eq major-mode 'org-mode) (org-in-src-block-p t)) (+format--org-region nil nil) (call-interactively (cond ((and +format-with-lsp (and (boundp 'lsp-mode) lsp-mode) (lsp-feature\? "textDocument/formatting")) #'lsp-format-buffer) ((and +format-with-lsp (and (boundp 'eglot--managed-mode) eglot--managed-mode) (eglot--server-capable :documentFormattingProvider)) #'eglot-format-buffer) (#'format-all-buffer))))
  +format-buffer-h()
  run-hooks(before-save-hook)
  basic-save-buffer(nil)
  save-buffer()
  evil-write(nil nil nil nil nil)
  funcall-interactively(evil-write nil nil nil nil nil)
  call-interactively(evil-write)
  evil-ex-call-command(nil #("w" 0 1 (ex-index 1)) nil)
  eval((evil-ex-call-command nil #("w" 0 1 (ex-index 1)) nil))
  evil-ex-execute(#("w" 0 1 (ex-index 1)))
  evil-ex(nil)
  funcall-interactively(evil-ex nil)
  call-interactively(evil-ex nil nil)
  command-execute(evil-ex)

I'm using Doom Emacs.

Doom v2.0.9 (HEAD -> develop adff1aa68 2020-10-22 02:10:59 -0400)
GNU Emacs 27.1 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.21, cairo version 1.16.0) of 2020-08-20
lassik commented 4 years ago

This seems to be a bug in Doom Emacs which I don't know how to fix. The backtrace line:

 (if (and (eq major-mode 'org-mode) (org-in-src-block-p t)) (+format--org-region nil nil) (call-interactively (cond ((and +format-with-lsp (and (boundp 'lsp-mode) lsp-mode) (lsp-feature\? "textDocument/formatting")) #'lsp-format-buffer) ((and +format-with-lsp (and (boundp 'eglot--managed-mode) eglot--managed-mode) (eglot--server-capable :documentFormattingProvider)) #'eglot-format-buffer) (#'format-all-buffer))))

shows that it tries a bunch of different alternatives for how to format the buffer, and at the end, falls back to format-all-buffer as the default alternative if the other ones do not apply. In the case of your buffer, since you have no source code blocks, it probably should give up instead of calling format-all.

flyingns commented 4 years ago

My org file contains some headlines with :crypt: as tags. Each time I edit and save it, the information is automatically encrypted to protect some of my personal privacy. Everything was normal before, but since a commit, every time you save after editing, you can always get the error message in the title, and it no longer automatically encodes the encrypted information.

Debugger entered--Lisp error: (error "Don’t know how to format org-mode code")
  signal(error ("Don’t know how to format org-mode code"))
  error("Don't know how to format %S code" org-mode)
  format-all-buffer()
  funcall-interactively(format-all-buffer)
  call-interactively(format-all-buffer)
  (if (and (eq major-mode 'org-mode) (org-in-src-block-p t)) (+format--org-region nil nil) (call-interactively (cond ((and +format-with-lsp (and (boundp 'lsp-mode) lsp-mode) (lsp-feature\? "textDocument/formatting")) #'lsp-format-buffer) ((and +format-with-lsp (and (boundp 'eglot--managed-mode) eglot--managed-mode) (eglot--server-capable :documentFormattingProvider)) #'eglot-format-buffer) (#'format-all-buffer))))
  +format-buffer-h()
  run-hooks(before-save-hook)
  basic-save-buffer(t)
  save-buffer(1)
  funcall-interactively(save-buffer 1)
  call-interactively(save-buffer nil nil)
  command-execute(save-buffer)
lassik commented 4 years ago

Please talk to the Doom Emacs people about this bug as we are not able to fix it on the format-all side. If they need some assistance from format-all to make it easier to fix, we can work it out.