Ensure to format Python code after tangling

This commit is contained in:
Gerard Vermeulen 2022-05-06 17:19:54 +02:00
parent 6cd9ed7ecd
commit 944e194758

View File

@ -2560,19 +2560,29 @@ Listing [[lst:configure-writegood-mode]] configures [[https://github.com/bnbeckw
:CUSTOM_ID: sec:format-all :CUSTOM_ID: sec:format-all
:END: :END:
Listing [[lst:configure-format-all]] configures [[https://github.com/lassik/emacs-format-all-the-code#readme][format-all]] which is a package that Listing [[lst:configure-format-all]]:
provides an universal interface to code formatters of more than 60 computer 1. Configures [[https://github.com/lassik/emacs-format-all-the-code#readme][format-all]] which is a package that provides an universal interface
languages. to code formatters of more than 60 computer languages.
2. Adds =format-all-org-babel-post-tangle= to =org-babel-post-tangle-hook= to
format tangled Python code.
#+caption[Configure =format-all=]: #+caption[Configure =format-all=]:
#+caption: Configure =format-all=. #+caption: Configure =format-all=.
#+name: lst:configure-format-all #+name: lst:configure-format-all
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; https://ianyepan.github.io/posts/format-all/
;; https://github.com/lassik/emacs-format-all-the-code#readme ;; https://github.com/lassik/emacs-format-all-the-code#readme
;; https://ianyepan.github.io/posts/format-all/
;; https://jamesaimonetti.com/posts/formatting-tangled-output-in-org-mode/
(when (ensure-package-installation 'format-all) (when (ensure-package-installation 'format-all)
(when (fboundp 'format-all-ensure-formatter) (when (fboundp 'format-all-ensure-formatter)
(add-hook 'prog-mode-hook #'format-all-ensure-formatter))) (add-hook 'prog-mode-hook #'format-all-ensure-formatter))
(add-hook 'org-babel-post-tangle-hook
(defun format-all-org-babel-post-tangle ()
(when (derived-mode-p 'python-mode)
(let ((format-all-formatters '(("Python" black))))
(message "Format whole `%s' buffer after tangling" major-mode)
(format-all-buffer))))))
#+end_src #+end_src
** [[https://dept-info.labri.fr/~strandh/Teaching/PFS/Common/Strandh-Tutorial/Dir-symbolic.html][Common Lisp programming]] ** [[https://dept-info.labri.fr/~strandh/Teaching/PFS/Common/Strandh-Tutorial/Dir-symbolic.html][Common Lisp programming]]