From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] feature request: debug messages Date: Tue, 23 Jul 2013 16:12:02 -0600 Message-ID: <874nbjpour.fsf@gmail.com> References: <87y59n2z6b.fsf@med.uni-goettingen.de> <878v1njlsh.fsf@gmail.com> <87txka3jy8.fsf@med.uni-goettingen.de> <87zju2idny.fsf@gmail.com> <87li51b722.fsf@med.uni-goettingen.de> <87hafpb6fr.fsf@med.uni-goettingen.de> <87d2qdb60n.fsf@med.uni-goettingen.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V27i7-0008CE-Qz for emacs-orgmode@gnu.org; Wed, 24 Jul 2013 18:39:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V27i6-0006Qf-30 for emacs-orgmode@gnu.org; Wed, 24 Jul 2013 18:39:07 -0400 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]:60989) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V27i5-0006Qb-OY for emacs-orgmode@gnu.org; Wed, 24 Jul 2013 18:39:06 -0400 Received: by mail-pa0-f45.google.com with SMTP id bg4so1204122pad.18 for ; Wed, 24 Jul 2013 15:39:04 -0700 (PDT) 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andreas Leha Cc: emacs-orgmode@gnu.org Andreas Leha writes: > Andreas Leha writes: > >> Andreas Leha writes: >> >>> Hi Eric, >>> >>> >>> Eric Schulte writes: >>> >>>> Andreas Leha writes: >>>> >>>>> Hi Eric, >>>>> >>>>> >>>>> Eric Schulte writes: >>>>> >>>>>> Hi Andreas, >>>>>> >>>>>> This should be easy to turn on or off using the newly introduced >>>>>> :prologue and :epilogue header arguments. See the manual and the >>>>>> following example. >>>>>> >>>>>> #+Title: debug messages >>>>>> #+Property: session *R* >>>>>> #+Property: prologue (format "print(\"entering %s\")" (get-current-n= ame)) >>>>>> >>>>>> An elisp block to simplify the =3D:prologue=3D definition. >>>>>> #+begin_src emacs-lisp >>>>>> (defun get-current-name () >>>>>> (save-excursion >>>>>> (goto-char org-babel-current-src-block-location) >>>>>> (while (and (forward-line -1) >>>>>> (looking-at org-babel-multi-line-header-regexp))) >>>>>> (when (looking-at org-babel-src-name-w-name-regexp) >>>>>> (org-no-properties (match-string 3))))) >>>>>> #+end_src >>>>>> >>>>>> Two blocks with simple assignments. >>>>>> >>>>>> #+name: block-1 >>>>>> #+begin_src R >>>>>> x <- 2 + 2 >>>>>> #+end_src >>>>>> >>>>>> #+name: block-2 >>>>>> #+begin_src R >>>>>> y <- x + x >>>>>> #+end_src >>>>>> >>>>>> Execute the whole buffer =3DC-c C-v b=3D to see the prologue in acti= on. >>>>>> >>>>>> Andreas Leha writes: >>>>>> >>>>>>> Hi all, >>>>>>> >>>>>>> I would love to see messages like 'entering block foo...' and >>>>>>> '...leaving block foo' printed to my R console. This would be very >>>>>>> handy when I evaluate a subtree (C-c C-v s) with a lot of #+call li= nes >>>>>>> and some lengthy ones. >>>>>>> >>>>>>> I know that >>>>>>> (1) I could implement that myself at in the source blocks. But I w= ould >>>>>>> love if orgmode did that for me >>>>>>> (2) Such messages are already printed to the emacs *Messages* buffe= r. >>>>>>> But that buffer might not be visible and I can not switch to it, >>>>>>> without interrupting the evaluation. Anyway it would be much n= icer >>>>>>> to see that output together with the other output, that my code >>>>>>> generates. >>>>>>> >>>>>>> >>>>>>> In essence it would be very helpful, if there was a variable >>>>>>> org-babel-print-debug-messages (or org-babel-debug-level...) which = if >>>>>>> non-nil would cause that messages to be printed. Or is there somew= here >>>>>>> already? >>>>>>> >>>>>>> Regards, >>>>>>> Andreas >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>> >>>>> >>>>> thanks for the quick answer! The :prologue and :epilogue header >>>>> arguments have indeed slipped my attention and they look really >>>>> interesting! I see, that they are documented, but somehow, they seem= to >>>>> not get their headline and TOC entry? >>>>> >>>>> I have three problems with your example, though: >>>>> 1) It does not run >>>>> 2) It does not work >>>>> 3) It won't be usable for 'my' epilogue, correct? >>>>> ;-) >>>>> >>>> >>>> Ah! My fault. I had to add prologue and epilogue support to ob-R.el >>>> when working through the example I sent, but then I forgot to commit >>>> that support to Org-mode. I've just pushed up that commit, and >>>> re-worked my example file to avoid the issue of prologue being applied >>>> to the emacs-lisp code block (using the very nice and also new >>>> language-specific PROPERTY header arguments). >>>> >>>> Finally, I don't use epilogues in the example because (as the last thi= ng >>>> evaluated) they would override the code block results. >>>> >>>> Hopefully the following: >>>> 1. will run >>>> 2. will work >>>> 3. will be usable >>>> >>>> Cheers, >>>> >>>> #+Title: debug messages >>>> #+Property: header-args:R :session *R* :prologue (format "print(\"ente= ring %s\")" (get-current-name)) >>>> >>>> An elisp block to simplify the =3D:prologue=3D definition. >>>> #+begin_src emacs-lisp :results silent >>>> (defun get-current-name () >>>> (save-excursion >>>> (goto-char org-babel-current-src-block-location) >>>> (while (and (forward-line -1) >>>> (looking-at org-babel-multi-line-header-regexp))) >>>> (when (looking-at org-babel-src-name-w-name-regexp) >>>> (org-no-properties (match-string 3))))) >>>> #+end_src >>>> >>>> Two blocks with simple assignments. >>>> >>>> #+name: block-1 >>>> #+begin_src R >>>> x <- 2 + 2 >>>> #+end_src >>>> >>>> #+RESULTS: block-1 >>>> : 4 >>>> #+name: block-2 >>>> #+begin_src R >>>> y <- x + x >>>> #+end_src >>>> >>>> #+RESULTS: block-2 >>>> : 8 >>>> >>>> Execute the whole buffer =3DC-c C-v b=3D to see the prologue in action. >>>> >>>>> >>>>> 1) >>>>> It does not run, because org tries to do the prologue also on the >>>>> emacs-lisp block defining the function of the prologue. So, I get >>>>> "format: Symbol's function definition is void: get-current-name" >>>>> I changed the #+property line to >>>>> #+Property: header-args:R :prologue (format "print(\"entering %s\")" = (get-current-name)) >>>>> which solved that problem. >>>>> >>>>> 2) >>>>> But still it does not work: This is what I get in my *R* buffer: >>>>> --8<---------------cut here---------------start------------->8--- >>>>> >>>>> R version 3.0.1 (2013-05-16) -- "Good Sport" >>>>> Copyright (C) 2013 The R Foundation for Statistical Computing >>>>> Platform: x86_64-pc-linux-gnu (64-bit) >>>>> >>>>> R ist freie Software und kommt OHNE JEGLICHE GARANTIE. >>>>> Sie sind eingeladen, es unter bestimmten Bedingungen weiter zu verbre= iten. >>>>> Tippen Sie 'license()' or 'licence()' f=C3=BCr Details dazu. >>>>> >>>>> R ist ein Gemeinschaftsprojekt mit vielen Beitragenden. >>>>> Tippen Sie 'contributors()' f=C3=BCr mehr Information und 'citation()= ', >>>>> um zu erfahren, wie R oder R packages in Publikationen zitiert werden= k=C3=B6nnen. >>>>> >>>>> Tippen Sie 'demo()' f=C3=BCr einige Demos, 'help()' f=C3=BCr on-line = Hilfe, oder >>>>> 'help.start()' f=C3=BCr eine HTML Browserschnittstelle zur Hilfe. >>>>> Tippen Sie 'q()', um R zu verlassen. >>>>> >>>>> [1] "C" >>>>> filehash: Simple key-value database (2.2-1 2012-03-12) >>>>> tikzDevice: R Graphics Output in LaTeX Format (v0.6.2-92-0ad2792) >>>>> LaTeX found in the PATH using the command: pdflatex >>>>> XeLaTeX found in the PATH using the command: xelatex >>>>> LuaLaTeX found in the PATH using the command: lualatex >>>>>> options(STERM=3D'iESS', str.dendrogram.last=3D"'", editor=3D'emacscl= ient', show.error.locations=3DTRUE) >>>>>> >>>>>> >=20 >>>>>> >=20 >>>>> --8<---------------cut here---------------end--------------->8--- >>>>> >>>>> I tried it with >>>>> - Org-mode version 8.0.4 (release_8.0.4-294-g62f20c) >>>>> - ess-version : 13.05-1 [] >>>>> - emacs -Q -l ~/.emacs.minimal.ess.org, whith that content: >>>>> --8<---------------cut here---------------start------------->8--- >>>>> (add-to-list 'load-path >>>>> "~/local/emacs/org-mode-install/lisp") >>>>> (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) >>>>> >>>>> (add-to-list 'load-path "~/local/emacs/ess/lisp") >>>>> (require 'ess-site) >>>>> >>>>> (setq org-babel-load-languages '((emacs-lisp . t) >>>>> (R . t) >>>>> (sh . t))) >>>>> --8<---------------cut here---------------end--------------->8--- >>>>> >>>>> What am I missing? (BTW: If I put a print("sth") into the R blocks >>>>> myself, I see that printed) >>>>> >>>>> >>>>> 3) >>>>> Even if it did run, I guess putting sth similar for 'leaving code blo= ck >>>>> foo' into the epilogue would spoil the return value of my src blocks, >>>>> correct? >>>>> Is there some work-around? >>>>> >>>>> >>>>> >>>>> Regards, >>>>> Andreas >>>>> >>>>> >>>>> >>> >>> >>> Could that awesome setup be extended to work on #+call lines as well? >>> That would be really helpful. >>> >>> The get-current-name does not work for #+call lines: >>> >>> #+Title: debug messages >>> #+Property: header-args:R :session *R* :prologue (format "print(\"enter= ing %s\")" (get-current-name)) >>> >>> An elisp block to simplify the =3D:prologue=3D definition. >>> #+begin_src emacs-lisp :results silent >>> (defun get-current-name () >>> (save-excursion >>> (goto-char org-babel-current-src-block-location) >>> (while (and (forward-line -1) >>> (looking-at org-babel-multi-line-header-regexp))) >>> (when (looking-at org-babel-src-name-w-name-regexp) >>> (org-no-properties (match-string 3))))) >>> #+end_src >>> >>> Two blocks with simple assignments. >>> >>> #+name: block-1 >>> #+begin_src R >>> x <- 2 + 2 >>> #+end_src >>> >>> #+results: block-1 >>> : 4 >>> >>> >>> >>> #+name: block-2 >>> #+begin_src R >>> y <- x + x >>> #+end_src >>> >>> #+results: block-2 >>> : 8 >>> >>> #+call: block-1() >>> >>> #+results: >>> : 4 >>> >>> >>> Execute the whole buffer =3DC-c C-v b=3D to see the prologue in action. >>> >>> Regards, >>> Andreas >> >> >> Just as an add-on. It does work with *named* #+call lines. >> >> Regards, >> Andreas > > > Sorry for continuously answering my own post. > > There is another problem with that solution: I can not edit a source > code buffer with C-' > ,---- > | save-excursion: Wrong type argument: integer-or-marker-p, nil > `---- > > Regards, > Andreas > > This version should - not throw an error when no code block is being executed, and - always return a string (even if there is no name) #+begin_src emacs-lisp :results silent (defun get-current-name () (or (when org-babel-current-src-block-location (save-excursion (goto-char org-babel-current-src-block-location) (while (and (forward-line -1) (looking-at org-babel-multi-line-header-regexp))) (when (looking-at org-babel-src-name-w-name-regexp) (org-no-properties (match-string 3))))) "")) #+end_src Hopefully this helps, --=20 Eric Schulte http://cs.unm.edu/~eschulte