emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] org-complex-heading-regexp should consider COMMENT keywords [9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)]
@ 2022-05-05 10:27 Ignacio Casso
  2022-05-06 10:52 ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Ignacio Casso @ 2022-05-05 10:27 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode


This topic was brought up again in
https://lists.gnu.org/archive/html/emacs-orgmode/2022-05/msg00058.html,
I continue the discussion here:

>> Still, I think it might be interesting to compare this topic with the
>> one I linked in my reply,
>> https://lists.gnu.org/archive/html/emacs-orgmode/2022-03/msg00293.html,
>> which it's basically the same bug report but about COMMENT keywords. In
>> that regard, I have tested that org-capture targets do work regardless
>> of statistcs cookies. Could not something equivalent be done so that
>> they also work regardless of COMMENT keywords? Feel free to reply in
>> that other thread if you feel this is off-topic here.
>
>> This bug is related with the issue I reported in
>> https://lists.gnu.org/archive/html/emacs-orgmode/2022-03/msg00293.html. The
>> problem is that `org-heading-components' uses
>> `org-complex-heading-regexp', which does not consider statistics
>> cookies, and neither COMMENT keywords as I reported. I think it should be
>> updated to consider both.
>
> Note that org-complex-heading-regexp-format does consider statistics
> cookies, but only at the beginning/end of the headline title.
> Unfortunately, it is impossible to provide generic printf format to
> match a headline title with arbitrary statistics cookies inserted in the
> middle of it.
>

Could not something equivalent be done for COMMENT keywords and
optionally match them at the beginning of the headline in
`org-complex-heading-regexp-format'? Something like this:

  (setq org-complex-heading-regexp-format
        (concat "^\\(\\*+\\)"
  	      "\\(?: +" org-todo-regexp "\\)?"
  	      "\\(?: +\\(\\[#.\\]\\)\\)?"
  	      "\\(?: +"
+             ;; Headline might be commented
+             "\\(COMMENT \\)?
  	      ;; Stats cookies can be stuck to body.
  	      "\\(?:\\[[0-9%%/]+\\] *\\)*"
  	      "\\(%s\\)"
  	      "\\(?: *\\[[0-9%%/]+\\]\\)*"
  	      "\\)"
  	      "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?"
  	      "[ \t]*$"))

This would fix the problem I really cared about: being able to use a
headline as capture target regardless of whether it is commented or
not. Getting the headline text was never important to me, so I don't
really care that much about `org-complex-heading-regexp'.

> As for your other report, it is a hard one - org-complex-heading-regexp
> is hard to modify because we guarantee certain match groups and its hard
> to fit COMMENT in there without breaking backward-compatibility.
>
> I generally dislike the idea of the available plethora of analytic
> regexps with numbered match groups.

Do you mean that there is no way to specify an optional string in a
regular expression without wrapping it in a parenthesized group, which
would break the match group numbering backwards compatibility? I'm not
that familiar with regular expressions, but if that's the case I
completely agree with your last statement.

--Ignacio


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [BUG] org-complex-heading-regexp should consider COMMENT keywords [9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)]
@ 2022-03-22 11:41 Ignacio Casso
  0 siblings, 0 replies; 10+ messages in thread
From: Ignacio Casso @ 2022-03-22 11:41 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I think `org-complex-heading-regexp' and
`org-complex-heading-regexp-format' should consider COMMENT keywords, as
they do with TODO keywords, priorities, and tags.


Firstly, with things as they are, different methods for accessing the
headline text are inconsistent. For example, for the headline below,
(org-entry-get (point) "ITEM"), which uses `org-complex-heading-regexp',
returns "COMMENT My headline", while (org-element-property :title
(org-element-context)), which doesn't, returns "My headline".

*** TODO [#A] COMMENT My headline   :my_tag:


But more importantly for me, this is a problem in particular with
org-capture, where I would like capture targets to be found regardless
of whether they are commented or not. But right now commented headlines
are only found if the COMMENT keyword also appears in the capture
template, and in that case if the headlines are later uncommented they
are no longer found. You can copy the entry below into an org file and
play around with it to reproduce this described behavior.

* COMMENT My Target
  #+begin_src emacs-lisp
    (let ((org-capture-templates
           `(("d" "My capture template" entry
              (file+headline ,buffer-file-name "My target")
              "* My content"
              :immediate-finish t))))
      (org-capture nil "d"))
  #+end_src

The cause of this is the use of `org-complex-heading-regexp-format' in
`org-capture-set-target-location'.

This is the bug I originally wanted to report, but after
exploring the cause I thought that the problem was really in
`org-complex-heading-regexp' and not org-capture's code.

What do you think? Do you know of any other uses of those variables and
how considering COMMENT keywords or not affects them?

If you agree I can send a patch that changes the default value of those
regexp variables. Otherwise, I can send a patch that just modifies the
code of `org-capture-set-target-location' to fix this only for the
org-capture use case.

Regards,

Ignacio


Emacs  : GNU Emacs 29.0.50 (build 13, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2022-03-21
Package: Org mode version 9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)


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

end of thread, other threads:[~2022-05-22  8:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-05 10:27 [BUG] org-complex-heading-regexp should consider COMMENT keywords [9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)] Ignacio Casso
2022-05-06 10:52 ` Ihor Radchenko
2022-05-06 12:14   ` Ignacio Casso
2022-05-07  5:27     ` Ihor Radchenko
2022-05-07 16:54       ` Ignacio Casso
2022-05-08 10:23         ` Ihor Radchenko
2022-05-08 11:15           ` Ignacio Casso
2022-05-08 11:51             ` Ihor Radchenko
2022-05-22  8:52               ` Bastien Guerry
  -- strict thread matches above, loose matches on Subject: below --
2022-03-22 11:41 Ignacio Casso

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).