Prepare the replacement of blacken with format-all

This commit is contained in:
Gerard Vermeulen 2022-04-28 20:13:57 +02:00
parent 107bcd55ea
commit 80f265380a
1 changed files with 48 additions and 19 deletions

View File

@ -208,7 +208,6 @@ The [[info:emacs#Init File][init file (info)]] does not load the ~custom-file~ a
'(applescript-mode ; mode to edit AppleScript code
async ; asynchroneous processing
auctex ; Aalborg University Center TeX
blacken ; Black Python code formatter client
citar ; bibliography handling
citeproc ; bibliography handling
code-cells ; lightweight notebooks in Emacs
@ -2420,6 +2419,28 @@ non-interactive =org-element= functions to an =Emacs-lisp= buffer.
:CUSTOM_ID: sec:programming
:END:
** [[https://github.com/lassik/emacs-format-all-the-code#readme][Format-all]]
:PROPERTIES:
: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.
#+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
(when (ensure-package-installation
'format-all) ; universal code formatters interface
(when (fboundp 'format-all-ensure-formatter)
(add-hook 'prog-mode-hook #'format-all-ensure-formatter)))
#+end_src
** [[https://dept-info.labri.fr/~strandh/Teaching/PFS/Common/Strandh-Tutorial/Dir-symbolic.html][Common Lisp programming]]
:PROPERTIES:
:CUSTOM_ID: sec:common-lisp-programming
@ -2779,24 +2800,9 @@ such a proper [[info:emacs#Directory Variables][.dir-locals.el]] file.
| =eldoc-doc-buffer= | {{{kbd(C-h .)}}} | =eglot-mode-map= |
|---------------------------+------------------+------------------|
Lising [[lst:configure-blacken]] configures [[https://github.com/pythonic-emacs/blacken#readme][blacken]], because I use it to format all
new Python code with the [[https://black.readthedocs.io/en/stable/index.html][Python Black code formatter]]. Listing
[[lst:pyproject-toml-kick-off]] and [[lst:setup-cfg-kick-off]] implement the rules in
[[https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html][using black with other tools]] in order to make [[https://flake8.pycqa.org/en/latest/][flake8]] or [[https://pycodestyle.pycqa.org/en/latest/][pycodestyle]] agree with
[[https://black.readthedocs.io/en/stable/index.html][black's uncompromising style]].
#+caption[Configure =blacken=]:
#+caption: Configure =blacken=.
#+name: lst:configure-blacken
#+begin_src emacs-lisp
(when (fboundp 'blacken-buffer)
(defun advice-derived-python-mode-p (fn &rest args)
(if (derived-mode-p 'python-mode)
(apply fn args)
(message "Refusal to run %S, since buffer is in %S." fn major-mode)))
(advice-add 'blacken-buffer :around #'advice-derived-python-mode-p))
#+end_src
Listing [[lst:pyproject-toml-kick-off]] and [[lst:setup-cfg-kick-off]] implement the
rules in [[https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html][using black with other tools]] in order to make [[https://flake8.pycqa.org/en/latest/][flake8]] or [[https://pycodestyle.pycqa.org/en/latest/][pycodestyle]]
agree with [[https://black.readthedocs.io/en/stable/index.html][black's uncompromising style]].
#+caption[Kick starting a =pyproject.toml= file]:
#+caption: Kick starting a =pyproject.toml= file.
@ -2907,6 +2913,29 @@ index bf312f6..4758b53 100644
#+end_src
:end:
*** [[https://github.com/pythonic-emacs/blacken#readme][Blacken]]
:PROPERTIES:
:CUSTOM_ID: sec:blacken
:END:
Listing [[lst:configure-blacken]] configures [[https://github.com/pythonic-emacs/blacken#readme][blacken]] to format Python code with the
[[https://black.readthedocs.io/en/stable/index.html][Python Black code formatter]].
#+caption[Configure =blacken=]:
#+caption: Configure =blacken=.
#+name: lst:configure-blacken
#+begin_src emacs-lisp
(when (ensure-package-installation
'blacken) ; Black Python code formatter client
(when (fboundp 'blacken-buffer)
(defun advice-derived-python-mode-p (fn &rest args)
(if (derived-mode-p 'python-mode)
(apply fn args)
(message "Refusal to run %S, since buffer is in %S." fn major-mode)))
(advice-add 'blacken-buffer :around #'advice-derived-python-mode-p)))
#+end_src
*** [[https://jedi.readthedocs.io/en/latest/][Jedi]]
:PROPERTIES:
:CUSTOM_ID: sec:jedi