aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-11-18 10:02:48 -0800
committercolin <colin@cicadas.surf>2023-11-18 10:02:48 -0800
commit884670d13fc509e5be32dfb28db0d1131ca624ce (patch)
treefcb348d136342cee653625483ec95fd5df561f88
parentaa504e816bf152d0b665d84a4b84a1c0b601c85c (diff)
org-mode read-only-aware src block editing
-rw-r--r--init-el.org109
1 files 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
@@ -466,18 +513,6 @@ e.g. here's one for org capture
#+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
#+name: ui-completion-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.
<<org-mode-main-config>>
<<org-mode-leader-key-menu>>
<<org-protocol-config>>
+<<org-bells-and-wistles>>
;;;;;;;;
;; UI ;;
@@ -1685,9 +1721,8 @@ emacs loads at startup.
<<ui-chrome-config>>
<<ui-tweaks-config>>
<<ui-fonts-config>>
-<<ui-bells-and-wistles>>
-<<ui-completion-engine>>
+<<ui-completion-engine>>
<<ui-windows-and-perspectives-packages>>
<<ui-window-leader-key-menu>>
<<ui-buffer-leader-key-menu>>
@@ -1716,7 +1751,7 @@ emacs loads at startup.
;;;;;;;;;;;;;;;;;;;;;;;;;
<<erc-config>>
-<<crdt-config>>
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; READING, WRITING, AND NOTETAKING ;;