emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-element-at-point and special blocks
@ 2015-12-09 18:04 Rasmus
  2015-12-10  6:34 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus @ 2015-12-09 18:04 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Is there a reason why org-element-at-point reports the type to be a
paragraph for special blocks?  E.g. in the examples at the bottom of this
mail, where | is the cursor, the types are: export-block, src-block and
paragraph with a nested special block.

Is there a neat way to detect if point is inside a block?  I’m trying to
write a function for structures (e.g. #+begin_latex) that works like
org-babel-demarcate-block.

Thanks,
Rasmus

#+BEGIN_LaTeX
|
#+END_LaTeX


#+BEGIN_SRC emacs-lisp
|
#+END_SRC


#+begin_abstract
|
#+end_abstract


-- 
Dung makes an excellent fertilizer

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

* Re: org-element-at-point and special blocks
  2015-12-09 18:04 org-element-at-point and special blocks Rasmus
@ 2015-12-10  6:34 ` Nicolas Goaziou
  2015-12-10 15:48   ` Rasmus
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2015-12-10  6:34 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> Is there a reason why org-element-at-point reports the type to be a
> paragraph for special blocks?  E.g. in the examples at the bottom of this
> mail, where | is the cursor, the types are: export-block, src-block and
> paragraph with a nested special block.

This is a corner-case. `org-element-at-point' returns the closest
element at point, but prefers to see an empty paragraph than a special
block, for consistency. I.e., when point is within block boundaries, you
never return `special-block'.

> Is there a neat way to detect if point is inside a block?  I’m trying to
> write a function for structures (e.g. #+begin_latex) that works like
> org-babel-demarcate-block.

(org-element-lineage (org-element-at-point) '(special-block) t)

Regards,

-- 
Nicolas Goaziou

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

* Re: org-element-at-point and special blocks
  2015-12-10  6:34 ` Nicolas Goaziou
@ 2015-12-10 15:48   ` Rasmus
  2015-12-10 16:08     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus @ 2015-12-10 15:48 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nicolas,

Thanks for the helpful reply.

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

>> Is there a reason why org-element-at-point reports the type to be a
>> paragraph for special blocks?  E.g. in the examples at the bottom of this
>> mail, where | is the cursor, the types are: export-block, src-block and
>> paragraph with a nested special block.
>
> This is a corner-case. `org-element-at-point' returns the closest
> element at point, but prefers to see an empty paragraph than a special
> block, for consistency. I.e., when point is within block boundaries, you
> never return `special-block'.

Out of curiosity, why is it "more" consistent to return paragraph here?

>> Is there a neat way to detect if point is inside a block?  I’m trying to
>> write a function for structures (e.g. #+begin_latex) that works like
>> org-babel-demarcate-block.
>
> (org-element-lineage (org-element-at-point) '(special-block) t)

That's very cool.  Thanks.

Rasmus

-- 
Even a three-legged dog has three good legs to lose

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

* Re: org-element-at-point and special blocks
  2015-12-10 15:48   ` Rasmus
@ 2015-12-10 16:08     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2015-12-10 16:08 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Out of curiosity, why is it "more" consistent to return paragraph
> here?

Notwithstanding this case, if `org-element-at-point' returns
`special-block', you /know/ that you are either on block boundaries
(#+begin_special or #+end_special) or on any affiliated keyword above,
but /never/ within the block.

If `org-element-at-point' returns `special-block' here, you create an
exception, which you have to handle later on.

Besides, the truly empty contents are

  #+begin_special
  #+end_special

therefore, I'm not shocked if

  #+begin_special
  
  #+end_special

is a special block with an empty paragraph instead.

Regards,

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

end of thread, other threads:[~2015-12-10 16:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-09 18:04 org-element-at-point and special blocks Rasmus
2015-12-10  6:34 ` Nicolas Goaziou
2015-12-10 15:48   ` Rasmus
2015-12-10 16:08     ` Nicolas Goaziou

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