Compare commits

...

2 Commits

View File

@ -4561,9 +4561,8 @@ the Org-mode source block code before calling `eglot-ensure'."
filename)))
(goto-char (point-min))
(insert-file-contents filename 'visit nil nil 'replace)
(let ((max-point (search-forward body))
(min-point (search-backward body)))
(narrow-to-region min-point max-point))
(search-forward body)
(narrow-to-region (match-beginning 0) (match-end 0))
(goto-char mark)
(eglot-ensure)))
@ -4571,28 +4570,75 @@ the Org-mode source block code before calling `eglot-ensure'."
(eglot-org-babel-edit-prep info)))
#+end_src
#+caption: Make sessions for ~eval-buffer~ in ~org-src~ buffers.
#+begin_src emacs-lisp -n
#+caption[Make sessions for "eval-buffer" in "org-src-mode" buffers.]:
#+caption: Make sessions for ~eval-buffer~ in ~org-src-mode~ buffers.
#+caption: *Experimental: do not tangle*.
#+begin_src emacs-lisp -n :tangle no
(with-eval-after-load 'emacs
(defun org-babel-edit-prep:python (info)
(message "`%S'" info)
(let* ((session (cdr (assq :session (nth 2 info))))
(muffed (if (member session '(nil "none" ":default"))
(muffed (if (member session '("none" ":default")) ;; nil
"*Python*"
(org-babel-python-with-earmuffs session)))
(key (car (rassoc muffed org-babel-python-buffers))))
(message "obpb is `%S'" org-babel-python-buffers)
(message "session is `%S', muffed is `%S', key is `%S'" session muffed key)
;; (message "obpb is `%S'" org-babel-python-buffers)
;; (message "session is `%S', muffed is `%S', key is `%S'"
;; session muffed key)
(unless (and (get-buffer muffed)
(buffer-match-p '(major-mode . inferior-python-mode) muffed)
(get-process (org-babel-python-without-earmuffs muffed)))
(when (y-or-n-p "Start Python session?")
(org-babel-python-initiate-session
(if (eq key :default) nil (org-babel-python-without-earmuffs muffed))))
(message "obpb is `%S'" org-babel-python-buffers))
;; (message "obpb is `%S'" org-babel-python-buffers)
)
(setq-local python-shell-buffer-name
(org-babel-python-without-earmuffs muffed)))
;; (eglot-org-babel-edit-prep info)
)
(eglot-org-babel-edit-prep info)))
#+end_src
#+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
(with-eval-after-load 'emacs
;; https://www.reddit.com/r/emacs/comments/w4f4u3
;; /using_rustic_eglot_and_orgbabel_for_literate/
(defun undo-eglot-org-babel-edit-prep()
"Undo the `eglot' setup by deleting the text hidden by narrowing.
This is to advice `org-edit-src-exit' and `org-edit-src-save'."
(when (and (bound-and-true-p org-src-mode)
(buffer-file-name)
(apply #'derived-mode-p eglot-maybe-ensure-modes))
(save-excursion
(goto-char (point-min))
(save-restriction
(widen)
(delete-region (point-min) (point)))
(goto-char (point-max))
(save-restriction
(widen)
(delete-region (point) (point-max))))))
(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_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
(with-eval-after-load 'emacs
(defun eglot-maybe-ensure ()
(when (and (apply #'derived-mode-p eglot-maybe-ensure-modes)
(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: Real sessions for ~eval-buffer~ in ~org-src~ buffers.
@ -4668,49 +4714,6 @@ Hello *Python* with `*:default*' seen!
,#+end_src
#+end_src
#+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
(with-eval-after-load 'emacs
;; https://www.reddit.com/r/emacs/comments/w4f4u3
;; /using_rustic_eglot_and_orgbabel_for_literate/
(defun undo-eglot-org-babel-edit-prep()
"Undo the `eglot' setup by deleting the text hidden by narrowing.
This is to advice `org-edit-src-exit' and `org-edit-src-save'."
(when (and (bound-and-true-p org-src-mode)
(buffer-file-name)
(apply #'derived-mode-p eglot-maybe-ensure-modes))
(save-excursion
(goto-char (point-min))
(save-restriction
(widen)
(delete-region (point-min) (point)))
(goto-char (point-max))
(save-restriction
(widen)
(delete-region (point) (point-max))))))
(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_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
(with-eval-after-load 'emacs
(defun eglot-maybe-ensure ()
(when (and (apply #'derived-mode-p eglot-maybe-ensure-modes)
(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
** [[https://github.com/lassik/emacs-format-all-the-code#readme][Format-all]]
:PROPERTIES:
:CUSTOM_ID: sec:format-all
@ -5733,7 +5736,7 @@ arguments of listing [[lst:maxima-example]].
#+caption[Maxima example]:
#+caption: Maxima example.
#+caption: The code is fontified because =maxima-mode= is enabled.
#+caption: The code is not fontified because =maxima-mode= is not enabled.
#+header: :wrap "src text -n"
#+name: lst:maxima-example
#+begin_src maxima -n :batch batch :cmdline --quiet :exports both :results raw