From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiegec Subject: 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/)] Date: Sat, 9 Jul 2016 07:43:33 +0800 Message-ID: <410FE869-C71E-4748-B7D2-5ECB5799C804@qq.com> References: Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLfQx-00084h-Tn for emacs-orgmode@gnu.org; Fri, 08 Jul 2016 19:43:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bLfQu-000220-Mk for emacs-orgmode@gnu.org; Fri, 08 Jul 2016 19:43:47 -0400 Received: from smtpbgau2.qq.com ([54.206.34.216]:40135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLfQt-00020Q-Nx for emacs-orgmode@gnu.org; Fri, 08 Jul 2016 19:43:44 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: "Charles C. Berry" Cc: emacs-orgmode@gnu.org 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)))=20= (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=E2=80=99d love to implement this = feature in another way. > On Jul 9, 2016, at 12:09 AM, Charles C. Berry = wrote: >=20 > On Fri, 8 Jul 2016, Jiajie Chen wrote: > [snip] >=20 >> 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 :) >>=20 >=20 > Not a bug, of course. >=20 > You can check on things like file existence in a number of ways. >=20 > First, you can put emacs-lisp in header args, for example: >=20 > This evaluates when there is a file called "elisp" in the default = directory: >=20 > #+header: :eval (or (file-exists-p "elisp") "no") > #+BEGIN_SRC emacs-lisp :eval (file-exists-p "elisp") > "got it!" > #+END_SRC >=20 >=20 > and this does not (when there is no 'eeeelisp'): >=20 > #+header: :eval (or (file-exists-p "eeeelisp") "no") > #+BEGIN_SRC emacs-lisp > "got it!" > #+END_SRC >=20 > I've illustrated here with `:eval', but `:file' will also take such an = elisp snippet. >=20 >=20 > Alternatively, you can define a function for = `org-confirm-babel-evaluate' that will block evaluation. >=20 > Chuck