emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Bruno Barbier <brubar.cs@gmail.com>
Cc: Damien Cassou <damien@cassou.me>,  emacs-orgmode@gnu.org
Subject: Re: PATCH: Re: Reading the parameters of a special-block
Date: Tue, 18 Oct 2022 04:56:18 +0000	[thread overview]
Message-ID: <871qr5hgr1.fsf@localhost> (raw)
In-Reply-To: <E1okViG-0002eo-8E@lists.gnu.org>

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	other threads:[~2022-10-18  4:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17  8:37 Reading the parameters of a special-block Damien Cassou
2022-10-17 19:28 ` PATCH: " Bruno Barbier
2022-10-18  4:56   ` Ihor Radchenko [this message]
2022-10-19 18:18     ` Bruno Barbier
2022-10-20  5:31       ` Ihor Radchenko
     [not found]         ` <notmuch-sha1-5aa2ae4e8031bcbe3c55fd813dfb0f61229b24d1>
2022-10-20  9:45           ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871qr5hgr1.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=brubar.cs@gmail.com \
    --cc=damien@cassou.me \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).