mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
lang/org: add eval handler
With this, gr and gR will now work in babel blocks to execute a subset of the block (or the whole thing, if you'd like). Results are displayed in a popup buffer (or overlay if :tools (eval +overlay) is enabled).
This commit is contained in:
29
modules/lang/org/autoload/org-babel.el
Normal file
29
modules/lang/org/autoload/org-babel.el
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
;;; lang/org/autoload/org-babel.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +org-eval-handler (beg end)
|
||||||
|
"TODO"
|
||||||
|
(save-excursion
|
||||||
|
(if (not (cl-loop for pos in (list beg (point) end)
|
||||||
|
if (save-excursion (goto-char pos) (org-in-src-block-p t))
|
||||||
|
return (goto-char pos)))
|
||||||
|
(message "Nothing to evaluate at point")
|
||||||
|
(org-babel-where-is-src-block-head)
|
||||||
|
(let ((beg (max beg (match-beginning 5)))
|
||||||
|
(end (min end (match-end 5)))
|
||||||
|
(major-mode
|
||||||
|
(org-src-get-lang-mode (or (org-eldoc-get-src-lang)
|
||||||
|
(user-error "No lang specified for this src block")))))
|
||||||
|
(+eval/region beg end)))))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;;; Hooks
|
||||||
|
|
||||||
|
;;;###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))
|
@ -468,14 +468,6 @@ All my (performant) foldings needs are met between this and `org-show-subtree'
|
|||||||
(org-cycle-internal-local)
|
(org-cycle-internal-local)
|
||||||
t)))))
|
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
|
;;;###autoload
|
||||||
(defun +org-make-last-point-visible-h ()
|
(defun +org-make-last-point-visible-h ()
|
||||||
"Unfold subtree around point if saveplace places us in a folded region."
|
"Unfold subtree around point if saveplace places us in a folded region."
|
||||||
|
@ -195,6 +195,8 @@ This forces it to read the background before rendering."
|
|||||||
|
|
||||||
|
|
||||||
(defun +org-init-babel-h ()
|
(defun +org-init-babel-h ()
|
||||||
|
(set-eval-handler! 'org-mode #'+org-eval-handler)
|
||||||
|
|
||||||
(setq org-src-preserve-indentation t ; use native major-mode indentation
|
(setq org-src-preserve-indentation t ; use native major-mode indentation
|
||||||
org-src-tab-acts-natively t ; we do this ourselves
|
org-src-tab-acts-natively t ; we do this ourselves
|
||||||
;; You don't need my permission (just be careful, mkay?)
|
;; You don't need my permission (just be careful, mkay?)
|
||||||
@ -1009,8 +1011,6 @@ compelling reason, so..."
|
|||||||
:m "]c" #'org-babel-next-src-block
|
:m "]c" #'org-babel-next-src-block
|
||||||
:m "[c" #'org-babel-previous-src-block
|
:m "[c" #'org-babel-previous-src-block
|
||||||
:n "gQ" #'org-fill-paragraph
|
:n "gQ" #'org-fill-paragraph
|
||||||
:n "gr" #'org-ctrl-c-ctrl-c
|
|
||||||
:n "gR" #'org-babel-execute-buffer
|
|
||||||
;; sensible vim-esque folding keybinds
|
;; sensible vim-esque folding keybinds
|
||||||
:n "za" #'+org/toggle-fold
|
:n "za" #'+org/toggle-fold
|
||||||
:n "zA" #'org-shifttab
|
:n "zA" #'org-shifttab
|
||||||
|
Reference in New Issue
Block a user