emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Import Reusable org-babel snippet using #+SETUPFILE


From: Douglas Perrin
Subject: Re: Import Reusable org-babel snippet using #+SETUPFILE
Date: Thu, 18 Jun 2020 12:03:30 -0400

Hi Salomon,
Babel definitions, in this case, lots of elsip blocks to add behaviors like this example to clear bloc results on save to avoid polluting commits that can be turned on and off per section with properties.

#+name: Clear-Results-On-Save
#+begin_src emacs-lisp :results none
;;; code to clean up org-file results on save
(defun CHAI-ClearResultsOnSave ()
  (when (eq major-mode 'org-mode)
    (org-babel-map-executables nil 
      (cond ((equal "true" (org-entry-get nil "ClearOnSave" t t))
             (org-babel-remove-result))
            ))
    ))

;;; interactive version that ignores PROPERTIES and clears all results
(defun CHAI-ClearResultsNow ()
  (interactive)
  (when (eq major-mode 'org-mode)
    (org-babel-map-executables nil (org-babel-remove-result))
    ))

;;; add the hook before saving a file
(add-hook 'before-save-hook 'CHAI-ClearResultsOnSave nil t)
#+end_src

In this case, the init block in the template.org file would have an org-sbe call to "Clear-Results-On-Save" after ingesting GeneralORGTools.org if I wanted that behavior. By convention, I always have an init bloc but in this case it is not very interesting:

#+name:GeneralORGTools_Init
#+BEGIN_SRC elisp
  ;; nice org-mode setting to remove newlines from the outline
  (setq org-cycle-separator-lines 0)
 #+end_src

**correction from my previous post**:
 (org-sbe "GeneralORGTools.org") '
should have been a call to the init 
(org-sbe ":GeneralORGTools_Init")

Regards
Doug

reply via email to

[Prev in Thread] Current Thread [Next in Thread]