From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iLNaMkZvfF+qKwAA0tVLHw (envelope-from ) for ; Tue, 06 Oct 2020 13:21:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id iPkTLkZvfF8SCAAAB5/wlQ (envelope-from ) for ; Tue, 06 Oct 2020 13:21:10 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 39E1694042A for ; Tue, 6 Oct 2020 13:21:10 +0000 (UTC) Received: from localhost ([::1]:57632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPmtw-0001ly-Uu for larch@yhetil.org; Tue, 06 Oct 2020 09:21:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPmqk-0007jP-05 for emacs-orgmode@gnu.org; Tue, 06 Oct 2020 09:17:53 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:45321) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kPmqh-0004gu-LQ for emacs-orgmode@gnu.org; Tue, 06 Oct 2020 09:17:49 -0400 Received: by mail-pf1-x42d.google.com with SMTP id x22so8987309pfo.12 for ; Tue, 06 Oct 2020 06:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=wGBXZsK4WhshWaeGIdPDkxAri6z50fNp4rxDQPYmAJ0=; b=II5qgbpQtH70lKc5su/GJ5qPHETuu097q1O2c8TlzNME2LnrZ/iWbrebqs53EzaaLR omokib2xyh+8j5mFZHebvty0wXcYtsUdffNZUA/eSuZDtoDeqITadPLPRg+UtgPGWCkf 3YP8rfCF2LA7czZ8lIAUP6L85htFzEUExax3Cb8FP53cACr5eow9iCazY++BWbT4rnXA e8zLWkF/Cp1EKZqe5uBjGeTGTnMy/0svEzCCf1hIcV1npRi1HFDwEy9Lp2GUU+rm35qu 36qreUOTMgbP5DYSi8/+l4auxSDu3/i9WXKJItf+ty0LxWSiQ3NFdY8LDfN8Z/h7lbOT 8p4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:cc:subject:in-reply-to:references :date:message-id:mime-version; bh=wGBXZsK4WhshWaeGIdPDkxAri6z50fNp4rxDQPYmAJ0=; b=ZW45ErswIwHXqnmM8wVB5hl8TJ55+pFCEnn7+XpVNAeyDl6JN+Ya5hoNNq3FF3INID 42yAuaGzOohKZ4y0LD8KByo1nT8n+8mLPRjXQJz9M2dNJoYuZEPD7CmTZQhjn7kZM5jn ggkNzwDLfjIsebuenactwk93TaHTKVWQJRbGHLqAFgu6r+dY7ICpqYRbrnM/UXPk07v4 kSI/Hnbeb6IztprqFT0j/QUv7hB0IiPuMFohrg3MgbQrcNHrbvI7ifyMmsKNt1zPZj5M cPVBP6z6Z70e3k2EnvzhLvKKa682wyvh9/ah1oPh424Ttb8mVPgg/NTwZMDE0C17mysp 7wjA== X-Gm-Message-State: AOAM5326di3QMudAMXC6ri5PlotnNDpYir5jqq6FYRZGzc4yPNrqJwA+ wP2gT0bRbZZ/I+yXysm85lRwgP56bahCng== X-Google-Smtp-Source: ABdhPJwO50EJIpJKn309H1bsLnFZK0n1OGtlQsHLeJw5ewPUWwKiSnBGgPznWPtgCpBMRoTT2hHm/A== X-Received: by 2002:a63:c551:: with SMTP id g17mr3956589pgd.399.1601990263667; Tue, 06 Oct 2020 06:17:43 -0700 (PDT) Received: from ryzen3950 (c-73-71-89-135.hsd1.ca.comcast.net. [73.71.89.135]) by smtp.gmail.com with ESMTPSA id q8sm4027631pff.18.2020.10.06.06.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2020 06:17:42 -0700 (PDT) From: Matt Huszagh To: Kyle Meyer Subject: Re: [PATCH] Omit file description when :file-desc has nil value In-Reply-To: <87a6x3kfjq.fsf@kyleam.com> References: <87r1rf35bb.fsf@kyleam.com> <87pn6uzq41.fsf@gmail.com> <877dsv3r1w.fsf@gmail.com> <87a6xfvjck.fsf@kyleam.com> <87eemrzokq.fsf@gmail.com> <874knmvkmx.fsf@kyleam.com> <878scs2rpg.fsf@gmail.com> <87a6x3kfjq.fsf@kyleam.com> Date: Tue, 06 Oct 2020 06:17:37 -0700 Message-ID: <87sgartrwu.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=huszaghmatt@gmail.com; helo=mail-pf1-x42d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: , Emacs-Orgmode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=II5qgbpQ; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: ODdVlv4k5SHe --=-=-= Content-Type: text/plain Kyle Meyer writes: > So, with the typo/spurious space change clean-ups, this looks good to > me. IIRC from a previous thread, you haven't yet completed the > copyright paperwork. Is that the case? I've made those fixes and attached the updated patch. I also sent you the paperwork separately (didn't post to the thread since the PDF is too large). Thanks Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ob-core.el-Allow-passing-empty-vector-to-file-d.patch >From 7452f3e8315be63fa8ae160f6be00963bac898a7 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Tue, 29 Sep 2020 14:11:59 -0700 Subject: [PATCH] lisp/ob-core.el: Allow passing empty vector to :file-desc to omit description * doc/org-manual.org (Type): Document empty vector argument for file-desc. * etc/ORG-NEWS (New argument for ~file-desc~ babel header): Add entry to NEWS. * lisp/ob-core.el (org-babel--file-desc): Add new function to evaluate file description value. (org-babel-execute-src-block): Correctly evaluate file description when executing src block. (org-babel-insert-result): Correctly evaluate file description value when inserting the result of src block execution into the buffer. * testing/lisp/test-ob.el (test-ob/file-desc-header-argument): Add test case for new behavior. --- doc/org-manual.org | 8 +++++--- etc/ORG-NEWS | 11 +++++++++++ lisp/ob-core.el | 16 +++++++++++----- testing/lisp/test-ob.el | 20 +++++++++++++++++++- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index e7d25b90e..ef2dad9ef 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17482,10 +17482,12 @@ default behavior is to automatically determine the result type. #+end_example #+cindex: @samp{file-desc}, header argument - The =file-desc= header argument defines the description (see - [[*Link Format]]) for the link. If =file-desc= is present but has no value, + The =file-desc= header argument defines the description (see [[*Link + Format]]) for the link. If =file-desc= is present but has no value, the =file= value is used as the link description. When this - argument is not present, the description is omitted. + argument is not present, the description is omitted. If you want to + provide the =file-desc= argument but omit the description, you can + provide it with an empty vector (i.e., :file-desc []). #+cindex: @samp{sep}, header argument By default, Org assumes that a table written to a file has diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 5dc68cba4..7f935bf52 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -24,6 +24,17 @@ Earlier, IDs generated using =ts= method had a hard-coded format (i.e. =20200923 The new option allows user to customise the format. Defaults are unchanged. +*** New argument for ~file-desc~ babel header + +It is now possible to provide the =file-desc= header argument for a +babel source block but omit the description by passing an empty vector +as an argument (i.e., :file-desc []). This can be useful because +providing =file-desc= without an argument results in the result of +=file= being used in the description. Previously, the only way to +omit a file description was to omit the header argument entirely, +which made it difficult/impossible to provide a default value for +=file-desc=. + ** New features *** =ob-python= improvements to =:return= header argument diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 7300f239e..075e3f928 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -646,6 +646,14 @@ a list with the following pattern: (replace-regexp-in-string (org-src-coderef-regexp coderef) "" expand nil nil 1)))) +(defun org-babel--file-desc (params result) + "Retrieve file description." + (pcase (assq :file-desc params) + (`nil nil) + (`(:file-desc) result) + (`(:file-desc . ,(and (pred stringp) val)) val) + (`(:file-desc . []) nil))) + ;;;###autoload (defun org-babel-execute-src-block (&optional arg info params) "Execute the current source code block. @@ -749,8 +757,7 @@ block." (let ((*this* (if (not file) result (org-babel-result-to-file file - (let ((desc (assq :file-desc params))) - (and desc (or (cdr desc) result))))))) + (org-babel--file-desc params result))))) (setq result (org-babel-ref-resolve post)) (when file (setq result-params (remove "file" result-params)))))) @@ -2257,9 +2264,8 @@ INFO may provide the values of these header arguments (in the (setq result (org-no-properties result)) (when (member "file" result-params) (setq result (org-babel-result-to-file - result (when (assq :file-desc (nth 2 info)) - (or (cdr (assq :file-desc (nth 2 info))) - result)))))) + result + (org-babel--file-desc (nth 2 info) result))))) ((listp result)) (t (setq result (format "%S" result)))) (if (and result-params (member "silent" result-params)) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 648e9c115..df4b13498 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1084,7 +1084,25 @@ trying to find the :END: marker." (org-babel-execute-src-block) (goto-char (point-min)) (should (search-forward "[[file:foo][bar]]" nil t)) - (should (search-forward "[[file:foo][foo]]" nil t)))) + (should (search-forward "[[file:foo][foo]]" nil t))) + (should (string-match-p + (regexp-quote "[[file:foo]]") + (org-test-with-temp-text " +#+begin_src emacs-lisp :results file :file-desc [] + \"foo\" +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block) + (buffer-substring-no-properties (point-min) (point-max))))) + (should (string-match-p + (regexp-quote "[[file:foo][foo]]") + (org-test-with-temp-text " +#+begin_src emacs-lisp :results file :file-desc + \"foo\" +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block) + (buffer-substring-no-properties (point-min) (point-max)))))) (ert-deftest test-ob/result-file-link-type-header-argument () "Ensure that the result is a link to a file. -- 2.28.0 --=-=-=--