about summary refs log tree commit diff
path: root/+bindings.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-03-13T16·33-0400
committerGriffin Smith <root@gws.fyi>2019-03-13T16·33-0400
commit857bb51980457e0d34aea80f9095b3b03e70b874 (patch)
tree3eed15f0828d6b58242faf66c78be6060ce36d67 /+bindings.el
parentfe879c97f3b8b9c04f800ebadc055790abc7cb32 (diff)
binding to insert new source blocks
Diffstat (limited to '+bindings.el')
-rw-r--r--+bindings.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/+bindings.el b/+bindings.el
index a0c4467319..c3acadf295 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