emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Max Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Incorrect link is stored (org-elements?)
Date: Wed, 10 Nov 2021 21:48:52 +0800	[thread overview]
Message-ID: <87zgqcktob.fsf@localhost> (raw)
In-Reply-To: <smgfa9$71t$1@ciao.gmane.io>

Max Nikulin <manikulin@gmail.com> writes:

> With equivalent patch (attached one has additional differences in spaces 
> around) my particular case works. I have no idea which additional 
> scenarios it may affect. I did not test the patch extensively. I faced 
> the issue while I was preparing a patch to fix storing double #CUSTOM_ID 
> links.

I pushed the patch upstream.

> P.S. I am puzzled that `org-element-at-point' returns paragraph even 
> when patch is not applied. After such call `org-store-link' does what I 
> expect. However "after undo" erroneous state survives emacs restart, 
> thanks to org-persist, I believe.

The bug was in very specific case. org-element-at-point now has a
special fast mode of operation when CACHED-ONLY argument is non-nil. In
this mode, it does not try to parse anything, but only checks the
nearest cached element and returns it if point is at the element
beginning, within +begin/end line of the element, or inside a
non-greater element. The error happened when the cached element was a
section and point was within blank lines at the end of the section
exactly one symbol before the following headline. In such cases,
org-element-at-point must follow some special rules (see comments in
org-element--parse-to), but it did not in this specific scenario.
On top of that, org-element-parse-to cannot return section and the
current code assumes that we ever attempt to return section when point
is at the beginning of section. So, it returns
(org-element-at-point (1+ pos)) instead. Hence, the next headline
was wrongly returned when (1) point is 1- beginning of next headline
(2) we are within blank lines at the end of section (3) some edit in
buffer just cleared everything in cache inside current section
(4) org-element-at-point is called with non-nil CACHED-ONLY argument.

Just calling org-element-at-point did not trigger error. You would need
to call (org-element-at-point nil 'cached)

Best,
Ihor



  reply	other threads:[~2021-11-10 13:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 17:01 Incorrect link is stored (org-elements?) Max Nikulin
2021-11-09 11:46 ` Ihor Radchenko
2021-11-10 12:52   ` Max Nikulin
2021-11-10 13:48     ` Ihor Radchenko [this message]
2021-11-11 14:45       ` Max Nikulin

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=87zgqcktob.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    /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).