emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: back-end - access to :mode attribute for section and symbol-name


From: Ihor Radchenko
Subject: Re: back-end - access to :mode attribute for section and symbol-name
Date: Tue, 16 Jan 2024 18:39:15 +0000

Garulfo <garulfo@azules.eu> writes:

> For "ox-mycontext-section", I try to access the attribute ":mode" of the 
> section
> in order to make the difference between "first-section" and "section".
>
> I had to use "symbol-name" :
>
>     (let*
>        ((section_mode (symbol-name (org-element-property :mode section))))
>
> Questions :
> 1/ Is it the "org-mode" way to do ?

:mode is an internal property set by the parser. I do not recommend
using it in your code.

Instead, you can check if a section is the first section like

(if (eq 'org-data (org-element-type (org-element-property :parent section)))
  "First section"
 "Ordinary section inside a heading")

or shorter (on the development version of Org mode)

(if (org-element-type-p (org-element-parent section) 'org-data)
  "First section"
 "Ordinary section inside a heading")

> 2/ What should I read to understand why "symbol-name" is needed, whereas 
> usually "org-element-property" just return the appropriate string.

:mode property is set to the parser mode used to parse a given syntax
node. Its value is not a string but a symbol.

>        (section_mode (symbol-name (org-element-property :mode section))))
>     (pcase section_mode
>       ("first-section" (concat "%\n% FIRST SECTION\n%\n"))

'first-section symbol is not equal to "first-section" string. You would
need

('first-section ...)

to match symbol without converting it to string manually.

-- 
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 via email to

[Prev in Thread] Current Thread [Next in Thread]