From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id sNQhBLfd6mVjXQAAqHPOHw:P1 (envelope-from ) for ; Fri, 08 Mar 2024 10:43:19 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id sNQhBLfd6mVjXQAAqHPOHw (envelope-from ) for ; Fri, 08 Mar 2024 10:43:19 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=n2zkuR2i; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1709890998; a=rsa-sha256; cv=none; b=rWid/zyhZIQw7kPkIy37vpfW098QvCvdAVM2nRs8PWtpDVvRbHEQydcDUo/lt3TF+EpgA0 8X8UTWo+aZWL6Z/FeJAOuygVxU4nP4S7SU3QgezNfO4QKctWAh4W3nys7eeXfb0TFA8g1x Wd1+LW7cVttTvDYLuvp/ZDvA8pskU95DPwkEp6ft+HRM0DcXzF+IgwJFC+nAzVQ2WqVwDL Jt6+076jdPaaCjiwHa9nEii1CMBEP/313cGuxpHHrM4GDZFSo4Svh0zrTzAEx4V0QlOxmD F0U0UnJr/Sr7d103Wkiyt3MqpoFdtYXv6yYuf/4kdbfm+ftrIorIT/i0X1L+ZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=n2zkuR2i; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1709890998; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=m1mK5TilVFIplZah+M8xDgb/wxAJKw0TKWAeYt9Cy+c=; b=f7cy/weAKyaLiS6m73QxQYDI9a9ctd+wM7ApiIfAXGKtvon2zTXS02eJpN0OopHrABSjwj uDQshp3FpgmRKWfCdLZecTb9lzwVp4BiVH31YRtchf/YA7b22xco42DeauFlMo61TgqQs8 fHosTMvAuFyBT7wnTTv8vCxy3yr0y/S/GL4nHvbTmW/IfdU0JkhM2xK12RK4W3rlyBiX2W n8UllTQho/MKNnU7zZPa5QVJN1yv2t2dF7tSCHUSZ3Jlq6cttLrZAMEv0KnThdLI/yWJ2i T7KcJdBFqujdDIcwP+ivJY1ridPUNlqg/ndoK/bpt6ZuCEG9Wd6GEMuSw/om3w== 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 D4C16EAC2 for ; Fri, 8 Mar 2024 10:43:18 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riWkJ-00070Y-FY; Fri, 08 Mar 2024 04:42:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1riWkH-000703-T3 for emacs-orgmode@gnu.org; Fri, 08 Mar 2024 04:42:29 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1riWkF-0002nH-9q for emacs-orgmode@gnu.org; Fri, 08 Mar 2024 04:42:29 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 1BC7B240028 for ; Fri, 8 Mar 2024 10:42:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1709890945; bh=OXfAJlRz539vhIWyO67BORpax3+1NGbqw052CcVhZYw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=n2zkuR2iRhUTkabDBsyAhOVYrF5xjbmdrOjbhpwJDxowuQ9X3Sa8LQwVneQGRChmC YODVW0CJZ4xLrBi4KuAq/+Ue/RJ3fRw97LDreY45dCzaTsQf8BzXuDxlpTf6nRIo7I OMQo9dTkEwE7R7TGr2qhfoGgTGrBSSovmylvSEccA+6adRnbRy9tzTdLneZdaEJ75H lzJO/qTPtSwVo/YKnS7V4jLqIWP11QZlylmktMVMuG5PuAyr38QssmNxb2QkqJhB+G t3E4elms/gm1C/rK/mjBoZCa3llYN8f3cSOMbmgTzHx4b5BKKKmjn5Wcml1flXEUfE N8eEofWE/pGPw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Trh675pjfz6tvq; Fri, 8 Mar 2024 10:42:23 +0100 (CET) From: Ihor Radchenko To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] obscure error for invalid :exports In-Reply-To: References: Date: Fri, 08 Mar 2024 09:46:30 +0000 Message-ID: <87wmqdhx8p.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -9.47 X-Spam-Score: -9.47 X-Migadu-Queue-Id: D4C16EAC2 X-TUID: elTRg2EEzatT --=-=-= Content-Type: text/plain Max Nikulin writes: > Trying to export (to HTML buffer) > > src_elisp[:exports source]{a} > > I have got an obscure error > > org-export-as: Wrong type argument: char-or-string-p, nil > > I believe, some meaningful error should be signaled. > > I was quite surprised since the following is exported with no error > > #+begin_src elisp :exports source > a > #+end_src Confirmed. The behavior on unknown value of :exports header arg is undefined. We may, however, show a warning in such scenario and avoid throwing cryptic error. See the attached tentative patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-export-Display-a-warning-when-the-value-of-expor.patch >From 8fcf787ca739008118f9834720ee56d6e190401d Mon Sep 17 00:00:00 2001 Message-ID: <8fcf787ca739008118f9834720ee56d6e190401d.1709891167.git.yantar92@posteo.net> From: Ihor Radchenko Date: Fri, 8 Mar 2024 12:42:33 +0300 Subject: [PATCH] org-export: Display a warning when the value of :exports header arg is invalid * lisp/ob-exp.el (org-babel-exp-do-export): Display warning when :exports value is not known. Document nil return value. (org-babel-exp-process-buffer): Do not remove code block when `org-babel-exp-do-export' returns nil. Reported-by: Max Nikulin Link: https://orgmode.org/list/usc9jn$g2r$1@ciao.gmane.io --- lisp/ob-exp.el | 70 +++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index aa6091924..af726dc2c 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -218,22 +218,27 @@ (defun org-babel-exp-process-buffer () (goto-char begin) (let ((replacement (org-babel-exp-do-export info 'inline))) - (if (equal replacement "") - ;; Replacement code is empty: remove - ;; inline source block, including extra - ;; white space that might have been - ;; created when inserting results. - (delete-region begin - (progn (goto-char end) - (skip-chars-forward " \t") - (point))) - ;; Otherwise: remove inline source block - ;; but preserve following white spaces. - ;; Then insert value. - (unless (string= replacement - (buffer-substring begin end)) - (delete-region begin end) - (insert replacement)))))) + (cond + ((equal replacement "") + ;; Replacement code is empty: remove + ;; inline source block, including extra + ;; white space that might have been + ;; created when inserting results. + (delete-region begin + (progn (goto-char end) + (skip-chars-forward " \t") + (point)))) + ((not replacement) + ;; Replacement code cannot be determined. + ;; Leave the code block as is. + (goto-char end)) + ;; Otherwise: remove inline source block + ;; but preserve following white spaces. + ;; Then insert value. + ((not (string= replacement + (buffer-substring begin end))) + (delete-region begin end) + (insert replacement)))))) ((or `babel-call `inline-babel-call) (org-babel-exp-do-export (or (org-babel-lob-get-info element) @@ -249,21 +254,27 @@ (defun org-babel-exp-process-buffer () ;; the object/element, including any extra ;; white space that might have been created ;; when including results. - (if (equal rep "") - (delete-region - begin - (progn (goto-char end) - (if (not (eq type 'babel-call)) - (progn (skip-chars-forward " \t") - (point)) - (skip-chars-forward " \r\t\n") - (line-beginning-position)))) + (cond + ((equal rep "") + (delete-region + begin + (progn (goto-char end) + (if (not (eq type 'babel-call)) + (progn (skip-chars-forward " \t") + (point)) + (skip-chars-forward " \r\t\n") + (line-beginning-position))))) + ((not rep) + ;; Replacement code cannot be determined. + ;; Leave the code block as is. + (goto-char end)) + (t ;; Otherwise, preserve trailing ;; spaces/newlines and then, insert ;; replacement string. (goto-char begin) (delete-region begin end) - (insert rep)))) + (insert rep))))) (`src-block (let ((match-start (copy-marker (match-beginning 0))) (ind (org-current-text-indentation))) @@ -335,6 +346,8 @@ (defun org-babel-exp-do-export (info type &optional hash) TYPE is the code block type: `block', `inline', or `lob'. HASH is the result hash. +Return nil when exported content cannot be determined. + The function respects the value of the :exports header argument." (let ((silently (lambda () (let ((session (cdr (assq :session (nth 2 info))))) (unless (equal "none" session) @@ -348,7 +361,10 @@ (defun org-babel-exp-do-export (info type &optional hash) ("results" (org-babel-exp-results info type nil hash) "") ("both" (org-babel-exp-results info type nil hash) - (org-babel-exp-code info type))))) + (org-babel-exp-code info type)) + (unknown-value + (warn "Unknown value of src block parameter :exports %S" unknown-value) + nil)))) (defcustom org-babel-exp-code-template "#+begin_src %lang%switches%flags\n%body\n#+end_src" -- 2.43.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--