Remove superfluous code and text from the "Eglot" section

This commit is contained in:
Gerard Vermeulen 2024-06-21 12:13:37 +02:00
parent c4d5380fd8
commit bb5fbc1990

View File

@ -3783,17 +3783,11 @@ Return \"Front Matter\" when current page is above the first headline."
[[https://github.com/joaotavora/eglot#readme][Emacs polyGLOT (Eglot)]] is an Emacs language-server-protocol client that stays
out of your way. [[info:eglot#Top][Eglot (info)]] is a builtin since Emacs-29.1. The following
listings contribute to a programming language mode independent [[https://github.com/joaotavora/eglot][Eglot]]
configuration:
1. Listing [[lst:minimal-eglot-setup][minimal Eglot setup]] adds key bindings to =eglot-mode-keymap=.
listings set up [[https://github.com/joaotavora/eglot][Eglot]]:
1. Listing [[lst:minimal-eglot-setup][minimal Eglot setup]] adds key bindings to =eglot-mode-keymap= and
ensures automatic [[https://github.com/joaotavora/eglot][Eglot]] startup in case of visiting files in =python-mode=.
2. Listing [[lst:setup-oglot]] uses [[https://github.com/gav451/oglot#][oglot]] to enable using [[https://github.com/joaotavora/eglot][Eglot]] in =org-src-mode=
Python buffers (and not for Julia buffers).
3. Listing [[lst:eglot-maybe-ensure]] starts [[https://github.com/joaotavora/eglot][Eglot]] in case of proper programming
modes and proper directory local variables (meaning in presence of a proper
file [[info:emacs#Directory Variables][.dir-locals.el]] in the root directory of any project using proper
programming modes).
4. Listing [[lst:whiten-black]] defines Emacs Lisp functions to undo (whiten) some
output of [[https://black.readthedocs.io/en/stable/][Black]] after src_emacs-lisp[:results silent]{(org-babel-tangle)}.
Python buffers.
#+caption[Ensure =eglot= installation with minimal setup]:
#+caption: Ensure =eglot= installation with minimal setup.
@ -3803,6 +3797,8 @@ configuration:
(keymap-set eglot-mode-map "C-c n" 'flymake-goto-next-error)
(keymap-set eglot-mode-map "C-c p" 'flymake-goto-prev-error)
(keymap-set eglot-mode-map "C-c r" 'eglot-rename))
(add-hook 'python-mode-hook #'eglot-ensure)
#+end_src
#+caption: Setup ~oglot~ for ~python-mode~.
@ -3814,68 +3810,6 @@ configuration:
(setopt oglot-maybe-ensure-modes '(python-mode)))
#+end_src
#+caption[Start =eglot= in case of a proper =dir-local-variables-alist=]:
#+caption: Start =eglot= in case of a proper =dir-local-variables-alist=.
#+name: lst:eglot-maybe-ensure
#+begin_src emacs-lisp -n :results silent
(defun eglot-maybe-ensure ()
"Call `eglot-ensure' under favorable conditions."
(when (and (apply #'derived-mode-p '(python-mode))
(assoc 'eglot-workspace-configuration dir-local-variables-alist))
(eglot-ensure)))
;; The two hooks `after-change-major-mode-hook' and
;; `hack-local-variables-hook' are OK, but language mode hooks like
;; `python-mode-hook' are not.
(add-hook 'after-change-major-mode-hook #'eglot-maybe-ensure)
#+end_src
#+caption[Whiten Black]:
#+caption: Whiten Black
#+name: lst:whiten-black
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'emacs
(defun black-python-sequence ()
"Try to find a Blackened Python sequence to whiten."
(interactive)
(if (derived-mode-p 'python-mode)
(re-search-forward "[[(][ \t]*$" nil t)
(org-narrow-to-block)
(re-search-forward "[[(][ \t]*$" nil t)
(widen)))
(defun whiten--python-sequence ()
"Whiten a Blackened Python sequence without narrowing.
Call `widen' after an `user-error'."
(if (not (and (looking-at-p "[ \t]*$")))
(user-error "Call `widen': not seeing `new-line'")
(skip-chars-backward " \t\\[\\(")
(if (not (looking-at-p "[ \t]*[[(][ \t]*$"))
(user-error "Call `widen': not seeing `[' or `(' before `new-line'")
(fixup-whitespace)
(skip-chars-forward " \\[\\(")
(kill-line)
(fixup-whitespace)
(move-end-of-line 1)
(while (and (eq ?\, (char-before)))
(kill-line)
(fixup-whitespace)
(move-end-of-line 1))
(save-excursion
(when (memq (char-before) '(?\) ?\]))
(goto-char (1- (point)))
(delete-char -1))))))
(defun whiten-python-sequence ()
"Whiten a Blackened Python sequence. Call `widen' after an `user-error'."
(interactive)
(if (derived-mode-p 'python-mode)
(whiten--python-sequences)
(org-narrow-to-block)
(whiten--python-sequence)
(widen))))
#+end_src
** [[https://github.com/lassik/emacs-format-all-the-code#readme][Format-all]]
:PROPERTIES:
:CUSTOM_ID: sec:format-all
@ -4989,8 +4923,7 @@ Listing [[lst:configure-eglot+pylsp-ruff]] configures [[https://github.com/joaot
[[https://github.com/hhatto/autopep8#readme][autopep8]], [[https://github.com/PyCQA/flake8][flake8]], [[https://github.com/PyCQA/pydocstyle#readme][pydocstyle]], [[https://github.com/PyCQA/pylint#readme][pylint]], and [[https://github.com/python-rope/rope#readme][rope]].
Listing [[lst:eglot-directory-variables-for-python]] shows a proper [[info:emacs#Directory Variables][.dir-locals.el]]
file in the root directory of any [[https://www.python.org][Python]] project to start [[https://github.com/joaotavora/eglot][eglot]] automatically
according to the configuration in listing [[lst:eglot-maybe-ensure]].
file in the root directory of any [[https://www.python.org][Python]] project to start [[https://github.com/joaotavora/eglot][eglot]] automatically.
Type {{{kbd(M-x eglot-show-workspace-configuration)}}} to dump a =JSON=
representation of src_emacs-lisp[:results none]{(describe-variable