From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [BUG] Re: header argument :noweb-ref seems can't be resolved Date: Tue, 19 Dec 2017 20:00:59 +0100 Message-ID: <873746lez8.fsf@nicolasgoaziou.fr> References: <65580a97-24c4-a54c-655f-c37fcddd2cd1@gmail.com> <580C6094-17BE-44C7-8F4C-8BAF3113AA40@ucsd.edu> <8C1BE6FC-D004-49A9-82F5-03181061E848@ucsd.edu> <65375b87-03d9-45bb-6529-f5473c4d6af7@gmail.com> <16cda4c5-1612-145d-9cd4-aa3facbf1363@gmail.com> <3763D550-0C04-4B8A-B329-582D16D3961A@ucsd.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRN8T-00006v-8L for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 14:01:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRN8S-0006LR-3c for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 14:01:05 -0500 Received: from relay2-d.mail.gandi.net ([2001:4b98:c:538::194]:52095) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRN8R-0006IU-Qo for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 14:01:04 -0500 In-Reply-To: <3763D550-0C04-4B8A-B329-582D16D3961A@ucsd.edu> (Charles Berry's message of "Tue, 19 Dec 2017 17:49:50 +0000") 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: "Berry, Charles" Cc: emacs-org-mode --=-=-= Content-Type: text/plain Hello, "Berry, Charles" 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ob-core-Correctly-find-Noweb-reference.patch Content-Description: fix noweb-ref >From ea24f751fd4ec91857d59e2c287754d3d6dc33f1 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 --=-=-=--