emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Allowed characters/formatting in Org text blocks
@ 2022-06-26  0:12 Fabio Natali
  2022-06-26  0:29 ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Fabio Natali @ 2022-06-26  0:12 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I seem to be having problems when selecting an Org text block from an
Emacs Lisp snippet. An MVE follows.

Consider a buffer with the following blocks. In this first example, the
Emacs Lisp block runs successfully. The block "foo" is identified
correctly and the point gets moved accordingly.

#+name: foo
#+begin_src text
Hello world
#+end_src

#+begin_src emacs-lisp
(org-babel-goto-named-src-block "foo")
#+end_src

Now consider a slight variation where "Hello world" is formatted as a
Org heading. The 'org-babel-goto-named-src-block' function is no longer
able to identify the text block. Executing the Emacs Lisp block results
in the error message below.

#+name: bar
#+begin_src text
* Hello world
#+end_src

#+begin_src emacs-lisp
(org-babel-goto-named-src-block "bar")
#+end_src

#+results:
: source-code block ‘bar’ not found in this buffer

Is this expected? Am I misunderstanding what text blocks are for and
what characters/formatting they're allowed to use?

Thanks, best wishes, Fabio.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Allowed characters/formatting in Org text blocks
  2022-06-26  0:12 Allowed characters/formatting in Org text blocks Fabio Natali
@ 2022-06-26  0:29 ` Ihor Radchenko
  2022-06-26 11:09   ` Fabio Natali
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-06-26  0:29 UTC (permalink / raw)
  To: Fabio Natali; +Cc: emacs-orgmode

Fabio Natali <me@fabionatali.com> writes:

> Now consider a slight variation where "Hello world" is formatted as a
> Org heading. The 'org-babel-goto-named-src-block' function is no longer
> able to identify the text block. Executing the Emacs Lisp block results
> in the error message below.
>
> #+name: bar
> #+begin_src text
> * Hello world
> #+end_src
> ...
> Is this expected? Am I misunderstanding what text blocks are for and
> what characters/formatting they're allowed to use?

Headline markup has the highest priority. Your block is interpreted as

<paragraph with #+name affiliated keyword>
#+name: bar
#+begin_sec text
<headline>
* Hello world
<paragraph>
#+end_src

See https://orgmode.org/manual/Literal-Examples.html
You need to escape "*" and "#+" at the beginning of line inside code
blocks using comma: ",*", ",#+".
Org will do it for you automatically if you use C-c ' interface to edit
source blocks.

Best,
Ihor


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Allowed characters/formatting in Org text blocks
  2022-06-26  0:29 ` Ihor Radchenko
@ 2022-06-26 11:09   ` Fabio Natali
  2022-06-26 11:39     ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Fabio Natali @ 2022-06-26 11:09 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 2022-06-26 08:29:02 +0800, Ihor Radchenko <yantar92@gmail.com> wrote:
[...]
> You need to escape "*" and "#+" at the beginning of line inside code
> blocks using comma: ",*", ",#+".

Hi Ihor,

Thanks for getting back to me!

I see, and yes, the documentation is pretty clear in that regard, you're
right. Escaping leading =*= and =#+= is perfectly possible in my case
and this completely solves my issue.

By the way, I've just tried with comment blocks, and I see that this
works the same way there too.

Incidentally and FWIW, this is a bit counter-intuitive to me. I'd have
expected everything withing a comment or literal block to be treated as
content until the ending statement, =#+end_comment= or =#+end_src=
respectively. I suppose that this makes sense in the larger scheme of
Org things though?

Thanks again, best wishes,

Fabio.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Allowed characters/formatting in Org text blocks
  2022-06-26 11:09   ` Fabio Natali
@ 2022-06-26 11:39     ` Ihor Radchenko
  2022-06-26 17:31       ` Fabio Natali
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-06-26 11:39 UTC (permalink / raw)
  To: Fabio Natali; +Cc: emacs-orgmode

Fabio Natali <me@fabionatali.com> writes:

> Incidentally and FWIW, this is a bit counter-intuitive to me. I'd have
> expected everything withing a comment or literal block to be treated as
> content until the ending statement, =#+end_comment= or =#+end_src=
> respectively. I suppose that this makes sense in the larger scheme of
> Org things though?

Each Org document consists of an optional first chapter followed by a
sequence of headlines. Each headline is a sequence of optional section
followed by sequence of child headlines. Each section is a sequence of
ordinary syntax elements. No syntax element ever intersect other
element.

So, headlines always have higher priority over other elements because
they always serve as separators of the document or parent heading
contents.

The high priority of headline elements has prons and cons.
Consider the following markdown markup:

     test 1
==============

```
    (message "Hello world!")

... 100 headings not shown ...

     test 2
==============

    (message "Hello world!")

```

Should "test 2" be considered a heading?
The answer is not so important in short documents, but long documents
with large number of headings may become very sensitive to incomplete or
broken markup like the above.
In Org, you just need to care about getting the headings right. Issues
with all other markup elements should never go beyond the containing
headline section, which is especially useful when Org document is used
as todo-list with large number of headings.

Best,
Ihor


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Allowed characters/formatting in Org text blocks
  2022-06-26 11:39     ` Ihor Radchenko
@ 2022-06-26 17:31       ` Fabio Natali
  0 siblings, 0 replies; 5+ messages in thread
From: Fabio Natali @ 2022-06-26 17:31 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 2022-06-26 19:39:25 +0800, Ihor Radchenko <yantar92@gmail.com> wrote:
[...]
> So, headlines always have higher priority over other elements because
> they always serve as separators of the document or parent heading
> contents.
> 
> The high priority of headline elements has prons and cons.

Hey Ihor,

I see, it all makes sense. That was a very useful recap.

Thanks for your help with this! All the best, Fabio.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-26 17:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-26  0:12 Allowed characters/formatting in Org text blocks Fabio Natali
2022-06-26  0:29 ` Ihor Radchenko
2022-06-26 11:09   ` Fabio Natali
2022-06-26 11:39     ` Ihor Radchenko
2022-06-26 17:31       ` Fabio Natali

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