* [PATCH] Add :eval only-manual to babel blocks
@ 2019-10-14 7:10 Ken Mankoff
2019-10-16 6:05 ` Ken Mankoff
0 siblings, 1 reply; 7+ messages in thread
From: Ken Mankoff @ 2019-10-14 7:10 UTC (permalink / raw)
To: Org Mailing List
[-- Attachment #1: Type: text/plain, Size: 302 bytes --]
With this patch and ":eval only-manual" in a babel header,
Org evaluates the source code if it is run via ~org-ctrl-c-ctrl-c~ (e.g. =C-c C-c= in the babel block), but not if run via the ~org-babel-execute-buffer~ function.
This is my first contribution to Org core. I've signed FSF papers.
-k.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-babel-only-manual.patch --]
[-- Type: text/x-diff, Size: 2077 bytes --]
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 59591894d..aa72c642c 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17051,6 +17051,12 @@ evaluating untrusted code blocks by prompting for a confirmation.
Org does not evaluate the source code when exporting, yet the user
can evaluate it interactively.
+- =only-manual= ::
+
+ Org evaluates the source code if it is run via ~org-ctrl-c-ctrl-c~
+ (e.g. =C-c C-c= in the babel block), but not if run via the
+ ~org-babel-execute-buffer~ function.
+
- =query-export= ::
Org prompts the user for permission to evaluate the source code
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 572f97919..15fadadf0 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -228,7 +228,9 @@ should be asked whether to allow evaluation."
(let* ((headers (nth 2 info))
(eval (or (cdr (assq :eval headers))
(when (assq :noeval headers) "no")))
- (eval-no (member eval '("no" "never")))
+ (manual (and (not (eq nil (member 'org-ctrl-c-ctrl-c (org--function-stack))))
+ (not (eq nil (member eval '("only-manual"))))))
+ (eval-no (member eval '("no" "never" "only-manual")))
(export org-babel-exp-reference-buffer)
(eval-no-export (and export (member eval '("no-export" "never-export"))))
(noeval (or eval-no eval-no-export))
@@ -240,10 +242,24 @@ should be asked whether to allow evaluation."
(nth 0 info) (nth 1 info))
org-confirm-babel-evaluate))))
(cond
+ (manual t)
(noeval nil)
(query 'query)
(t t))))
+(defun org--function-stack ()
+ "Return the current call stack function names."
+ ;; https://emacs.stackexchange.com/questions/7396/
+ (butlast (mapcar 'cl-second
+ (let ((frames)
+ (frame)
+ (index 5))
+ (while (setq frame (backtrace-frame index))
+ (push frame frames)
+ (incf index))
+ (remove-if-not 'car frames)))))
+
+
(defun org-babel-check-evaluate (info)
"Check if code block INFO should be evaluated.
Do not query the user, but do display an informative message if
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Add :eval only-manual to babel blocks
2019-10-14 7:10 [PATCH] Add :eval only-manual to babel blocks Ken Mankoff
@ 2019-10-16 6:05 ` Ken Mankoff
2019-10-16 10:38 ` Nicolas Goaziou
0 siblings, 1 reply; 7+ messages in thread
From: Ken Mankoff @ 2019-10-16 6:05 UTC (permalink / raw)
To: Org Mailing List
On 2019-10-14 at 09:10 +02, Ken Mankoff <mankoff@gmail.com> wrote...
> With this patch and ":eval only-manual" in a babel header,
>
> Org evaluates the source code if it is run via ~org-ctrl-c-ctrl-c~
> (e.g. =C-c C-c= in the babel block), but not if run via the
> ~org-babel-execute-buffer~ function.
Hmm. So it turns out (I think) this patch isn't necessary. The behavior I wanted and thought I implemented is actually the default behavior! I think the behavior is undefined for :eval not equal to "yes", "no", or "query", but the current undefined implementation does what I want.
-k.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add :eval only-manual to babel blocks
2019-10-16 6:05 ` Ken Mankoff
@ 2019-10-16 10:38 ` Nicolas Goaziou
2019-10-16 11:36 ` Ken Mankoff
2019-10-16 21:10 ` Ken Mankoff
0 siblings, 2 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2019-10-16 10:38 UTC (permalink / raw)
To: Ken Mankoff; +Cc: Org Mailing List
Hello,
Ken Mankoff <mankoff@gmail.com> writes:
> Hmm. So it turns out (I think) this patch isn't necessary. The
> behavior I wanted and thought I implemented is actually the default
> behavior! I think the behavior is undefined for :eval not equal to
> "yes", "no", or "query", but the current undefined implementation does
> what I want.
Note that what you want, i.e., to distinguish behaviour depending on the
location of the call stack is cheesy, at best. Think about macros,
user-defined functions, etc.
The Emacs' answer to this is usually to check if call to a function is
interactive, or not.
So, if you want to implement it properly, you may want to look into that
direction.
Of course, meawhile, do not rely on undefined behaviour :)
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add :eval only-manual to babel blocks
2019-10-16 10:38 ` Nicolas Goaziou
@ 2019-10-16 11:36 ` Ken Mankoff
2019-10-16 16:07 ` Nicolas Goaziou
2019-10-16 21:10 ` Ken Mankoff
1 sibling, 1 reply; 7+ messages in thread
From: Ken Mankoff @ 2019-10-16 11:36 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mailing List
Hi Nicolas,
On 2019-10-16 at 12:38 +02, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote...
> Note that what you want, i.e., to distinguish behaviour depending on
> the location of the call stack is cheesy, at best. Think about macros,
> user-defined functions, etc.
Yes, it felt a bit hackish. But I'm new to this level of Org coding.
> The Emacs' answer to this is usually to check if call to a function is
> interactive, or not.
Can you provide a more obvious hint? :) I've read the documentation on called-interactively-p but have not had success yet with that function. The bottom of that doc string suggests this is not an appropriate use for it.
I've read the manual part on "Distinguish Interactive Calls"[1] but working through those examples I can't get deeper called functions to know if the nth-parent was called interactively or not.
Would you solve this issue somewhere completely different? Like an advice around the org-ctrl-c-ctrl-c function or something?
Thanks,
-k.
[1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Distinguish-Interactive.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add :eval only-manual to babel blocks
2019-10-16 11:36 ` Ken Mankoff
@ 2019-10-16 16:07 ` Nicolas Goaziou
0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2019-10-16 16:07 UTC (permalink / raw)
To: Ken Mankoff; +Cc: Org Mailing List
Hello,
Ken Mankoff <mankoff@gmail.com> writes:
> Can you provide a more obvious hint? :)
I don't have enough time to help you more on that, sorry. I didn't even
look closely to the issue you're encountering. Hopefully, someone else
on the ML can provide guidance on it.
> I've read the documentation on called-interactively-p but have not had
> success yet with that function. The bottom of that doc string suggests
> this is not an appropriate use for it.
Indeed.
> I've read the manual part on "Distinguish Interactive Calls"[1] but
> working through those examples I can't get deeper called functions to
> know if the nth-parent was called interactively or not.
IMO, this is what you shouldn't try to do: mess with the call stack.
This sounds like a wrong approach to the problem.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add :eval only-manual to babel blocks
2019-10-16 10:38 ` Nicolas Goaziou
2019-10-16 11:36 ` Ken Mankoff
@ 2019-10-16 21:10 ` Ken Mankoff
2019-10-17 12:17 ` Nicolas Goaziou
1 sibling, 1 reply; 7+ messages in thread
From: Ken Mankoff @ 2019-10-16 21:10 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mailing List
On 2019-10-16 at 12:38 +02, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote...
> Of course, meawhile, do not rely on undefined behaviour :)
Would you accept a documentation patch that defines the current behavior?
Then I get what I want, and it is on future developers to not mess it up :).
-k.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add :eval only-manual to babel blocks
2019-10-16 21:10 ` Ken Mankoff
@ 2019-10-17 12:17 ` Nicolas Goaziou
0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2019-10-17 12:17 UTC (permalink / raw)
To: Ken Mankoff; +Cc: Org Mailing List
Hello,
Ken Mankoff <mankoff@gmail.com> writes:
> On 2019-10-16 at 12:38 +02, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote...
>
> Would you accept a documentation patch that defines the current
> behavior?
I don't know enough of the problem to answer. A default answer which in
neither "yes" or "no" is odd. Let's discuss it with other users of
Babel.
> Then I get what I want, and it is on future developers to not mess it
> up :).
This is the problem. Is it a reasonable expectation? I cannot tell.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-10-17 12:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-14 7:10 [PATCH] Add :eval only-manual to babel blocks Ken Mankoff
2019-10-16 6:05 ` Ken Mankoff
2019-10-16 10:38 ` Nicolas Goaziou
2019-10-16 11:36 ` Ken Mankoff
2019-10-16 16:07 ` Nicolas Goaziou
2019-10-16 21:10 ` Ken Mankoff
2019-10-17 12:17 ` Nicolas Goaziou
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).