emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Berry, Charles" <ccberry@ucsd.edu>
Cc: emacs-org-mode <emacs-orgmode@gnu.org>
Subject: Re: [BUG] Re: header argument :noweb-ref seems can't be resolved
Date: Tue, 19 Dec 2017 20:00:59 +0100	[thread overview]
Message-ID: <873746lez8.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <3763D550-0C04-4B8A-B329-582D16D3961A@ucsd.edu> (Charles Berry's message of "Tue, 19 Dec 2017 17:49:50 +0000")

[-- Attachment #1: Type: text/plain, Size: 1542 bytes --]

Hello,

"Berry, Charles" <ccberry@ucsd.edu> writes:

> I guess I was unclear. There are two ways to fix this.
>
> 1) let bind org-babel-current-src-block-location in
> org-babel-expand-noweb-references in the loop that scans for
> noweb-ref'ed src blocks. This fixes the bug, but contradicts the
> docstring for o-b-c-s-b-l, which says it is the location of the
> currently executing src block. Maybe not a big deal, since
> `org-babel-exp-src-block' can export blocks that are not actually
> executed which is another contradiction of the docstring. Maybe change
> the docstring.
>
> 2) rewrite org-babel-params-from-properties to add an optional arg
> `src-block-location' and use it when provided to govern where to look
> up properties. Modify `org-babel-get-src-block-info' accordingly to
> add that arg when calling o-b-p-f-p. This honors the use of
> o-b-c-s-b-l as the location of the executing src block, but inflates
> the code to accommodate just the `noweb-ref' case.
>
> I think `2' is better as it makes clearer where o-b-p-f-p is looking
> for properties when reading the code of org-babel-get-src-block-info.

Since :noweb-ref is the only property that absolutely needs to be
retrieved from definition, another option would be to write a specific
function for that.

It implies some duplicated efforts with `org-babel-get-src-block-info',
but it is faster when the source name doesn't match, which is the most
common case, and avoids all side-effects from
`org-babel-get-src-block-info'.

WDYT?

Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix noweb-ref --]
[-- Type: text/x-diff, Size: 2706 bytes --]

From ea24f751fd4ec91857d59e2c287754d3d6dc33f1 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Tue, 19 Dec 2017 19:55:51 +0100
Subject: [PATCH] ob-core: Correctly find  Noweb reference

* lisp/ob-core.el (org-babel--noweb-reference): New function.
(org-babel-expand-noweb-references): Use new function.
---
 lisp/ob-core.el | 41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index ade39ec67..bc3c255f5 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2662,6 +2662,36 @@ CONTEXT may be one of :tangle, :export or :eval."
     (cl-some (lambda (v) (member v allowed-values))
 	     (split-string (or (cdr (assq :noweb params)) "")))))
 
+(defun org-babel--noweb-reference (element)
+  "Return Noweb reference for ELEMENT.
+ELEMENT is a source block.  Return value from `:noweb-ref',
+possibly inherited from properties, or nil."
+  (let ((language (org-element-property :language element)))
+    (cdr
+     (or (assq :noweb-ref		;from block itself
+	       (org-babel-parse-header-arguments
+		(mapconcat #'identity
+			   (cons (org-element-property :parameters element)
+				 (org-element-property :header element))
+			   " ")))
+	 (assq :noweb-ref		;from properties
+	       (org-babel-parse-header-arguments
+		(org-trim
+		 (concat
+		  (and language
+		       (org-entry-get (point)
+				      (concat "header-args:" language)
+				      'inherit))
+		  " "
+		  (org-entry-get (point) "header-args" 'inherit)))))
+	 (and language
+	      (let ((lang-headers
+		     (intern (concat "org-babel-default-header-args:"
+				     language))))
+		(and (boundp lang-headers)
+		     (assq :noweb-ref (symbol-value lang-headers)))))
+	 (assq :noweb-ref org-babel-default-header-args)))))
+
 (defun org-babel-expand-noweb-references (&optional info parent-buffer)
   "Expand Noweb references in the body of the current source code block.
 
@@ -2777,11 +2807,14 @@ block but are passed literally to the \"example-block\"."
 			;; those with a matching Noweb reference.
 			(let ((expansion nil))
 			  (org-babel-map-src-blocks nil
-			    (let ((i (org-babel-get-src-block-info 'light)))
+			    (let ((element (org-element-at-point)))
 			      (when (equal source-name
-					   (cdr (assq :noweb-ref (nth 2 i))))
-				(let ((sep (or (cdr (assq :noweb-sep (nth 2 i)))
-					       "\n")))
+					   (org-babel--noweb-reference element))
+				(let* ((i (org-babel-get-src-block-info
+					   'light element))
+				       (sep
+					(or (cdr (assq :noweb-sep (nth 2 i)))
+					    "\n")))
 				  (setq expansion
 					(cons sep
 					      (cons (funcall expand-body i)
-- 
2.15.1


  reply	other threads:[~2017-12-19 19:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-17 14:58 header argument :noweb-ref seems can't be resolved stardiviner
2017-12-17 17:40 ` Berry, Charles
2017-12-18  2:08   ` stardiviner
2017-12-18  4:12     ` Berry, Charles
2017-12-18  4:28       ` stardiviner
2017-12-18 16:46         ` Berry, Charles
2017-12-18 17:28           ` numbchild
2017-12-19  4:59             ` Berry, Charles
2017-12-19  7:31               ` [BUG] " stardiviner
2017-12-19 17:49                 ` Berry, Charles
2017-12-19 19:00                   ` Nicolas Goaziou [this message]
2017-12-20  5:32                     ` Berry, Charles
2017-12-20 12:23                       ` Nicolas Goaziou
2017-12-20 15:41                         ` numbchild

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873746lez8.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).