Fix last commit: replace defvar' with defcustom'

This commit is contained in:
Gerard Vermeulen 2023-12-16 14:02:02 +01:00
parent c09ed7bbb9
commit 2c9932c95a

View File

@ -2342,28 +2342,34 @@ list detailing and motivating each listing:
;; Modified from https://emacs.stackexchange.com/a/61364 which replies to
;; https://emacs.stackexchange.com/questions/61359/
;; "How to specify a directory to tangle all code blocks into".
(defvar post-tangle-hook-dir nil
(defcustom org-babel-post-tangle-dir nil
"Destination directory used by `dir+org-babel-post-tangle'.
May be changed by `toggle-post-tangle-hook-dir-usage'.")
May be changed by `toggle-post-tangle-hook-dir-usage'."
:group 'org-babel)
(defcustom org-babel-post-tangle-dir-modes '(emacs-lisp-mode)
"Modes for which `dir+org-babel-post-tangle' does what it has to do."
:group 'org-babel)
(defun dir+org-babel-post-tangle ()
"Function to hook on `org-babel-post-tangle-hook'."
(when (and (bound-and-true-p post-tangle-hook-dir)
(derived-mode-p '(emacs-lisp-mode)))
(message "Tangle into `%S'" post-tangle-hook-dir)
(rename-file (buffer-file-name) post-tangle-hook-dir t)))
(when (and org-babel-post-tangle-dir
(derived-mode-p org-babel-post-tangle-dir-modes))
(message "Tangle `%S' modes into `%S'"
org-babel-post-tangle-dir-modes org-babel-post-tangle-dir)
(rename-file (buffer-file-name) org-babel-post-tangle-dir t)))
(defun toggle-post-tangle-hook-dir-usage ()
"Toggle tangling to `post-tangle-hook-dir' by `dir+org-babel-post-tangle'."
"Toggle tangling to `org-babel-post-tangle-dir'."
(interactive)
(if (member 'dir+org-babel-post-tangle org-babel-post-tangle-hook)
(progn
(setq post-tangle-hook-dir nil)
(message "Disable tangling into `post-tangle-hook-dir'")
(setq org-babel-post-tangle-dir nil)
(message "Disable tangling (into `%S')" org-babel-post-tangle-dir)
(remove-hook 'org-babel-post-tangle-hook #'dir+org-babel-post-tangle))
(setq post-tangle-hook-dir (org-entry-get nil "post-tangle-hook-dir" t))
(message "Enable tangling into `post-tangle-hook-dir' which equals `%S'"
post-tangle-hook-dir)
(setq org-babel-post-tangle-dir (org-entry-get nil "tangle-dir" t))
(message "Enable tangling (into `%S')" org-babel-post-tangle-dir)
(add-hook 'org-babel-post-tangle-hook #'dir+org-babel-post-tangle))))
#+end_src