emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Tom Alexander <tom@fizz.buzz>
Cc: emacs-orgmode@gnu.org
Subject: Re: Extra paragraphs incorrectly spawning when ":end:" appears.
Date: Sun, 01 Oct 2023 07:50:05 +0000	[thread overview]
Message-ID: <87o7hiwzma.fsf@localhost> (raw)
In-Reply-To: <f186c0a8-3a71-4b11-8e25-c5b8d9f4c628@app.fastmail.com>

"Tom Alexander" <tom@fizz.buzz> writes:

> This test document should have 1 paragraph but org-mode is parsing it as 2:
> ```
> foo
> :end:
> baz
> ```
>
> which parses as:
> ```
> (section
>   (paragraph "foo\n")
>   (paragraph ":end:\nbaz\n")
> )
> ```
>
> The paragraph documentation[1] states that:
>> Empty lines and other elements end paragraphs.
>
> But the document contains no empty lines and we can see in the output that it only contains paragraphs.

The documentation is not accurate here.

The parser uses anything that _potentially_ looks like the beginning of
another element to calculate paragraph boundaries
(`org-element-paragraph-separate'). ":end:" is potentially a drawer and
thus ends the preceding paragraph.

Later, ":end:" line is parsed as a new structural element using
`org-element-drawer-parser'. The drawer parser detects that there is no
closing :end: line and thus falls back to paragraph parsing:

(defun org-element-drawer-parser (limit affiliated)
...
	;; Incomplete drawer: parse it as a paragraph.
	(org-element-paragraph-parser limit affiliated)

The same logic applies to a number of other incomplete elements.

The reason behind the current logic and not re-parsing the preceding
paragraph when we encounter incomplete drawer/block/etc is that Org
parser is written to do a single pass - we never re-parse already parsed
parts. Doing things otherwise, while could solve certain non-intuitive
behaviors, would be problematic performance-wise.

So, the actual paragraph separator that should be used is
`org-element-paragraph-separate' regexp.

We need to fix the WORG syntax description accordingly.

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


  parent reply	other threads:[~2023-10-01  7:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30 18:47 Extra paragraphs incorrectly spawning when ":end:" appears Tom Alexander
2023-09-30 19:15 ` Tom Alexander
2023-10-01  7:50 ` Ihor Radchenko [this message]
2023-10-02 14:17   ` Tom Alexander
2024-02-13 11:49   ` 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=87o7hiwzma.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=tom@fizz.buzz \
    /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).