From 857bb51980457e0d34aea80f9095b3b03e70b874 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 13 Mar 2019 12:33:05 -0400 Subject: binding to insert new source blocks --- +bindings.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/+bindings.el b/+bindings.el index a0c4467319b2..c3acadf295fd 100644 --- a/+bindings.el +++ b/+bindings.el @@ -1110,6 +1110,37 @@ If invoked with a prefix ARG eval the expression after inserting it" nil nil nil))) +(defun grfn/insert-new-src-block () + (interactive) + (let* ((current-src-block (org-element-at-point)) + (src-block-head (save-excursion + (goto-char (org-element-property + :begin current-src-block)) + (thing-at-point 'line t))) + (point-to-insert + (if-let (results-loc (org-babel-where-is-src-block-result)) + (save-excursion + (goto-char results-loc) + (org-element-property + :end + (org-element-at-point))) + (org-element-property :end (org-element-at-point))))) + (goto-char point-to-insert) + (insert "\n") + (insert src-block-head) + (let ((contents (point-marker))) + (insert "\n#+END_SRC\n") + (goto-char contents)))) + +(defun grfn/+org-insert-item (orig direction) + (interactive) + (if (and (org-in-src-block-p) + (equal direction 'below)) + (grfn/insert-new-src-block) + (funcall orig direction))) + +(advice-add #'+org/insert-item :around #'grfn/+org-insert-item) + (map! (:map magit-mode-map -- cgit 1.4.1