From b9f90b3a1a4055fec9c88034153a70de6b501e1e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 30 Dec 2019 00:07:19 -0500 Subject: [PATCH] lang/org: clear src block results on TAB When cursor is inside a src block. e.g. #+BEGIN_SRC elisp <-- not here (message "hi") <-- in here #+END_SRC <-- not here --- modules/lang/org/autoload/org.el | 8 ++++++++ modules/lang/org/config.el | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/lang/org/autoload/org.el b/modules/lang/org/autoload/org.el index 14ea6d959..511f908fe 100644 --- a/modules/lang/org/autoload/org.el +++ b/modules/lang/org/autoload/org.el @@ -406,6 +406,14 @@ with `org-cycle')." (org-cycle-internal-local) t))))) +;;;###autoload +(defun +org-clear-babel-results-h () + "Remove the results block for the org babel block at point." + (when (and (org-in-src-block-p t) + (org-babel-where-is-src-block-result)) + (org-babel-remove-result) + t)) + ;;;###autoload (defun +org-unfold-to-2nd-level-or-point-h () "My version of the 'overview' #+STARTUP option: expand first-level headings. diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index ffce10b0c..5ac1e8de1 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -850,8 +850,11 @@ compelling reason, so..." (defvar evil-org-use-additional-insert t) :config (evil-org-set-key-theme) - ;; Only fold the current tree, rather than recursively - (add-hook 'org-tab-first-hook #'+org-cycle-only-current-subtree-h 'append) + (add-hook! 'org-tab-first-hook :append + ;; Only fold the current tree, rather than recursively + #'+org-cycle-only-current-subtree-h + ;; Clear babel results if point is inside a src block + #'+org-clear-babel-results-h) (map! :map evil-org-mode-map :ni [C-return] #'+org/insert-item-below :ni [C-S-return] #'+org/insert-item-above