Move Org source blocks with Eglot functionality to `oglot' library

This commit is contained in:
Gerard Vermeulen 2024-02-24 16:06:48 +01:00
parent a43104c2eb
commit c81a45820e
1 changed files with 27 additions and 18 deletions

View File

@ -2988,8 +2988,8 @@ to add =HTML+CSS+JS= for ~mhtml-mode~:
#+caption[Buffer properties]:
#+caption: Buffer properties.
#+name: lst:buffer-properties
#+begin_src emacs-lisp -n :results silent
#+name: lst:buffer-properties-XXX
#+begin_src emacs-lisp -n :results silent :tangle no
(with-eval-after-load 'org
(defconst prop-comments-link-re
"\\( :comments link$\\)\\|\\( *$\\)"
@ -3008,20 +3008,24 @@ to add =HTML+CSS+JS= for ~mhtml-mode~:
(format prop-ha-re-template "python")
"Regexp to find `#+property:' Python header arguments.")
(defun prop-python-link-comments-toggle ()
(defun prop-python-comments-link-toggle ()
(interactive)
(save-excursion
(goto-char (point-min))
(if (re-search-forward prop-python-ha-re nil 'noerror)
(if (re-search-forward prop-comments-link-re nil t)
(if (match-string 1)
(replace-match " ")
(replace-match " :comments link"))
(user-error "Found no python link comment"))
(user-error "Found no python header arguments property")))
(move-beginning-of-line 1)
(org-ctrl-c-ctrl-c))
(when (re-search-forward prop-comments-link-re nil t)
(if (match-string 1)
(replace-match " ")
(replace-match " :comments link"))
(org-ctrl-c-ctrl-c))
(user-error "Found no python header arguments property")))))
#+end_src
#+caption[Buffer properties]:
#+caption: Buffer properties.
#+name: lst:buffer-properties
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'org
(defun org-get-buffer-properties ()
"Get all properties in buffer."
(org-element-map (org-element-parse-buffer) 'keyword
@ -4779,7 +4783,7 @@ configuration:
#+caption: 1st help to setup any =org-src-mode= buffers for =eglot=.
#+caption: Bad practice.
#+name: lst:help-setup-org-src-mode-for-eglot-1
#+begin_src emacs-lisp -n :results silent
#+begin_src emacs-lisp -n :results silent :tangle no
;;; Begin: Eglot and Org Babel source blocks
;; https://www.reddit.com/r/emacs/comments/w4f4u3
@ -4824,7 +4828,7 @@ the Org-mode source block code before calling `eglot-ensure'."
#+caption: 2nd help to setup any =org-src-mode= buffers for =eglot=.
#+caption: Best practice.
#+name: lst:help-setup-org-src-mode-for-eglot-2
#+begin_src emacs-lisp -n :results silent
#+begin_src emacs-lisp -n :results silent :tangle no
;; https://www.reddit.com/r/emacs/comments/w4f4u3
;; /using_rustic_eglot_and_orgbabel_for_literate/
(defun eglot-org-babel-edit-prep (info)
@ -4871,7 +4875,7 @@ the Org-mode source block code before calling `eglot-ensure'."
#+caption: 3rd help to setup any =org-src-mode= buffers for =eglot=.
#+caption: Good practice.
#+name: lst:help-setup-org-src-mode-for-eglot-3
#+begin_src emacs-lisp -n :results silent
#+begin_src emacs-lisp -n :results silent :tangle no
;; https://www.reddit.com/r/emacs/comments/w4f4u3
;; /using_rustic_eglot_and_orgbabel_for_literate/
(defun eglot-org-babel-edit-prep-if-let (info)
@ -4919,7 +4923,7 @@ the Org-mode source block code before calling `eglot-ensure'."
#+caption[Setup Python =org-src-mode= buffers for =eglot=]:
#+caption: Setup Python =org-src-mode= buffers for =eglot=.
#+name: lst:setup-python-org-src-mode-for-eglot
#+begin_src emacs-lisp -n :results silent
#+begin_src emacs-lisp -n :results silent :tangle no
;; https://www.reddit.com/r/emacs/comments/w4f4u3
;; /using_rustic_eglot_and_orgbabel_for_literate/
(defun org-babel-edit-prep:python (info)
@ -4948,6 +4952,13 @@ This is to advice `org-edit-src-exit' and `org-edit-src-save'."
(advice-add 'org-edit-src-exit :before #'undo-eglot-org-babel-edit-prep)
(advice-add 'org-edit-src-save :before #'undo-eglot-org-babel-edit-prep)
;;; End: Eglot and Org Babel source blocks
#+end_src
#+begin_src emacs-lisp -n :results silent
(when (package-installed-p 'oglot)
(require 'oglot))
#+end_src
#+caption[Start =eglot= in case of a proper =dir-local-variables-alist=]:
@ -4955,7 +4966,7 @@ This is to advice `org-edit-src-exit' and `org-edit-src-save'."
#+name: lst:eglot-maybe-ensure
#+begin_src emacs-lisp -n :results silent
(defun eglot-maybe-ensure ()
(when (and (apply #'derived-mode-p eglot-maybe-ensure-modes)
(when (and (apply #'derived-mode-p '(python-mode))
(assoc 'eglot-workspace-configuration dir-local-variables-alist))
(eglot-ensure)))
@ -4963,8 +4974,6 @@ This is to advice `org-edit-src-exit' and `org-edit-src-save'."
;; `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: Eglot and Org Babel source blocks
#+end_src
#+caption[Whiten Black]: