emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: org-mode-email <emacs-orgmode@gnu.org>
Subject: [BUG] org-get-outline-path misbehave in some scenarios when org-element-use-cache is t Inbox
Date: Tue, 15 Aug 2023 19:03:17 +0000	[thread overview]
Message-ID: <CAGxMbPbbqc33iaqJ=EceyKrLaf4maJAxaUmJGaPOvG_Rpw+xcQ@mail.gmail.com> (raw)

I've noticed that =org-get-outline-path= report incorrect information
when =org-element-use-cache= is =t=. This mail shows some experiments
that demonstrates this bug.

* Experiment 1

In this experiment, we define a =func= which contains the sexps that
we want to run when =org-element-use-cache= is =t= and when it is
=nil=. In =func=, we use =org-map-entries= to loop through headlines
that have depth 2. In each headline, we move the point two lines below
and insert a new line containing =FOO=.

#+HEADER: :results output
#+begin_src elisp
(let ((func (lambda ()
              (with-temp-buffer
                (org-mode)
                (insert "* 1
,** 1-1
a
,** 1-2
a
,* 2
,** 2-1
b
,** 2-2
b
")
                (princ (format "--- before\n%s\n--- before\n"
                         (buffer-substring-no-properti
es
                          (point-min) (point-max))))
                (org-map-entries
                 (lambda ()
                   ;; We get the outline path before calling
                   ;; (forward-line 2) to ensure that we are referring
                   ;; to the headline in the current iteration
                   (princ (format "org-get-outline-path: %s\n"
(org-get-outline-path t)))
                   ;; Move two lines below the current headline A. After
                   ;; executing (forward-line 2), the point is where
                   ;; the next headline B starts.
                   (forward-line 2)
                   ;; We add a line which moves the headline B, one
                   ;; line below
                   (insert "FOO" "\n"))
                 "LEVEL=2")
                (princ (format "--- after \n%s\n---after\n"
                         (buffer-substring-no-properti
es
                          (point-min) (point-max))))))))
  (princ "Experiment 1.1 (org-element-use-cache nil)\n")
  (let ((org-element-use-cache nil))
    (funcall func))
  (princ "Experiment 1.2 (org-element-use-cache t)\n")
  (let ((org-element-use-cache t))
    (funcall func)))
#+end_src

#+RESULTS:
#+begin_example
Experiment 1.1 (org-element-use-cache nil)
--- before
,* 1
,** 1-1
a
,** 1-2
a
,* 2
,** 2-1
b
,** 2-2
b

--- before
org-get-outline-path: (1 1-1)
org-get-outline-path: (1 1-2)
org-get-outline-path: (2 2-1)
org-get-outline-path: (2 2-2)
--- after
,* 1
,** 1-1
a
FOO
,** 1-2
a
FOO
,* 2
,** 2-1
b
FOO
,** 2-2
b
FOO

---after
Experiment 1.2 (org-element-use-cache t)
--- before
,* 1
,** 1-1
a
,** 1-2
a
,* 2
,** 2-1
b
,** 2-2
b

--- before
org-get-outline-path: (1 1-1)
org-get-outline-path: (1 1-1 1-2)
org-get-outline-path: (1 2 2-1)
org-get-outline-path: (1 2 2-2)
--- after
,* 1
,** 1-1
a
FOO
,** 1-2
a
FOO
,* 2
,** 2-1
b
FOO
,** 2-2
b
FOO

---after
#+end_example

In the results above, we can see that in =Experiment 1.2=,
=org-get-outline-path= returns wrong information (note that the
results are lists of length 3), while in =Experiment 1.1= this doesn't
happen.

* Experiment 2

I noticed that when we pass one paameter (i.e. ="FOO\n"=) instead of
two as we did in the previous experiment (i.e. ="FOO" "\n"=) to
=insert=, the bug doesn't happen. See minimal reproducible example
below.

In this group of experiments we pass ="FOO\n"= instead of ="FOO" "\n"=
to =insert=.

#+HEADER: :results output
#+begin_src elisp
(let ((func (lambda ()
              (with-temp-buffer
                (org-mode)
                (insert "* 1
,** 1-1
a
,** 1-2
a
,* 2
,** 2-1
b
,** 2-2
b
")
                (princ (format "--- before\n%s\n--- before\n"
                         (buffer-substring-no-properties
                          (point-min) (point-max))))
                (org-map-entries
                 (lambda ()
                   (princ (format "org-get-outline-path: %s\n"
(org-get-outline-path t)))
                   (forward-line 2)
                   (insert "FOO\n"))
                 "LEVEL=2")
                (princ (format "--- after \n%s\n---after\n"
                         (buffer-substring-no-properties
                          (point-min) (point-max))))))))
  (princ "Experiment 2.1 (org-element-use-cache nil)\n")
  (let ((org-element-use-cache nil))
    (funcall func))
  (princ "Experiment 2.2 (org-element-use-cache t)\n")
  (let ((org-element-use-cache t))
    (funcall func)))
#+end_src

#+RESULTS:
#+begin_example
Experiment 2.1 (org-element-use-cache nil)
--- before
,* 1
,** 1-1
a
,** 1-2
a
,* 2
,** 2-1
b
,** 2-2
b

--- before
org-get-outline-path: (1 1-1)
org-get-outline-path: (1 1-2)
org-get-outline-path: (2 2-1)
org-get-outline-path: (2 2-2)
--- after
,* 1
,** 1-1
a
FOO
,** 1-2
a
FOO
,* 2
,** 2-1
b
FOO
,** 2-2
b
FOO

---after
Experiment 2.2 (org-element-use-cache t)
--- before
,* 1
,** 1-1
a
,** 1-2
a
,* 2
,** 2-1
b
,** 2-2
b

--- before
org-get-outline-path: (1 1-1)
org-get-outline-path: (1 1-2)
org-get-outline-path: (2 2-1)
org-get-outline-path: (2 2-2)
--- after
,* 1
,** 1-1
a
FOO
,** 1-2
a
FOO
,* 2
,** 2-1
b
FOO
,** 2-2
b
FOO

---after
#+end_example

In the results above, we can see that both Experiment 2.1 and
Experiment 2.2 have the same output.

* Personal thoughts

With regards to experiment 2, we know that passing either ="FOO\n"= or
="FOO" "\n"= insert the same content, so I'm wondering how come
passing different parameters to =insert= which result in the same
outcome can affect the behavior of =org-get-outline-path=.


             reply	other threads:[~2023-08-15 19:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 19:03 Rodrigo Morales [this message]
2023-08-16  8:47 ` [BUG] org-get-outline-path misbehave in some scenarios when org-element-use-cache is t Inbox Ihor Radchenko
2023-08-30 23:47 ` Rodrigo Morales

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='CAGxMbPbbqc33iaqJ=EceyKrLaf4maJAxaUmJGaPOvG_Rpw+xcQ@mail.gmail.com' \
    --to=moralesrodrigo1100@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).