Added Babel diff function.

This commit is contained in:
James Patrick 2023-01-31 22:15:44 -05:00
parent c970a86cd6
commit 0c94f4f92d
2 changed files with 61 additions and 1 deletions

View File

@ -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)

View File

@ -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)