From: Ihor Radchenko <yantar92@posteo.net>
To: Garulfo <garulfo@azules.eu>
Cc: emacs-orgmode@gnu.org
Subject: Re: back-end - access to :mode attribute for section and symbol-name
Date: Tue, 16 Jan 2024 18:39:15 +0000 [thread overview]
Message-ID: <87v87tjf70.fsf@localhost> (raw)
In-Reply-To: <ed2b9bda-b2d2-4cf1-8999-c2e23b5ca3c2@azules.eu>
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>
prev parent reply other threads:[~2024-01-16 18:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 13:15 back-end - access to :mode attribute for section and symbol-name Garulfo
2024-01-16 18:39 ` Ihor Radchenko [this message]
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=87v87tjf70.fsf@localhost \
--to=yantar92@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=garulfo@azules.eu \
/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).