From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ENvnEzOuTWNaBQAAbAwnHQ (envelope-from ) for ; Mon, 17 Oct 2022 21:34:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id +N38EzOuTWOROAAA9RJhRA (envelope-from ) for ; Mon, 17 Oct 2022 21:34:11 +0200 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 A85B2291DD for ; Mon, 17 Oct 2022 21:34:10 +0200 (CEST) Received: from localhost ([::1]:54824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okVsG-0008Qb-HD for larch@yhetil.org; Mon, 17 Oct 2022 15:34:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okViG-0002eo-8E for emacs-orgmode@gnu.org; Mon, 17 Oct 2022 15:23:49 -0400 Received: from smtp6-g21.free.fr ([2a01:e0c:1:1599::15]:62032) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okViE-0003Ce-3T for emacs-orgmode@gnu.org; Mon, 17 Oct 2022 15:23:47 -0400 Received: from tosh-laptop (unknown [IPv6:2a01:e0a:505:3460:1a16:a0c4:3f89:c0d9]) by smtp6-g21.free.fr (Postfix) with ESMTPS id D456B780306; Mon, 17 Oct 2022 21:23:40 +0200 (CEST) Received: by tosh-laptop (sSMTP sendmail emulation); Mon, 17 Oct 2022 21:28:40 +0200 From: Bruno Barbier To: Damien Cassou , emacs-orgmode@gnu.org Subject: PATCH: Re: Reading the parameters of a special-block In-Reply-To: <87zgdu26dd.fsf@cassou.me> References: <87zgdu26dd.fsf@cassou.me> Date: Mon, 17 Oct 2022 21:28:39 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: softfail client-ip=2a01:e0c:1:1599::15; envelope-from=brubar.cs@gmail.com; helo=smtp6-g21.free.fr X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, MISSING_MID=0.497, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action Message-Id: 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" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666035250; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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; bh=vugEMz+rqRWBIg0u7uJq/JhKLunDgIqR9+yjeFsR9OE=; b=qVLzAfMP/+KFILEHPeHFHgYS9rFQ/eajNl8HsmnX2sajRTVDT8uxcxhn+7ja3Zh7/78/4d 7zrdQUMRfHgbar3tZbUbXXss12NgtUmmhQqcUSSsHiSfmPE3EZp4AftnmF94p0dqxPsAq0 BfBMbMo8SYL2QyZAcR49UaCb4Nv86BHw+wQy5Q3DEEkqZx8D15P4eR9r4TAdB908XCc+wZ RCS8sLHiZl1FVdvBHPdlqknIjgJRRf8PdQlkq/Fsn+yMm6yfORNCEG+IohKrkdvoEYsy4E 9uQ4scjeonn5VzCVmxnAMA+R5+7wCPA/xobO+1evBN38zjpDcso3AG7+jhOA2Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666035250; a=rsa-sha256; cv=none; b=L+JGISE15z/K1nagrHjvceIw/Gs+JUJYQxX1gafJaLkivvTl56WOtQTsge4VDrZQ7vppBf VrvN8Mud4c0zPGeKX5f6l1z6sNaYDk43wu/DBe0gMx54392TNSmyIyj6qthvzaeda4CCU1 N7/0D241vLtE52DWIxIxMjUMTzZfAK6aY9x7eg412Jjzvfp545DXJ+Xq6lrtEPmUeZ1QWm QzLu3YKcOcVrPYPdm5U/XotuKNM5AiLOop1WqXnpi1tvaCicPObODlvKKBV5bXHwKrp0jk /HYYXC/oa1ENFBXJhxIiFrtTZHPAusYIv3NrOVXCblEnbRS74hCrbWMBUJOWHA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 3.78 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: A85B2291DD X-Spam-Score: 3.78 X-Migadu-Scanner: scn1.migadu.com X-TUID: n1Ojylr1pXnl --=-=-= Content-Type: text/plain Damien Cassou writes: > Hi, > > in Worg's description of Org's syntax, there is a section about "greater > blocks" [1]. The syntax is > > #+begin_NAME PARAMETERS > CONTENTS > #+end_NAME > > There is then a "PARAMETERS" optional string attached to special > blocks. Unfortunately, in the special-block transcoder I'm writing, I > have no clue how to access the parameters. I can't find any parameters > function in org that would be related. > > What is the best way to access the parameters of a special-block? My understanding is that the parameters line is just ignored for special blocks. I wrote and used a patch a while ago to fix this; it was on my todo list to clean it up and submit it to org. Now looks like a good time. My patch adds a `:parameters-line' property to org elements that are special blocks, storing the PARAMETERS line as a string. See attached patch. Could this be added to org ? Bruno --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-lisp-org-element-Add-a-parameters-line-property-to-s.patch Content-Description: Patch to add parameters-line to special blocks >From a57412351a21cecf0a83264139cc99bcc77f1093 Mon Sep 17 00:00:00 2001 From: Bruno BARBIER Date: Mon, 17 Oct 2022 20:19:02 +0200 Subject: [PATCH] lisp/org-element: Add a parameters-line property to special blocks Add a property `parameters-line' to special blocks, to store the PARAMETERS as a string. * lisp/org-element.el (org-element-special-block-parser): Parse PARAMETERS and set the property `:parameters-line'. (org-element-special-block-interpreter): Interpret the new property `:parameters-line'. * testing/lisp/test-org-element.el (test-org-element/special-block-parser): Update to test parsing the block PARAMETERS. (test-org-element/special-block-interpreter-with-params): New test. --- lisp/org-element.el | 20 ++++++++++++++------ testing/lisp/test-org-element.el | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 7b26e877e..23751ad30 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -1868,13 +1868,16 @@ (defun org-element-special-block-parser (limit affiliated) their value. Return a list whose CAR is `special-block' and CDR is a plist -containing `:type', `:begin', `:end', `:contents-begin', -`:contents-end', `:post-blank' and `:post-affiliated' keywords. +containing `:type', `:parameters-line', `:begin', `:end', +`:contents-begin', `:contents-end', `:post-blank' and +`:post-affiliated' keywords. Assume point is at the beginning of the block." (let* ((case-fold-search t) - (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)") - (match-string-no-properties 1)))) + (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)[ \t]*\\(.*\\)[ \t]*$") + (match-string-no-properties 1))) + (parameters-line (match-string-no-properties 2)) + ) (if (not (save-excursion (re-search-forward (format "^[ \t]*#\\+END_%s[ \t]*$" (regexp-quote type)) @@ -1898,6 +1901,7 @@ (defun org-element-special-block-parser (limit affiliated) (list 'special-block (nconc (list :type type + :parameters-line parameters-line :begin begin :end end :contents-begin contents-begin @@ -1909,8 +1913,12 @@ (defun org-element-special-block-parser (limit affiliated) (defun org-element-special-block-interpreter (special-block contents) "Interpret SPECIAL-BLOCK element as Org syntax. CONTENTS is the contents of the element." - (let ((block-type (org-element-property :type special-block))) - (format "#+begin_%s\n%s#+end_%s" block-type contents block-type))) + (let ((block-type (org-element-property :type special-block)) + (block-parameters-line (org-element-property :parameters-line special-block)) + ) + (format "#+begin_%s%s%s\n%s#+end_%s" block-type + (if (string= "" block-parameters-line) "" " ") block-parameters-line + contents block-type))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 187cadf7a..396c329b7 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -2425,7 +2425,13 @@ (ert-deftest test-org-element/special-block-parser () ;; Handle non-empty blank line at the end of buffer. (should (org-test-with-temp-text "#+BEGIN_SPECIAL\nC\n#+END_SPECIAL\n " - (= (org-element-property :end (org-element-at-point)) (point-max))))) + (= (org-element-property :end (org-element-at-point)) (point-max)))) + ;; Parse the parameter line if any + (should + (org-test-with-temp-text "#+BEGIN_SPECIAL* s p :w 3\nC\n#+END_SPECIAL*" + (equal "s p :w 3" + (org-element-property :parameters-line (org-element-at-point)))))) + ;;;; Src Block @@ -2791,6 +2797,14 @@ (ert-deftest test-org-element/dynamic-block-interpreter () "#+BEGIN: myblock :parameter value1\nTest\n#+END:") "#+begin: myblock :parameter value1\nTest\n#+end:\n"))) +(ert-deftest test-org-element/special-block-interpreter-with-params () + "Test special block interpreter." + (should + (equal (org-test-parse-and-interpret + "#+BEGIN_special some parameters until EOL\nA very special content\n#+END_special") + "#+begin_special some parameters until EOL\nA very special content\n#+end_special\n"))) + + (ert-deftest test-org-element/footnote-definition-interpreter () "Test footnote definition interpreter." (should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n")) -- 2.37.3 --=-=-= Content-Type: text/plain > > [1] https://orgmode.org/worg/dev/org-syntax.html#Greater_Blocks > > -- > Damien Cassou > > "Success is the ability to go from one failure to another without > losing enthusiasm." --Winston Churchill --=-=-=--