From 944e194758a866144eae1a82f2020c0421780b33 Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Fri, 6 May 2022 17:19:54 +0200 Subject: [PATCH] Ensure to format Python code after tangling --- README.org | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index 424e91e..8acc528 100644 --- a/README.org +++ b/README.org @@ -2560,19 +2560,29 @@ Listing [[lst:configure-writegood-mode]] configures [[https://github.com/bnbeckw :CUSTOM_ID: sec:format-all :END: -Listing [[lst:configure-format-all]] configures [[https://github.com/lassik/emacs-format-all-the-code#readme][format-all]] which is a package that -provides an universal interface to code formatters of more than 60 computer -languages. +Listing [[lst:configure-format-all]]: +1. Configures [[https://github.com/lassik/emacs-format-all-the-code#readme][format-all]] which is a package that provides an universal interface + 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=. #+name: lst:configure-format-all #+begin_src emacs-lisp - ;; https://ianyepan.github.io/posts/format-all/ ;; 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 (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 ** [[https://dept-info.labri.fr/~strandh/Teaching/PFS/Common/Strandh-Tutorial/Dir-symbolic.html][Common Lisp programming]]