[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 98cae03b7d 2/2: lisp/org-element: Add a parameters-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 98cae03b7d 2/2: lisp/org-element: Add a parameters-line property to special blocks |
Date: |
Thu, 20 Oct 2022 05:58:00 -0400 (EDT) |
branch: externals/org
commit 98cae03b7d9a612334d5ea461e73ac0b37b0285d
Author: Bruno BARBIER <brubar.cs@gmail.com>
Commit: Ihor Radchenko <yantar92@posteo.net>
lisp/org-element: Add a parameters-line property to special blocks
Add a property `:parameters' 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'.
(org-element-special-block-interpreter): Interpret the property
`:parameters'.
*
testing/lisp/test-org-element.el (test-org-element/special-block-parser):
Add a new test for PARAMETERS.
(test-org-element/special-block-interpreter): Add new tests for PARAMETERS.
---
lisp/org-element.el | 19 +++++++++++++------
testing/lisp/test-org-element.el | 33 +++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index ca3b61b49f..ce6daaef84 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -1868,13 +1868,15 @@ keyword and CDR is a plist of affiliated keywords along
with
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', `: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 (match-string-no-properties 2)))
(if (not (save-excursion
(re-search-forward
(format "^[ \t]*#\\+END_%s[ \t]*$" (regexp-quote type))
@@ -1898,6 +1900,8 @@ Assume point is at the beginning of the block."
(list 'special-block
(nconc
(list :type type
+ :parameters (and (org-string-nw-p parameters)
+ (org-trim parameters))
:begin begin
:end end
:contents-begin contents-begin
@@ -1909,8 +1913,11 @@ Assume point is at the beginning of the block."
(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 (or contents "") block-type)))
+ (let ((block-type (org-element-property :type special-block))
+ (parameters (org-element-property :parameters special-block)))
+ (format "#+begin_%s%s\n%s#+end_%s" block-type
+ (if parameters (concat " " parameters) "")
+ (or contents "") block-type)))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 985108e375..eb5b95e86e 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -2429,7 +2429,19 @@ Outside list"
;; When contents is empty, the parsed contents is nil.
(should
(org-test-with-temp-text "#+BEGIN_SPECIAL\n#+END_SPECIAL"
- (eq nil (org-element-contents (org-element-at-point))))))
+ (eq nil (org-element-contents (org-element-at-point)))))
+ ;; Parse parameters if any, trimming blanks.
+ (should
+ (org-test-with-temp-text "#+BEGIN_SPECIAL* s p :w 3
\nContent.\n#+END_SPECIAL*"
+ (equal "s p :w 3"
+ (org-element-property :parameters (org-element-at-point)))))
+ ;; When parameters is blank, `:parameters' is nil.
+ (should
+ (org-test-with-temp-text "#+BEGIN_SPECIAL* \t
\nContent.\n#+END_SPECIAL*"
+ (eq nil (org-element-property :parameters (org-element-at-point))))
+ ))
+
+
;;;; Src Block
@@ -2945,13 +2957,30 @@ Outside list"
(ert-deftest test-org-element/special-block-interpreter ()
"Test special block interpreter."
+ ;; No parameters
(should (equal (org-test-parse-and-interpret
"#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
"#+begin_SPECIAL\nTest\n#+end_SPECIAL\n"))
;; No content
(should (equal (org-test-parse-and-interpret
"#+BEGIN_SPECIAL\n#+END_SPECIAL")
- "#+begin_SPECIAL\n#+end_SPECIAL\n")))
+ "#+begin_SPECIAL\n#+end_SPECIAL\n"))
+ ;; Some parameters
+ (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"))
+ ;; No parameters (blanks only)
+ (should
+ (equal (org-test-parse-and-interpret
+ "#+BEGIN_special \t \nA very special content\n#+END_special")
+ "#+begin_special\nA very special content\n#+end_special\n"))
+ ;; Some parameters with leading and trailing blanks, no content, and
+ ;; a /special/ name.
+ (should
+ (equal (org-test-parse-and-interpret
+ "#+BEGIN_spe<c>ial :a :b \t :c \t \n#+END_spe<c>ial")
+ "#+begin_spe<c>ial :a :b \t :c\n#+end_spe<c>ial\n")))
(ert-deftest test-org-element/babel-call-interpreter ()
"Test Babel call interpreter."