From 0c94f4f92d49fc47c759ae8d240019eace2f4edc Mon Sep 17 00:00:00 2001 From: James Patrick Date: Tue, 31 Jan 2023 22:15:44 -0500 Subject: [PATCH] Added Babel diff function. --- emacs/+orgmode.el | 10 +++++++++ emacs/config.org | 52 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/emacs/+orgmode.el b/emacs/+orgmode.el index 1e5ff9e..8438c87 100644 --- a/emacs/+orgmode.el +++ b/emacs/+orgmode.el @@ -138,5 +138,15 @@ "#+title: %<%Y-%m-%d>\n#+filetags: %<:%Y:%B:>\n" ("Goals"))))) +(defun org-babel-execute:diff (body params) + "Applies diff patches. Use with care. +See https://emacs.stackexchange.com/questions/63517/org-mode-evaluate-diff-code-block" + (with-temp-buffer + (insert body "\n") + (shell-command-on-region (point-min) (point-max) "patch --strip=1" "*patch*") + (prog1 + (with-current-buffer "*patch*" (buffer-string)) + (kill-buffer "*patch*")))) + ;(add-hook! 'org-mode-hook #'solaire-mode) ;(add-hook 'mixed-pitch-mode-hook #'solaire-mode-reset) diff --git a/emacs/config.org b/emacs/config.org index 493f260..78c918c 100644 --- a/emacs/config.org +++ b/emacs/config.org @@ -451,7 +451,6 @@ literate (default +bindings +smartparens) #+end_src - ** Additional Keybinds Keybinds custom keybinds can be located at =$DOOMDIR/+keybinds.el=. @@ -749,6 +748,57 @@ We'll **** Keybinds These were declared in [[id:f9ffe9df-a417-45c4-8bf2-6ee655140648][Roam Keybinds]] section above. See there for more details. +*** Babel stuff +Babel execute can be tweaked per the syntax see orgmode docs [[https://orgmode.org/manual/Evaluating-Code-Blocks.html][here]]. + +**** Diff +The snippet below is largely pulled from John Kitchin [[https://emacs.stackexchange.com/questions/63517/org-mode-evaluate-diff-code-block/63520#63520][Stackexchange Post]]. + +#+begin_src emacs-lisp :tangle "+orgmode.el" :noweb no-export :comments no +(defun org-babel-execute:diff (body params) + "Applies diff patches. Use with care. +See https://emacs.stackexchange.com/questions/63517/org-mode-evaluate-diff-code-block" + (with-temp-buffer + (insert body "\n") + (shell-command-on-region (point-min) (point-max) "patch --strip=1" "*patch*") + (prog1 + (with-current-buffer "*patch*" (buffer-string)) + (kill-buffer "*patch*")))) +#+end_src + +As an sample: + +#+begin_example +#+BEGIN_SRC org :tangle a.org +1 +2 +#+END_SRC + +#+BEGIN_SRC org :tangle b.org +1 +3 +#+END_SRC +#+begin_src diff +--- a.org 2021-02-21 20:20:27.000000000 -0500 ++++ b.org 2021-02-21 20:20:27.000000000 -0500 +@@ -1,2 +1,2 @@ + 1 +-2 ++3 +#+end_src + +#+RESULTS: +: patching file a.org + +#+BEGIN_SRC sh +cat a.org +#+END_SRC + +#+RESULTS: +| 1 | +| 3 | +#+end_example + *** Solaire #+begin_src emacs-lisp :tangle "+orgmode.el" :noweb no-export :comments no ;(add-hook! 'org-mode-hook #'solaire-mode)