From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Leha Subject: Re: get name of source block Date: Mon, 18 May 2015 12:07:55 +0100 Message-ID: References: <86pp5yz2lq.fsf@example.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuItj-0000zn-2o for emacs-orgmode@gnu.org; Mon, 18 May 2015 07:07:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuIte-0000ZY-16 for emacs-orgmode@gnu.org; Mon, 18 May 2015 07:07:51 -0400 Received: from plane.gmane.org ([80.91.229.3]:44697) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuItd-0000Yp-Q4 for emacs-orgmode@gnu.org; Mon, 18 May 2015 07:07:45 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YuItb-0000vK-BV for emacs-orgmode@gnu.org; Mon, 18 May 2015 13:07:43 +0200 Received: from cpc33-cmbg15-2-0-cust4.5-4.cable.virginm.net ([81.102.136.5]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 18 May 2015 13:07:43 +0200 Received: from andreas.leha by cpc33-cmbg15-2-0-cust4.5-4.cable.virginm.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 18 May 2015 13:07:43 +0200 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: emacs-orgmode@gnu.org Hi Sebastien, Sebastien Vauban 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' (2015-05-01) > * cec47a6 ob-core: Change `org-babel-named-src-block-regexp-for-name' signature (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