emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: Re: Reading the parameters of a special-block


From: Ihor Radchenko
Subject: Re: PATCH: Re: Reading the parameters of a special-block
Date: Tue, 18 Oct 2022 04:56:18 +0000

Bruno Barbier <brubar.cs@gmail.com> writes:

> 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 ?

I am in favour of it.

The property name could be simply :parameters. Just like in src blocks
(see org-element-src-block-parser).

> -      (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

We probably want something like

:parameters (and (org-string-nw-p parameters) (org-trim parameters))

Just as in org-element-src-block-parser.

> -  (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))
> +     )

No dangling ")" please.

> +    (format "#+begin_%s%s%s\n%s#+end_%s" block-type
> +            (if (string= "" block-parameters-line) "" " ") 
> block-parameters-line
> +            contents block-type)))

We will not need to test against ="" with my above comment incorporated.
  
> @@ -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))))))

May also test against empty parameters and space-only parameters.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]