all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [BUG?] Cache: org-scan-tags behaves differently on inlinetasks with and without cache
@ 2021-11-22  8:29 Anders Johansson
  2021-11-22 11:35 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Anders Johansson @ 2021-11-22  8:29 UTC (permalink / raw)
  To: org-mode-email

Hi,
I use inlinetasks with tags extensively in my library for coding
qualitative research data
(https://gitlab.com/andersjohansson/orgqda/).

With the new org-element caching functionality (which hopefully can
provide substantial speedups for my case, thanks Ihor!) I have
stumbled on a difference in how inlinetasks are handled by
org-scan-tags.

Without cache, inlinetasks are matched, but with cache they are not.

A minimal test file:

#+BEGIN_ORG
* Test heading :testtag:
Contents

* Another heading

*************** An inlinetask :testtag:
#+END_ORG

Executing this code in this file
#+BEGIN_SRC emacs-lisp
(let ((org-element-use-cache nil))
  (org-scan-tags
   (lambda () (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
   (cdr (org-make-tags-matcher "testtag"))
   nil))
#+END_SRC

Yields: ("* Test heading :testtag:" "*************** An inlinetask :testtag:")

That is, both the headline and inlinetask were matched

However:
#+BEGIN_SRC
(let ((org-element-use-cache t))
  (org-scan-tags
   (lambda () (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
   (cdr (org-make-tags-matcher "testtag"))
   nil))
#+END_SRC

Yields: ("* Test heading :testtag:")
Only the headline was matched.

The difference is in org-scan-tags, where the code using cache always
retrieves tags for matching with org-get-tags, whereas the code
without cache takes tags from group 4 of the scanning regexp ("re").
It appears that org-get-tags doesn't fetch tags for inlinetasks, is
this really right? Otherwise, the small patch below gets me the right
behaviour (tags returned also for inlinetasks) for these tests.

Best,
Anders Johansson

---
 lisp/org.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 17b7ff597..98ff5dba7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11808,7 +11808,7 @@ (defun org-get-tags (&optional pos-or-element
local fontify)
                      (org-before-first-heading-p))
           (unless (org-element-type pos-or-element) (org-back-to-heading t))
           (let ((ltags (if (org-element-type pos-or-element)
-                           (org-element-property :tags
(org-element-lineage pos-or-element '(headline) t))
+                           (org-element-property :tags
(org-element-lineage pos-or-element '(headline inlinetask) t))
                          (org--get-local-tags fontify)))
                 itags)
             (if (or local (not org-use-tag-inheritance)) ltags
--
2.34.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [BUG?] Cache: org-scan-tags behaves differently on inlinetasks with and without cache
  2021-11-22  8:29 [BUG?] Cache: org-scan-tags behaves differently on inlinetasks with and without cache Anders Johansson
@ 2021-11-22 11:35 ` Ihor Radchenko
  2021-11-22 14:39   ` Anders Johansson
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2021-11-22 11:35 UTC (permalink / raw)
  To: Anders Johansson; +Cc: org-mode-email

Anders Johansson <mejlaandersj@gmail.com> writes:

> Without cache, inlinetasks are matched, but with cache they are not.
>
> A minimal test file:
>
> #+BEGIN_ORG
> * Test heading :testtag:
> Contents
>
> * Another heading
>
> *************** An inlinetask :testtag:
> #+END_ORG

Thanks for reporting! You encountered a bug in org-get-tags. It ignored
inlinetasks in some cases. Fixed in 7a14d6035.

Best,
Ihor


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG?] Cache: org-scan-tags behaves differently on inlinetasks with and without cache
  2021-11-22 11:35 ` Ihor Radchenko
@ 2021-11-22 14:39   ` Anders Johansson
  2021-11-22 15:02     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Anders Johansson @ 2021-11-22 14:39 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: org-mode-email

> Thanks for reporting! You encountered a bug in org-get-tags. It ignored
> inlinetasks in some cases. Fixed in 7a14d6035.

Thank you!
It works very well now, and indeed the counting and collection of
tagged extracts (done with org-scan-tags) is much quicker now with
cache enabled. I tested with some generated files, and it looks like
with caching (assuming an updated cache) the time scales linearly with
the number of headlines/inlinetasks to match versus some power
function (n^1.6) with the old buffer-scanning.

I had considered to implement some kind of cache in my code, but now I
get this "for free"! I originally didn't use org-scan-tags but some
custom and "simpler" code for scanning, but I am glad I refactored to
use org-scan-tags, because now I get this speedup without a single
code change in orgqda.

Best,
Anders


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG?] Cache: org-scan-tags behaves differently on inlinetasks with and without cache
  2021-11-22 14:39   ` Anders Johansson
@ 2021-11-22 15:02     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2021-11-22 15:02 UTC (permalink / raw)
  To: Anders Johansson; +Cc: org-mode-email

Anders Johansson <mejlaandersj@gmail.com> writes:

> I had considered to implement some kind of cache in my code, but now I
> get this "for free"! I originally didn't use org-scan-tags but some
> custom and "simpler" code for scanning, but I am glad I refactored to
> use org-scan-tags, because now I get this speedup without a single
> code change in orgqda.

You can achieve even better speedup if you directly use
org-element-cache-map with :next-re/:fail-re parameters. If you are
matching against specific tags, those tags can be used to create a
regexp to locate match candidates very quickly.

Beware that org-element-cache-map does not work without
org-element-use-cache set to t (it is, by default).

Best,
Ihor


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-22 15:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-22  8:29 [BUG?] Cache: org-scan-tags behaves differently on inlinetasks with and without cache Anders Johansson
2021-11-22 11:35 ` Ihor Radchenko
2021-11-22 14:39   ` Anders Johansson
2021-11-22 15:02     ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.