[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Bug: Feature Request: add 'org-babel-before-execute-hook' [8.3.4
Re: [O] 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/)]
Sat, 9 Jul 2016 07:43:33 +0800
Yes this is not a bug and I have implemented this using advice:
;; 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
;; Copied from ob-core.el. May not be compatible.
(nth 6 info)
;; inline src block
(info (if 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)
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 <address@hidden> wrote:
> On Fri, 8 Jul 2016, Jiajie Chen wrote:
>> 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!"
> and this does not (when there is no 'eeeelisp'):
> #+header: :eval (or (file-exists-p "eeeelisp") "no")
> #+BEGIN_SRC emacs-lisp
> "got it!"
> I've illustrated here with `:eval', but `:file' will also take such an elisp
> Alternatively, you can define a function for `org-confirm-babel-evaluate'
> that will block evaluation.