emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* get name of source block
@ 2015-05-14 14:07 Andreas Leha
  2015-05-18  8:55 ` Sebastien Vauban
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Leha @ 2015-05-14 14:07 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

for quite some time I've had the following in my .emacs:

--8<---------------cut here---------------start------------->8---
;; This Snippet returns the name of the current source block.
;; An elisp block to simplify the =:prologue= definition.
;; Author: Eric Schulte
;; It is useful to insert the debug message 'Entering foo()' as output.
;; For R code blocks, enable it with this line:
;; #+PROPERTY: header-args:R :session *R* :prologue (format "print(\"entering %s\")" (get-current-name))
(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)))))
      ""))
--8<---------------cut here---------------end--------------->8---

That had stopped working during export (my main use-case) a few weeks
back.  Now, org-babel-src-name-w-name-regexp is gone from the source
so that this snippet is completely broken.

I would like to again have the name of the source block displayed
during execution of src blocks.  Is there a function in org already?
And if not, how would the proposed function look like so that it works
during export as well?

Thanks in advance!
Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get name of source block
  2015-05-14 14:07 get name of source block Andreas Leha
@ 2015-05-18  8:55 ` Sebastien Vauban
  2015-05-18 11:07   ` Andreas Leha
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastien Vauban @ 2015-05-18  8:55 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Andreas Leha wrote:
> for quite some time I've had the following in my .emacs:
>
> ;; This Snippet returns the name of the current source block.
> ;; An elisp block to simplify the =:prologue= definition.
> ;; Author: Eric Schulte
> ;; It is useful to insert the debug message 'Entering foo()' as output.
> ;; For R code blocks, enable it with this line:
> ;; #+PROPERTY: header-args:R :session *R* :prologue (format "print(\"entering %s\")" (get-current-name))
> (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)))))
>       ""))
>
> That had stopped working during export (my main use-case) a few weeks
> back.  Now, org-babel-src-name-w-name-regexp is gone from the source
> so that this snippet is completely broken.
>
> I would like to again have the name of the source block displayed
> during execution of src blocks.  Is there a function in org already?
> And if not, how would the proposed function look like so that it works
> during export as well?

Seems to come from:

* 49a656a ob-core: Remove `org-babel-src-name-w-name-regexp' <Nicolas Goaziou> (2015-05-01)
* cec47a6 ob-core: Change `org-babel-named-src-block-regexp-for-name' signature <Nicolas Goaziou> (2015-05-01)

Maybe looking at the diff would give you the way to translate the regexp
into some newer form?

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get name of source block
  2015-05-18  8:55 ` Sebastien Vauban
@ 2015-05-18 11:07   ` Andreas Leha
  2015-05-18 11:42     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Leha @ 2015-05-18 11:07 UTC (permalink / raw)
  To: emacs-orgmode

Hi Sebastien,

Sebastien Vauban <sva-news@mygooglest.com> writes:
> Andreas Leha wrote:
>> for quite some time I've had the following in my .emacs:
>>
>> ;; This Snippet returns the name of the current source block.
>> ;; An elisp block to simplify the =:prologue= definition.
>> ;; Author: Eric Schulte
>> ;; It is useful to insert the debug message 'Entering foo()' as output.
>> ;; For R code blocks, enable it with this line:
>> ;; #+PROPERTY: header-args:R :session *R* :prologue (format "print(\"entering %s\")" (get-current-name))
>> (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)))))
>>       ""))
>>
>> That had stopped working during export (my main use-case) a few weeks
>> back.  Now, org-babel-src-name-w-name-regexp is gone from the source
>> so that this snippet is completely broken.
>>
>> I would like to again have the name of the source block displayed
>> during execution of src blocks.  Is there a function in org already?
>> And if not, how would the proposed function look like so that it works
>> during export as well?
>
> Seems to come from:
>
> * 49a656a ob-core: Remove `org-babel-src-name-w-name-regexp' <Nicolas Goaziou> (2015-05-01)
> * cec47a6 ob-core: Change `org-babel-named-src-block-regexp-for-name' signature <Nicolas Goaziou> (2015-05-01)
>
> Maybe looking at the diff would give you the way to translate the regexp
> into some newer form?
>
> Best regards,
>   Seb



Yes, I was lazy and following the change to
`org-babel-named-src-block-regexp-for-name' is easy enough.
But how does that solve my first problem?

During export (and preview (C-c C-v v)) the code block name is not
displayed.

Here is an expample:

--8<---------------cut here---------------start------------->8---
#+PROPERTY: header-args:R :session *testR* :prologue (format "print(\"entering %s\")" (get-current-name))

* Setup								   :noexport:
#+begin_src emacs-lisp :results none
  (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-named-src-block-regexp-for-name))
              (org-match-string-no-properties 9))))
        ""))
  (message (get-current-name))
#+end_src


* Test echo name during export

Execute this source block (C-c C-c) and look into *testR*.  There
should be a message "entering testname".

Export this file and look into *testR*.  The message is "entering ".

#+name: testname
#+begin_src R
  1:10
#+end_src
--8<---------------cut here---------------end--------------->8---


Thanks,
Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get name of source block
  2015-05-18 11:07   ` Andreas Leha
@ 2015-05-18 11:42     ` Nicolas Goaziou
  2015-05-18 14:46       ` Andreas Leha
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2015-05-18 11:42 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Hello,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> During export (and preview (C-c C-v v)) the code block name is not
> displayed.

See `org-babel-exp-code-template'.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get name of source block
  2015-05-18 11:42     ` Nicolas Goaziou
@ 2015-05-18 14:46       ` Andreas Leha
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Leha @ 2015-05-18 14:46 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nicolas,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> During export (and preview (C-c C-v v)) the code block name is not
>> displayed.
>
> See `org-babel-exp-code-template'.
>

Thanks for looking into this.

If I get you correctly, you are suggesting a way to have the name
of the code block shown in the exported file.  What I am after is
to have the name of the code block shown *in the R session*
during evaluation at export (to easily see where things fail).
Sorry for being unclear.

If your hint helps there as well, could you elaborate a bit?

Thanks,
Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-18 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14 14:07 get name of source block Andreas Leha
2015-05-18  8:55 ` Sebastien Vauban
2015-05-18 11:07   ` Andreas Leha
2015-05-18 11:42     ` Nicolas Goaziou
2015-05-18 14:46       ` Andreas Leha

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).