* Bug: Feature Request: add 'org-babel-before-execute-hook' [8.3.4 (8.3.4-99-ga8e4a3-elpa @ /Users/macbookair/.emacs.d/elpa/org-20160704/)]
@ 2016-07-08 10:56 Jiajie Chen
2016-07-08 16:09 ` Charles C. Berry
0 siblings, 1 reply; 3+ messages in thread
From: Jiajie Chen @ 2016-07-08 10:56 UTC (permalink / raw)
To: emacs-orgmode
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen. You don't know how to make a good report? See
http://orgmode.org/manual/Feedback.html#Feedback
Your bug report will be posted to the Org-mode mailing list.
------------------------------------------------------------------------
Now there exists 'org-babel-after-execute-hook'. I want to implement
this functionality: Check whether the path specified in `:file' exists
in file system and throw an error if that does not exists. If there is
`org-babel-before-execute-hook', we can do that instead of using
advice. I love symmetry :)
Emacs : GNU Emacs 25.1.50.1 (x86_64-apple-darwin15.5.0, NS appkit-1404.47 Version 10.11.5 (Build 15F34))
of 2016-07-03
Package: Org-mode version 8.3.4 (8.3.4-99-ga8e4a3-elpa @ /Users/macbookair/.emacs.d/elpa/org-20160704/)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug: Feature Request: add 'org-babel-before-execute-hook' [8.3.4 (8.3.4-99-ga8e4a3-elpa @ /Users/macbookair/.emacs.d/elpa/org-20160704/)]
2016-07-08 10:56 Bug: Feature Request: add 'org-babel-before-execute-hook' [8.3.4 (8.3.4-99-ga8e4a3-elpa @ /Users/macbookair/.emacs.d/elpa/org-20160704/)] Jiajie Chen
@ 2016-07-08 16:09 ` Charles C. Berry
2016-07-08 23:43 ` Jiegec
0 siblings, 1 reply; 3+ messages in thread
From: Charles C. Berry @ 2016-07-08 16:09 UTC (permalink / raw)
To: Jiajie Chen; +Cc: emacs-orgmode
On Fri, 8 Jul 2016, Jiajie Chen wrote:
[snip]
> Now there exists 'org-babel-after-execute-hook'. I want to implement
> this functionality: Check whether the path specified in `:file' exists
> in file system and throw an error if that does not exists. If there is
> `org-babel-before-execute-hook', we can do that instead of using
> advice. I love symmetry :)
>
Not a bug, of course.
You can check on things like file existence in a number of ways.
First, you can put emacs-lisp in header args, for example:
This evaluates when there is a file called "elisp" in the default
directory:
#+header: :eval (or (file-exists-p "elisp") "no")
#+BEGIN_SRC emacs-lisp :eval (file-exists-p "elisp")
"got it!"
#+END_SRC
and this does not (when there is no 'eeeelisp'):
#+header: :eval (or (file-exists-p "eeeelisp") "no")
#+BEGIN_SRC emacs-lisp
"got it!"
#+END_SRC
I've illustrated here with `:eval', but `:file' will also take such an
elisp snippet.
Alternatively, you can define a function for `org-confirm-babel-evaluate'
that will block evaluation.
Chuck
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug: Feature Request: add 'org-babel-before-execute-hook' [8.3.4 (8.3.4-99-ga8e4a3-elpa @ /Users/macbookair/.emacs.d/elpa/org-20160704/)]
2016-07-08 16:09 ` Charles C. Berry
@ 2016-07-08 23:43 ` Jiegec
0 siblings, 0 replies; 3+ messages in thread
From: Jiegec @ 2016-07-08 23:43 UTC (permalink / raw)
To: Charles C. Berry; +Cc: emacs-orgmode
Yes this is not a bug and I have implemented this using advice:
#+BEGIN_SRC emacs-lisp
;; See https://emacs-china.org/t/file/696
;; And http://lists.gnu.org/archive/html/emacs-orgmode/2016-07/msg00136.html
(defun check-file-exists-advice (orig-fun
&optional arg
info
params)
;; Copied from ob-core.el. May not be compatible.
(let* ((org-babel-current-src-block-location
(or org-babel-current-src-block-location
(nth 6 info)
(org-babel-where-is-src-block-head)
;; inline src block
(and (org-babel-get-inline-src-block-matches)
(match-beginning 0))))
(info (if info
(copy-tree info)
(org-babel-get-src-block-info)))
(merged-params (org-babel-merge-params (nth 2 info) params)))
(when (cdr (assoc :file merged-params))
(unless (file-exists-p (cdr (assoc :file merged-params)))
(error "File does not exist"))))
(funcall orig-fun arg info params))
(advice-add 'org-babel-execute-src-block :around #'check-file-exists-advice)
#+END_SRC
And this is just a feature request: I’d love to implement this feature
in another way.
> On Jul 9, 2016, at 12:09 AM, Charles C. Berry <ccberry@ucsd.edu> wrote:
>
> On Fri, 8 Jul 2016, Jiajie Chen wrote:
> [snip]
>
>> Now there exists 'org-babel-after-execute-hook'. I want to implement
>> this functionality: Check whether the path specified in `:file' exists
>> in file system and throw an error if that does not exists. If there is
>> `org-babel-before-execute-hook', we can do that instead of using
>> advice. I love symmetry :)
>>
>
> Not a bug, of course.
>
> You can check on things like file existence in a number of ways.
>
> First, you can put emacs-lisp in header args, for example:
>
> This evaluates when there is a file called "elisp" in the default directory:
>
> #+header: :eval (or (file-exists-p "elisp") "no")
> #+BEGIN_SRC emacs-lisp :eval (file-exists-p "elisp")
> "got it!"
> #+END_SRC
>
>
> and this does not (when there is no 'eeeelisp'):
>
> #+header: :eval (or (file-exists-p "eeeelisp") "no")
> #+BEGIN_SRC emacs-lisp
> "got it!"
> #+END_SRC
>
> I've illustrated here with `:eval', but `:file' will also take such an elisp snippet.
>
>
> Alternatively, you can define a function for `org-confirm-babel-evaluate' that will block evaluation.
>
> Chuck
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-07-08 23:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-08 10:56 Bug: Feature Request: add 'org-babel-before-execute-hook' [8.3.4 (8.3.4-99-ga8e4a3-elpa @ /Users/macbookair/.emacs.d/elpa/org-20160704/)] Jiajie Chen
2016-07-08 16:09 ` Charles C. Berry
2016-07-08 23:43 ` Jiegec
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.