mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-25 07:27:57 +00:00
now possible to abort code block evaluation without throwing errors
this makes it possible to export while not evaluating some code blocks * lisp/ob-exp.el (org-babel-exp-do-export): removing hacky ":noeval", which is now an alias to ":eval no" * lisp/ob.el (org-babel-confirm-evaluate): ":noeval" is an alias for ":eval no", also no longer throwing errors (org-babel-header-arg-names): adding both eval and noeval as general header arguments (org-babel-execute-src-block): now using the new non-error confirmation functionality
This commit is contained in:
parent
2c33b2eb66
commit
e52909d902
@ -195,8 +195,7 @@ options are taken from `org-babel-default-header-args'."
|
|||||||
The function respects the value of the :exports header argument."
|
The function respects the value of the :exports header argument."
|
||||||
(flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
|
(flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
|
||||||
(when (and session
|
(when (and session
|
||||||
(not (equal "none" session))
|
(not (equal "none" session)))
|
||||||
(not (assoc :noeval (nth 2 info))))
|
|
||||||
(org-babel-exp-results info type 'silent))))
|
(org-babel-exp-results info type 'silent))))
|
||||||
(clean () (org-babel-remove-result info)))
|
(clean () (org-babel-remove-result info)))
|
||||||
(case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
|
(case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
|
||||||
|
137
lisp/ob.el
137
lisp/ob.el
@ -182,18 +182,20 @@ confirmation from the user.
|
|||||||
|
|
||||||
Note disabling confirmation may result in accidental evaluation
|
Note disabling confirmation may result in accidental evaluation
|
||||||
of potentially harmful code."
|
of potentially harmful code."
|
||||||
(let* ((eval (cdr (assoc :eval (nth 2 info))))
|
(let* ((eval (or (cdr (assoc :eval (nth 2 info)))
|
||||||
|
(when (assoc :noeval (nth 2 info)) "no")))
|
||||||
(query (or (equal eval "query")
|
(query (or (equal eval "query")
|
||||||
(and (functionp org-confirm-babel-evaluate)
|
(and (functionp org-confirm-babel-evaluate)
|
||||||
(funcall org-confirm-babel-evaluate
|
(funcall org-confirm-babel-evaluate
|
||||||
(nth 0 info) (nth 1 info)))
|
(nth 0 info) (nth 1 info)))
|
||||||
org-confirm-babel-evaluate)))
|
org-confirm-babel-evaluate)))
|
||||||
(when (or (equal eval "never")
|
(if (or (equal eval "never") (equal eval "no")
|
||||||
(and query
|
(and query
|
||||||
(not (yes-or-no-p
|
(not (yes-or-no-p
|
||||||
(format "Evaluate this%scode on your system? "
|
(format "Evaluate this%scode on your system? "
|
||||||
(if info (format " %s " (nth 0 info)) " "))))))
|
(if info (format " %s " (nth 0 info)) " "))))))
|
||||||
(error "evaluation aborted"))))
|
(prog1 nil (message "evaluation aborted"))
|
||||||
|
t)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-babel-execute-safely-maybe ()
|
(defun org-babel-execute-safely-maybe ()
|
||||||
@ -254,7 +256,7 @@ then run `org-babel-pop-to-session'."
|
|||||||
|
|
||||||
(defconst org-babel-header-arg-names
|
(defconst org-babel-header-arg-names
|
||||||
'(cache cmdline colnames dir exports file noweb results
|
'(cache cmdline colnames dir exports file noweb results
|
||||||
session tangle var noeval comments)
|
session tangle var eval noeval comments)
|
||||||
"Common header arguments used by org-babel.
|
"Common header arguments used by org-babel.
|
||||||
Note that individual languages may define their own language
|
Note that individual languages may define their own language
|
||||||
specific header arguments as well.")
|
specific header arguments as well.")
|
||||||
@ -322,66 +324,65 @@ Optionally supply a value for PARAMS which will be merged with
|
|||||||
the header arguments specified at the front of the source code
|
the header arguments specified at the front of the source code
|
||||||
block."
|
block."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((info (or info (org-babel-get-src-block-info)))
|
(let ((info (or info (org-babel-get-src-block-info))))
|
||||||
;; note the `evaluation-confirmed' variable is currently not
|
(when (org-babel-confirm-evaluate info)
|
||||||
;; used, but could be used later to avoid the need for
|
(let* ((lang (nth 0 info))
|
||||||
;; chaining confirmations
|
(params (setf
|
||||||
(evaluation-confirmed (org-babel-confirm-evaluate info))
|
(nth 2 info)
|
||||||
(lang (nth 0 info))
|
(sort (org-babel-merge-params (nth 2 info) params)
|
||||||
(params (setf (nth 2 info)
|
(lambda (el1 el2) (string< (symbol-name (car el1))
|
||||||
(sort (org-babel-merge-params (nth 2 info) params)
|
(symbol-name (car el2)))))))
|
||||||
(lambda (el1 el2) (string< (symbol-name (car el1))
|
(new-hash
|
||||||
(symbol-name (car el2)))))))
|
(if (and (cdr (assoc :cache params))
|
||||||
(new-hash
|
(string= "yes" (cdr (assoc :cache params))))
|
||||||
(if (and (cdr (assoc :cache params))
|
(org-babel-sha1-hash info)))
|
||||||
(string= "yes" (cdr (assoc :cache params))))
|
(old-hash (org-babel-result-hash info))
|
||||||
(org-babel-sha1-hash info)))
|
(body (setf (nth 1 info)
|
||||||
(old-hash (org-babel-result-hash info))
|
(if (and (cdr (assoc :noweb params))
|
||||||
(body (setf (nth 1 info)
|
(string= "yes" (cdr (assoc :noweb params))))
|
||||||
(if (and (cdr (assoc :noweb params))
|
(org-babel-expand-noweb-references info)
|
||||||
(string= "yes" (cdr (assoc :noweb params))))
|
(nth 1 info))))
|
||||||
(org-babel-expand-noweb-references info)
|
(result-params (split-string (or (cdr (assoc :results params)) "")))
|
||||||
(nth 1 info))))
|
(result-type (cond ((member "output" result-params) 'output)
|
||||||
(result-params (split-string (or (cdr (assoc :results params)) "")))
|
((member "value" result-params) 'value)
|
||||||
(result-type (cond ((member "output" result-params) 'output)
|
(t 'value)))
|
||||||
((member "value" result-params) 'value)
|
(cmd (intern (concat "org-babel-execute:" lang)))
|
||||||
(t 'value)))
|
(dir (cdr (assoc :dir params)))
|
||||||
(cmd (intern (concat "org-babel-execute:" lang)))
|
(default-directory
|
||||||
(dir (cdr (assoc :dir params)))
|
(or (and dir (file-name-as-directory dir)) default-directory))
|
||||||
(default-directory
|
(org-babel-call-process-region-original
|
||||||
(or (and dir (file-name-as-directory dir)) default-directory))
|
(if (boundp 'org-babel-call-process-region-original)
|
||||||
(org-babel-call-process-region-original
|
org-babel-call-process-region-original
|
||||||
(if (boundp 'org-babel-call-process-region-original) org-babel-call-process-region-original
|
(symbol-function 'call-process-region)))
|
||||||
(symbol-function 'call-process-region)))
|
(indent (car (last info)))
|
||||||
(indent (car (last info)))
|
result)
|
||||||
result)
|
(unwind-protect
|
||||||
(unwind-protect
|
(flet ((call-process-region (&rest args)
|
||||||
(flet ((call-process-region (&rest args)
|
(apply 'org-babel-tramp-handle-call-process-region args)))
|
||||||
(apply 'org-babel-tramp-handle-call-process-region args)))
|
(unless (fboundp cmd)
|
||||||
(unless (fboundp cmd)
|
(error "No org-babel-execute function for %s!" lang))
|
||||||
(error "No org-babel-execute function for %s!" lang))
|
(if (and (not arg) new-hash (equal new-hash old-hash))
|
||||||
(if (and (not arg) new-hash (equal new-hash old-hash))
|
(save-excursion ;; return cached result
|
||||||
(save-excursion ;; return cached result
|
(goto-char (org-babel-where-is-src-block-result nil info))
|
||||||
(goto-char (org-babel-where-is-src-block-result nil info))
|
(end-of-line 1) (forward-char 1)
|
||||||
(end-of-line 1) (forward-char 1)
|
(setq result (org-babel-read-result))
|
||||||
(setq result (org-babel-read-result))
|
(message (replace-regexp-in-string
|
||||||
(message (replace-regexp-in-string "%" "%%"
|
"%" "%%" (format "%S" result))) result)
|
||||||
(format "%S" result))) result)
|
(message "executing %s code block%s..."
|
||||||
(message "executing %s code block%s..."
|
(capitalize lang)
|
||||||
(capitalize lang)
|
(if (nth 4 info) (format " (%s)" (nth 4 info)) ""))
|
||||||
(if (nth 4 info) (format " (%s)" (nth 4 info)) ""))
|
(setq result (funcall cmd body params))
|
||||||
(setq result (funcall cmd body params))
|
(if (eq result-type 'value)
|
||||||
(if (eq result-type 'value)
|
(setq result (if (and (or (member "vector" result-params)
|
||||||
(setq result (if (and (or (member "vector" result-params)
|
(member "table" result-params))
|
||||||
(member "table" result-params))
|
(not (listp result)))
|
||||||
(not (listp result)))
|
(list (list result))
|
||||||
(list (list result))
|
result)))
|
||||||
result)))
|
(org-babel-insert-result
|
||||||
(org-babel-insert-result
|
result result-params info new-hash indent lang)
|
||||||
result result-params info new-hash indent lang)
|
(run-hooks 'org-babel-after-execute-hook)
|
||||||
(run-hooks 'org-babel-after-execute-hook)
|
result))
|
||||||
result))
|
(setq call-process-region 'org-babel-call-process-region-original))))))
|
||||||
(setq call-process-region 'org-babel-call-process-region-original))))
|
|
||||||
|
|
||||||
(defun org-babel-expand-body:generic (body params &optional processed-params)
|
(defun org-babel-expand-body:generic (body params &optional processed-params)
|
||||||
"Expand BODY with PARAMS.
|
"Expand BODY with PARAMS.
|
||||||
|
Loading…
Reference in New Issue
Block a user