From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id oHu4CFbV72QWNAAAG6o9tA:P1 (envelope-from ) for ; Thu, 31 Aug 2023 01:48:38 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id oHu4CFbV72QWNAAAG6o9tA (envelope-from ) for ; Thu, 31 Aug 2023 01:48:38 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C15FB5EE80 for ; Thu, 31 Aug 2023 01:48:37 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=S3pHErtl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1693439318; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=lgznQLHde5xCrAM4LHXOD49pAlHkjfrrreQeS82nDnA=; b=tzigl3xyhzywDU1TwUlDNC40spSRrnRS80LEvFMfJaI0yJB31eH3xzf11voaKBmXQtWXuG psEV9fAnW4BDyBJrHlhJw7qhMf6CiC3t5GYNM/s7YEravPkkHl9fphFwESN22PFTyhaabB x/NjZxAPhqbeqr60KQRepTmPzIMBmlNe9RMFElSiwAJ62dbmnYuwGhp37p6uqEDdP7U31i Ks8P26reVUoTm39bGx7+y7dFEU1GmWJtcf93pKC1l0T55f3MRYPpZ+r5tgugyW0wcXFcpX AovufUD/uHU6GeozUCkltPovhv56F6pFAM/aJ7ucOV61whvnUU0lVGU6Q9DX5Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1693439318; a=rsa-sha256; cv=none; b=Gi2fiNOQWUsJgeItRY7owfbvIptePTp4WmTO4PzkdA9+gSe1kyq0PD+Hc0VLqgwXxZNi9i BW+FbI6RyiSPZRt+ygaOiy/z0GntKTreeMOcfFkbxywkbumRMI6YK44oiCXWqEZEkcG+CQ AaM5M9VgAtVoPvbd0hV8KAq3kuzdIkGxd0WP6l1wmQbKev71dVJSEZZO4zBGc4eLKsVQPA K9MEnl3FJOIFbVnPX03QtFZd6DULHsy6AoO4AhoM1ytmd8UmYZVMDtnnkVqYsw4LBRhTEJ nVXgedChjKXScYIsqyJOutxxP0JDTef+aS44F/3ZU9rrsddnkcuZxWu7bOXtFA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=S3pHErtl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbUuU-0007zY-Fg; Wed, 30 Aug 2023 19:47:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbUuS-0007zI-Qy for emacs-orgmode@gnu.org; Wed, 30 Aug 2023 19:47:40 -0400 Received: from mail-vs1-xe36.google.com ([2607:f8b0:4864:20::e36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbUuP-00047A-5W for emacs-orgmode@gnu.org; Wed, 30 Aug 2023 19:47:40 -0400 Received: by mail-vs1-xe36.google.com with SMTP id ada2fe7eead31-44e9888ebebso173088137.3 for ; Wed, 30 Aug 2023 16:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693439255; x=1694044055; darn=gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=lgznQLHde5xCrAM4LHXOD49pAlHkjfrrreQeS82nDnA=; b=S3pHErtlV/2JlNK85kIjFD8NQQpKAzBJwAp9u5D5Bsuu5DE3wBKjNkWo1bY3jh73CH vSsRm1S0fexTuBJueK7JOdIuO/bYsH1FryVrLqLG+XUTQ9/83uKgAdHRFpdI4eMAjI21 /8Do0UIjWTIJNo6NWXXcSrhy302BE/CnZLjW9K0ZRkm0NfvFKUhQEPbMQoFjaQ2uXu98 sZktHc5RpL4cRBo4nANUo4dBKMGt0feJ6t//pyV5c/0wtiLPSJb4nmlHBAclaOFqzenP gwg/fjvuuyR0GVrQcsIqeoeyyhK+xCbK7ylphqyzmuU9MEDhNFaoHWNb3XR+bkZX1IAy hRYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693439255; x=1694044055; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lgznQLHde5xCrAM4LHXOD49pAlHkjfrrreQeS82nDnA=; b=aL2ZihPESAu+wKDIONgc2SlBf2uh6b/gDdCGqXFgT/VXmS/DmpsK0YgoxG1P8FxAP4 nFIwZ5hgfHSYvTeaqJEseg6k9bPxAwm6kXILwmzbi5Pf5NWcst910+tzB1xa3bOsEYRE cHyRTL0FSg8HFpJQnAktRo8K6Y70u6HNw9UgSBeUzmQ/g5tUa28tShn+Vrx+UJEloVs5 y8LWqiwk65KL8wOJBh1OJpgA5APWN7i+EGBIuBcdRLmBObtIhdOQjCdN39OscMu6uNNA bq0RB5b80dOt324Nsur1stzoratMwPCl8kq5mJNI1BqLsy1pvGSsVjY4VAKldl42XujG VIrg== X-Gm-Message-State: AOJu0YxYj0jqlVf8j4ixaZzYckvT7NrqtgJAqWZYFidVDcB0R7VPHgUZ tbIFHcjgP355leum4Sa0v/vbJ1RcodKcbcjWR4n9nsWfNKI= X-Google-Smtp-Source: AGHT+IFTs7/jwjBtQ0vCKdxU+6PHiB4RnIuWmIidSn5xg8pQWcSX39Cb8Cf2fEQ4Kh46WTZqhoPgrJRLIgGpbsmP/1I= X-Received: by 2002:a67:be12:0:b0:44d:5435:a3e with SMTP id x18-20020a67be12000000b0044d54350a3emr3188875vsq.9.1693439254702; Wed, 30 Aug 2023 16:47:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Rodrigo Morales Date: Wed, 30 Aug 2023 23:47:18 +0000 Message-ID: Subject: Re: [BUG] org-get-outline-path misbehave in some scenarios when org-element-use-cache is t Inbox To: org-mode-email Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::e36; envelope-from=moralesrodrigo1100@gmail.com; helo=mail-vs1-xe36.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.58 X-Spam-Score: -6.58 X-Migadu-Queue-Id: C15FB5EE80 X-Migadu-Scanner: mx2.migadu.com X-TUID: wDBCZT3kdHqc For those interested: here's another minimal working example: #+HEADER: :results output #+begin_src elisp (with-temp-buffer (org-mode) (insert "* 1 ,** 1.1 ,* 2 ") ;; jump to the first headline to print the value of :end (goto-char (point-min)) (princ (format "%s\n" (org-element-property :end (org-element-context)))) ;; search (search-forward "* 2") (beginning-of-line) (insert "a" "\n") ;; jump to the first headline to print the value of :end (goto-char (point-min)) (princ (format "%s\n" (org-element-property :end (org-element-context))))) #+end_src Results of evaluation in v9.6.7 (unexpected behavior) #+RESULTS: #+begin_example 12 18 #+end_example Results of evaluation in latest development main (expected behavior) #+RESULTS: #+begin_example 12 14 #+end_example On Tue, 15 Aug 2023 at 19:03, Rodrigo Morales wrote: > > 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=.