Remove the blacken and anaconda sections completely

This commit is contained in:
Gerard Vermeulen 2022-07-26 20:13:43 +02:00
parent b415dbef07
commit 2b8030a9f7
1 changed files with 9 additions and 102 deletions

View File

@ -3242,18 +3242,20 @@ in [[https://orgmode.org/][Org Mode]].
:CUSTOM_ID: sec:python-programming
:END:
The [[https://www.emacswiki.org/emacs/PythonProgrammingInEmacs][Python Programming in Emacs]] wiki page lists options to enhance Emacs's
built-in ~python-mode~. Here, the focus is on two packages:
built-in ~python-mode~. Here, the focus is on three packages:
1. [[https://github.com/joaotavora/eglot][Eglot - Emacs polyGLOT: an Emacs LSP client that stays out of your way]]. The
maintainer also contributes to Emacs itself and has a deep understanding of
[[https://sheer.tj/the_way_of_emacs.html][the Way of Emacs]]. He refuses to add new features without seeing how they fit
into [[https://sheer.tj/the_way_of_emacs.html][the Way of Emacs]] as this discussion on [[https://github.com/joaotavora/eglot/issues/523][org-mode source code blocks]]
shows.
2. [[https://github.com/pythonic-emacs/anaconda-mode][Anaconda - code navigation, documentation lookup, and completion for Python]].
In my opinion, [[https://github.com/joaotavora/eglot][eglot]] has more potential than [[https://github.com/pythonic-emacs/anaconda-mode][anaconda]], but [[https://github.com/pythonic-emacs/anaconda-mode][anaconda]] is
compatible with [[info:org#Editing Source Code][source code block editing]] while [[https://github.com/joaotavora/eglot][eglot]] is not.
2. [[https://jedi.readthedocs.io/en/latest/][Jedi]] is a static analysis tool for Python that is typically used in plugins
for editors or integrated development environments. Jedi has a focus on
autocompletion and object definition lookup functionality.
3. [[https://github.com/astoff/code-cells.el#readme][Code-cells]] allows to edit [[https://ipython.org/notebook.html][IPython or Jupyter notebooks]] in Emacs with help
from either [[https://github.com/mwouts/jupytext][Jupytext]] or [[https://pandoc.org/][Pandoc]].
Here are a few links covering how to integrate Emacs, Python and a Python LSP
server, before plunging into the configuring steps:
Here are links covering how to integrate Emacs, Python and a Python LSP
server, before plunging into the configuration steps:
1. [[https://taingram.org/blog/emacs-lsp-ide.html][Building Your Own Emacs IDE with LSP]]
2. [[https://rgoswami.me/posts/emacs-lang-servers/][Doom Emacs and Language Servers]]
3. [[https://ddavis.io/posts/eglot-python-ide/][Eglot based Emacs Python IDE]]
@ -3566,35 +3568,12 @@ index bf312f6..4758b53 100644
#+end_src
:end:
*** [[https://github.com/pythonic-emacs/blacken#readme][Blacken]] :noexport:
:PROPERTIES:
:CUSTOM_ID: sec:blacken
:header-args:emacs-lisp: :tangle no
: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 (and (ensure-package-installation 'blacken)
(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
:END:
Listing [[lst:example-py]] is a [[https://www.python.org][Python]] example to test whether [[https://jedi.readthedocs.io/en/latest/][jedi]] in combination
with and either [[https://github.com/pythonic-emacs/anaconda-mode][anaconda]] or [[https://github.com/joaotavora/eglot][eglot]] works when coding certain functions of for
instance [[https://numpy.org/][numpy]] and [[https://scipy.org/][scipy]].
with [[https://github.com/joaotavora/eglot][eglot]] works when coding for instance [[https://numpy.org/][numpy]] universal functions.
#+caption[Tangle the =example.py= file]:
#+caption: Tangle the =example.py= file.
@ -3610,78 +3589,6 @@ instance [[https://numpy.org/][numpy]] and [[https://scipy.org/][scipy]].
print(q)
#+end_src
*** [[https://github.com/pythonic-emacs/anaconda-mode][Anaconda]] :noexport:
:PROPERTIES:
:CUSTOM_ID: sec:anaconda
:header-args:emacs-lisp: :tangle no
:END:
Listing [[lst:configure-anaconda+company-for-python]] and
[[lst:define-my-toggle-anaconda-mode]] configure [[https://github.com/pythonic-emacs/anaconda-mode][anaconda]]. See [[https://github.com/jorgenschaefer/elpy/blob/8d0de310d41ebf06b22321a8534546447456870c/elpy.el#L2775][elpy-module-company]]
for how to handle ~company-backends~ as a local variable in listing
[[lst:configure-anaconda+company-for-python]]. The call to [[info:elisp#Advising Functions][advice-add]] in listing
[[lst:define-my-toggle-anaconda-mode]] opens Python =org-edit-src-code= buffers in
~anaconda-mode~.
#+caption[Configure =anaconda= with =company= for Python]:
#+caption: Configure =anaconda= with =company= for Python.
#+name: lst:configure-anaconda+company-for-python
#+begin_src emacs-lisp
(when (ensure-package-installation 'anaconda-mode 'company-anaconda)
(with-eval-after-load 'python
(with-eval-after-load 'company
(when (and (fboundp 'anaconda-mode)
(fboundp 'company-anaconda))
(defun my-disable-anaconda-mode ()
(when (derived-mode-p 'python-mode)
(anaconda-mode -1)
(make-variable-buffer-local 'company-backends)
(setq company-backends
(delq 'company-anaconda
(mapcar #'identity company-backends)))
(anaconda-eldoc-mode -1)))
(defun my-enable-anaconda-mode ()
(when (derived-mode-p 'python-mode)
(anaconda-mode +1)
(make-variable-buffer-local 'company-backends)
(setq company-backends
(cons 'company-anaconda
(delq 'company-semantic
(delq 'company-capf
(mapcar #'identity company-backends)))))
(anaconda-eldoc-mode
(if (file-remote-p default-directory) -1 1))))))))
#+end_src
#+caption[Define =my-toggle-anaconda-mode= for Python]:
#+caption: Define =my-toggle-anaconda-mode= for Python.
#+name: lst:define-my-toggle-anaconda-mode
#+begin_src emacs-lisp
(with-eval-after-load 'python
(unless (and (fboundp 'my-disable-anaconda-mode)
(fboundp 'my-enable-anaconda-mode))
(when (fboundp 'anaconda-mode)
(defun my-disable-anaconda-mode ()
(when (derived-mode-p 'python-mode)
(anaconda-mode -1)
(anaconda-eldoc-mode -1)))
(defun my-enable-anaconda-mode ()
(when (derived-mode-p 'python-mode)
(anaconda-mode +1)
(anaconda-eldoc-mode
(if (file-remote-p default-directory) -1 1))))))
(when (fboundp 'my-enable-anaconda-mode)
(advice-add 'org-edit-src-code :after #'my-enable-anaconda-mode))
(when (and (fboundp 'my-disable-anaconda-mode)
(fboundp 'my-enable-anaconda-mode))
(defun my-toggle-anaconda-mode ()
"Toggle anaconda-mode with bells and whistles."
(interactive)
(if (bound-and-true-p anaconda-mode)
(my-disable-anaconda-mode)
(my-enable-anaconda-mode)))))
#+end_src
*** [[https://github.com/astoff/code-cells.el#readme][Code-cells]]
:PROPERTIES:
:CUSTOM_ID: sec:code-cells