emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* block folding - should this work?
@ 2021-12-24 21:21 Robert Nikander
  2021-12-25  5:57 ` tomas
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Robert Nikander @ 2021-12-24 21:21 UTC (permalink / raw)
  To: emacs-orgmode

I started reading about “blocks" in the manual. I wanted a chunk of text that I could hide, so I tried this:

* Test
Some text
#+BEGIN 
Hide this
#+END

Hitting TAB on the BEGIN line does nothing. But if I add a blank line before it, then hitting TAB hides and shows the block. Is that a bug? Or am I doing it wrong? Seems like it should work without the blank line.

* Test
Some text

#+BEGIN 
Hide this
#+END

M-x org-version => 9.5.1.

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

* Re: block folding - should this work?
  2021-12-24 21:21 block folding - should this work? Robert Nikander
@ 2021-12-25  5:57 ` tomas
  2021-12-26 14:50 ` [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block Ihor Radchenko
  2021-12-29 21:37 ` block folding - should this work? Tim Cross
  2 siblings, 0 replies; 6+ messages in thread
From: tomas @ 2021-12-25  5:57 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

On Fri, Dec 24, 2021 at 04:21:58PM -0500, Robert Nikander wrote:
> I started reading about “blocks" in the manual. I wanted a chunk of text that I could hide, so I tried this:
> 
> * Test
> Some text
> #+BEGIN 
> Hide this
> #+END
> 
> Hitting TAB on the BEGIN line does nothing. But if I add a blank line before it, then hitting TAB hides and shows the block. Is that a bug? Or am I doing it wrong? Seems like it should work without the blank line.
> 
> * Test
> Some text
> 
> #+BEGIN 
> Hide this
> #+END
> 
> M-x org-version => 9.5.1.

Ah. You have to decide on a concrete /kind/ of block.
So try:

  #+begin_example
  This is a small example
  with two lines
  #+end_example

(BTW. I seem to remember that Org prefers to spell those things in lower
case these days, as in my example).

There are some block kinds which Org "knows about" and treats specially,
like _example, _quote, _center, _src and so on.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block
  2021-12-24 21:21 block folding - should this work? Robert Nikander
  2021-12-25  5:57 ` tomas
@ 2021-12-26 14:50 ` Ihor Radchenko
  2021-12-26 19:24   ` Nicolas Goaziou
  2021-12-29 21:37 ` block folding - should this work? Tim Cross
  2 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2021-12-26 14:50 UTC (permalink / raw)
  To: Robert Nikander, Nicolas Goaziou; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 693 bytes --]

Robert Nikander <robert.nikander@icloud.com> writes:

> Hitting TAB on the BEGIN line does nothing. But if I add a blank line before it, then hitting TAB hides and shows the block. Is that a bug? Or am I doing it wrong? Seems like it should work without the blank line.
>
> * Test
> Some text
>
> #+BEGIN 
> Hide this
> #+END
>
> M-x org-version => 9.5.1.

This last case is actually a bug. As Tomas pointed, Org blocks have
slightly different syntax: either #+begin_something or #+begin:
typeofblock. The fact that you can fold the #+BEGIN..#+END in your
second case should not happen.

The fix is attached.

Nicolas,
Let me know if I miss something about special block parsing.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-element-current-element-Fix-BEGIN-parsed-as-spec.patch --]
[-- Type: text/x-diff, Size: 1192 bytes --]

From 289afdb9672eadaea119ebb2b0deecff4db3aa89 Mon Sep 17 00:00:00 2001
Message-Id: <289afdb9672eadaea119ebb2b0deecff4db3aa89.1640530104.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sun, 26 Dec 2021 22:45:36 +0800
Subject: [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special
 block

* lisp/org-element.el (org-element--current-element): Use
`org-element-dynamic-block-open-re' to match blocks.

Reported in https://list.orgmode.org/Ycay4s3iAdEGSwgt@tuxteam.de/T/#t
---
 lisp/org-element.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index eac39d429..ce251da38 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4266,7 +4266,7 @@ (defun org-element--current-element (limit &optional granularity mode structure
 	            ((looking-at "CALL:")
 		     (beginning-of-line)
 		     (org-element-babel-call-parser limit affiliated))
-	            ((looking-at "BEGIN:? ")
+	            ((looking-at org-element-dynamic-block-open-re)
 		     (beginning-of-line)
 		     (org-element-dynamic-block-parser limit affiliated))
 	            ((looking-at "\\S-+:")
-- 
2.32.0


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

* Re: [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block
  2021-12-26 14:50 ` [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block Ihor Radchenko
@ 2021-12-26 19:24   ` Nicolas Goaziou
  2022-05-14  5:55     ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2021-12-26 19:24 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Robert Nikander

Hello,

Ihor Radchenko <yantar92@gmail.com> writes:

> Nicolas,
> Let me know if I miss something about special block parsing.

LGTM! Thanks.

Regards,
-- 
Nicolas Goaziou


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

* Re: block folding - should this work?
  2021-12-24 21:21 block folding - should this work? Robert Nikander
  2021-12-25  5:57 ` tomas
  2021-12-26 14:50 ` [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block Ihor Radchenko
@ 2021-12-29 21:37 ` Tim Cross
  2 siblings, 0 replies; 6+ messages in thread
From: Tim Cross @ 2021-12-29 21:37 UTC (permalink / raw)
  To: emacs-orgmode


Robert Nikander <robert.nikander@icloud.com> writes:

> I started reading about “blocks" in the manual. I wanted a chunk of text that I could hide, so I tried this:
>
> * Test
> Some text
> #+BEGIN 
> Hide this
> #+END
>
> Hitting TAB on the BEGIN line does nothing. But if I add a blank line before it,
> then hitting TAB hides and shows the block. Is that a bug? Or am I doing it
> wrong? Seems like it should work without the blank line.
>
> * Test
> Some text
>
> #+BEGIN 
> Hide this
> #+END
>
> M-x org-version => 9.5.1.

The problem here is that your blocks are not correctly specified. If you
run M-x org-lint on your example, it will tell you the blocks may not be
correctly specified. You need to tell org what sort of block it is. Org
supports a number of different block types, such as source code blocks
(#+begin_src/#+end_src), example blocks (#+begin_example/#+end_example),
centred blocks (#+begin_center/#+end_center) etc. You can use C-c C-, to
run the command org-insert-structured-template to select the block type.
If you first highlight the region, it will be wrapped in the block you
select.



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

* Re: [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block
  2021-12-26 19:24   ` Nicolas Goaziou
@ 2022-05-14  5:55     ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2022-05-14  5:55 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Robert Nikander, emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> Nicolas,
>> Let me know if I miss something about special block parsing.
>
> LGTM! Thanks.

Applied onto main as e5e7ae36c.

I changed the patch as org-element-dynamic-block-open-re is matching
from bol.

Also, I fixed one broken test that assumed
#+BEGIN:
Paragraph
to be a full paragraph, not a sequence of keyword + paragraph.

Best,
Ihor


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

end of thread, other threads:[~2022-05-14  5:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24 21:21 block folding - should this work? Robert Nikander
2021-12-25  5:57 ` tomas
2021-12-26 14:50 ` [PATCH] org-element--current-element: Fix #+BEGIN$ parsed as special block Ihor Radchenko
2021-12-26 19:24   ` Nicolas Goaziou
2022-05-14  5:55     ` Ihor Radchenko
2021-12-29 21:37 ` block folding - should this work? Tim Cross

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