瀏覽代碼

Better integration between Babel and `C-c C-c'

* lisp/org.el (org-ctrl-c-ctrl-c): Handle Babel context without relying
  to user hooks.
* lisp/ob-core.el (org-babel-execute-maybe):
(org-babel-hash-at-point): Do not functions in `C-c C-c' hook.
Nicolas Goaziou 8 年之前
父節點
當前提交
6ca5cc8efb
共有 2 個文件被更改,包括 19 次插入11 次删除
  1. 0 3
      lisp/ob-core.el
  2. 19 8
      lisp/org.el

+ 0 - 3
lisp/ob-core.el

@@ -298,8 +298,6 @@ environment, to override this check."
   (unless org-babel-no-eval-on-ctrl-c-ctrl-c
     (org-babel-execute-maybe)))
 
-(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-execute-safely-maybe)
-
 ;;;###autoload
 (defun org-babel-execute-maybe ()
   (interactive)
@@ -1329,7 +1327,6 @@ This can be called with `\\[org-ctrl-c-ctrl-c]'."
 			      (lambda (ol) (overlay-get ol 'babel-hash))
                               (overlays-at (or point (point))))))))
     (when hash (kill-new hash) (message hash))))
-(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-hash-at-point)
 
 (defun org-babel-result-hide-spec ()
   "Hide portions of results lines.

+ 19 - 8
lisp/org.el

@@ -21102,6 +21102,7 @@ This command does many different things, depending on context:
    ((and (local-variable-p 'org-finish-function)
 	 (fboundp org-finish-function))
     (funcall org-finish-function))
+   ((org-babel-hash-at-point))
    ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
    ((save-excursion (beginning-of-line) (looking-at-p "[ \t]*$"))
     (or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
@@ -21113,10 +21114,12 @@ This command does many different things, depending on context:
 	    (org-element-lineage
 	     (org-element-context)
 	     ;; Limit to supported contexts.
-	     '(clock dynamic-block footnote-definition footnote-reference
-		     item keyword node-property paragraph plain-list
-		     property-drawer radio-target statistics-cookie table
-		     table-cell table-row timestamp)
+	     '(babel-call clock dynamic-block footnote-definition
+			  footnote-reference inline-babel-call inline-src-block
+			  item keyword node-property paragraph plain-list
+			  property-drawer radio-target src-block
+			  statistics-cookie table table-cell table-row
+			  timestamp)
 	     t))
 	   (type (org-element-type context)))
       ;; For convenience: at the first line of a paragraph on the same
@@ -21130,6 +21133,9 @@ This command does many different things, depending on context:
 	    (setq type 'item))))
       ;; Act according to type of element or object at point.
       (pcase type
+	((or `babel-call `inline-babel-call)
+	 (let ((info (org-babel-lob-get-info context)))
+	   (when info (org-babel-execute-src-block nil info))))
 	(`clock (org-clock-update-time-maybe))
 	(`dynamic-block
 	 (save-excursion
@@ -21142,11 +21148,16 @@ This command does many different things, depending on context:
 	((or `headline `inlinetask)
 	 (save-excursion (goto-char (org-element-property :begin context))
 			 (call-interactively #'org-set-tags)))
+	((or `inline-src-block `src-block)
+	 (unless org-babel-no-eval-on-ctrl-c-ctrl-c
+	   (org-babel-eval-wipe-error-buffer)
+	   (org-babel-execute-src-block
+	    current-prefix-arg (org-babel-get-src-block-info nil context))))
 	(`item
-	 ;; At an item: a double C-u set checkbox to "[-]"
-	 ;; unconditionally, whereas a single one will toggle its
-	 ;; presence.  Without a universal argument, if the item has
-	 ;; a checkbox, toggle it.  Otherwise repair the list.
+	 ;; At an item: `C-u C-u' sets checkbox to "[-]"
+	 ;; unconditionally, whereas `C-u' will toggle its presence.
+	 ;; Without a universal argument, if the item has a checkbox,
+	 ;; toggle it.  Otherwise repair the list.
 	 (let* ((box (org-element-property :checkbox context))
 		(struct (org-element-property :structure context))
 		(old-struct (copy-tree struct))