From 884670d13fc509e5be32dfb28db0d1131ca624ce Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 18 Nov 2023 10:02:48 -0800 Subject: org-mode read-only-aware src block editing --- init-el.org | 109 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/init-el.org b/init-el.org index 141993f..a9efa57 100644 --- a/init-el.org +++ b/init-el.org @@ -33,6 +33,8 @@ (insert-file-contents f) (buffer-string))) + + #+end_src @@ -135,7 +137,7 @@ I'm using melpa and elpa package archives. (def-my-command my-leader-command '((?/ "[/] search buffer" swiper) - (?? "[?] imenu" imenu) + (?? "[?] imenu" imenu-list) (?q "[q]uery replace" query-replace) (?e "[e]diting" my-special-edit-command) (?' "['] shell" persp-shell--jump-to-persp-shell) @@ -286,6 +288,39 @@ I'm using melpa and elpa package archives. #+name: org-mode-leader-key-menu #+begin_src elisp :results none :noweb no-export +(defun org-src--source-buffer () + (marker-buffer org-src--beg-marker)) + +(defun buffer-read-only-p (buffer) + "Returns T if BUFFER, which can be a name or a buffer, is read only." + (buffer-local-value 'buffer-read-only (get-buffer buffer))) + +(defvar org-src--read-only-source-buffer-cache nil + "") + +(defun before-org-edit-src-exit (&rest args) + "If necessary, make the org src buffer's target buffer writable +prior to exiting." + (let ((target-buffer (org-src--source-buffer))) + (when (buffer-read-only-p target-buffer) + (setf org-src--read-only-source-buffer-cache target-buffer) + (with-current-buffer target-buffer + (read-only-mode 0))))) + +(defun after-org-edit-src-exit (&rest args) + "If necessary, make the org src buffer's target buffer read-only +again, if it was whent he org edit src buffer was opened." + (when org-src--read-only-source-buffer-cache + (with-current-buffer org-src--read-only-source-buffer-cache + (read-only-mode 1)) + (setf org-src--read-only-source-buffer-cache nil))) + +(advice-add 'org-edit-src-exit + :before #'before-org-edit-src-exit) + +(advice-add 'org-edit-src-exit + :after #'after-org-edit-src-exit) + (def-my-command my-org-command '((?/ "[/] sparse tree" org-sparse-tree) (?g "[g]oto" org-goto) @@ -398,6 +433,18 @@ e.g. here's one for org capture javascript:location.href='org-protocol://capture:/w/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection()) #+end_src +** Bells and Whistles + +#+name: org-bells-and-wistles +#+begin_src elisp :results none +(package-install 'org-superstar) +(require 'org-superstar) +(add-hook 'org-mode-hook (lambda () + (org-superstar-mode 1) + (visual-line-mode))) + +#+end_src + * UI @@ -464,18 +511,6 @@ e.g. here's one for org capture (global-hl-line-mode 1) -#+end_src - -** Bells and Whistles - -#+name: ui-bells-and-wistles -#+begin_src elisp :results none -(package-install 'org-superstar) -(require 'org-superstar) -(add-hook 'org-mode-hook (lambda () - (org-superstar-mode 1) - (visual-line-mode))) - #+end_src ** Completions Engine @@ -625,7 +660,7 @@ e.g. here's one for org capture (package-install 'autothemer) ;; for custom themes (setq my-installed-themes - '(yoshi-theme solarized-theme)) + '(yoshi-theme leuven-theme)) (dolist (package my-installed-themes) @@ -729,9 +764,7 @@ LOAD-THEME" #+begin_src elisp :noweb no-export :results none (setq *coding-themes* - (append '(yoshi) - (mapcan 'themes-in-package - '(solarized-theme)))) + (append '(leuven yoshi leuven-dark))) (setq *writing-themes* (themes-in-package 'poet)) @@ -876,19 +909,6 @@ stand up and move around. #+end_src - -** CRDT -#+name: crdt-config -#+begin_src elisp :noweb no-export :results none -(def-my-command my-crdt-commands - '((?s "[s]hare this buffer" crdt-share-buffer) - (?f "[f]ollow a user" crdt-follow-user) - (?u "[u]nfollow a user" crdt-stop-follow) - (?C "[C]lose connection" crdt-disconnect) - (?c "[c]onnect" crdt-connect) - (?l "[l]ist buffers" crdt-list-buffers))) - -#+end_src * Reading, Notes, and Writing ** General Reading Tools @@ -896,7 +916,7 @@ stand up and move around. wordnut is a wordnet interface #+name: general-reading-tools -#+begin_src elisp :noweb no-export +#+begin_src elisp :noweb no-export :results none (package-install 'wordnut) @@ -906,8 +926,14 @@ wordnut is a wordnet interface #+end_src -#+RESULTS: general-reading-tools -: my-reading-command +imenu-list displayes imenu results in a a navigable table-of-contents tree-like format. + +#+name: imenu-list +#+begin_src elisp :noweb no-export + +(package-install 'imenu-list) + +#+end_src ** Calibre db @@ -1267,6 +1293,16 @@ code in emacs org blocks. #+name: crdt-config #+begin_src elisp :results none (package-install 'crdt) + +(def-my-command my-crdt-commands + '((?s "[s]hare this buffer" crdt-share-buffer) + (?f "[f]ollow a user" crdt-follow-user) + (?u "[u]nfollow a user" crdt-stop-follow) + (?C "[C]lose connection" crdt-disconnect) + (?c "[c]onnect" crdt-connect) + (?l "[l]ist buffers" crdt-list-buffers))) + + #+end_src ** Tools Essential To Development @@ -1612,7 +1648,6 @@ from debian contrib #+RESULTS: python-config * Tools - ** Export Emacs Buffer #+name: buffer-export-config @@ -1677,6 +1712,7 @@ emacs loads at startup. <> <> <> +<> ;;;;;;;; ;; UI ;; @@ -1685,9 +1721,8 @@ emacs loads at startup. <> <> <> -<> -<> +<> <> <> <> @@ -1716,7 +1751,7 @@ emacs loads at startup. ;;;;;;;;;;;;;;;;;;;;;;;;; <> -<> + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; READING, WRITING, AND NOTETAKING ;; -- cgit v1.2.3