* [PATCH] Add NO-STATS switch to org-get-heading
@ 2020-03-13 15:11 Brice Waegeneire
2020-03-13 17:22 ` Nicolas Goaziou
2020-03-13 18:50 ` Adam Porter
0 siblings, 2 replies; 6+ messages in thread
From: Brice Waegeneire @ 2020-03-13 15:11 UTC (permalink / raw)
To: emacs-orgmode
* lisp/org-element.el (org-element-context): Handle headlines only
containing a statistics cookie.
* lisp/org.el (test-org/get-heading): Add regex capture group 6 for
statistics cookie.
(org-get-heading): Add NO-STATS argument, if
non-nil, will not return the statistics cookie.
* testing/lisp/test-org.el (test-org/get-heading): Add 3 tests using the
NO-STATS argument.
---
lisp/org-element.el | 4 ++--
lisp/org.el | 13 +++++++++----
testing/lisp/test-org.el | 13 +++++++++++++
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 798c540e9..c1798e07a 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -5906,9 +5906,9 @@ Providing it allows for quicker computation."
(let ((case-fold-search nil))
(goto-char (org-element-property :begin element))
(looking-at org-complex-heading-regexp)
- (let ((end (match-end 4)))
+ (let ((end (or (match-end 6) (match-end 4))))
(if (not end) (throw 'objects-forbidden element)
- (goto-char (match-beginning 4))
+ (goto-char (or (match-beginning 4) (match-beginning 6)))
(when (looking-at org-comment-string)
(goto-char (match-end 0)))
(if (>= (point) end) (throw 'objects-forbidden element)
diff --git a/lisp/org.el b/lisp/org.el
index 31133c554..b6fc6ad26 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4011,6 +4011,7 @@ group 2: The TODO keyword, maybe
group 3: Priority cookie
group 4: True headline
group 5: Tags
+group 6: Statistics cookie
Since TODO keywords are case-sensitive, `case-fold-search' is
expected to be bound to nil when matching against this regexp.")
@@ -4328,7 +4329,8 @@ related expressions."
"\\(?: +" org-todo-regexp "\\)?"
"\\(?: +\\(\\[#.\\]\\)\\)?"
"\\(?: +\\(.*?\\)\\)??"
- "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?"
+ "\\(?: +\\(?6:\\[[0-9%%/]+\\]\\)\\)?"
+ "\\(?:[ \t]+\\(?5::[[:alnum:]_@#%:]+:\\)\\)?"
"[ \t]*$")
org-complex-heading-regexp-format
(concat "^\\(\\*+\\)"
@@ -6897,12 +6899,14 @@ So this will delete or add empty lines."
(insert (make-string n ?\n))
(move-to-column column)))
-(defun org-get-heading (&optional no-tags no-todo no-priority no-comment)
+(defun org-get-heading (&optional no-tags no-todo no-priority
+ no-comment no-stats)
"Return the heading of the current entry, without the stars.
When NO-TAGS is non-nil, don't include tags.
When NO-TODO is non-nil, don't include TODO keywords.
When NO-PRIORITY is non-nil, don't include priority cookie.
When NO-COMMENT is non-nil, don't include COMMENT string.
+When NO-STATS is non-nil, don't include statistics cookie.
Return nil before first heading."
(unless (org-before-first-heading-p)
(save-excursion
@@ -6919,9 +6923,10 @@ Return nil before first heading."
(format "\\`%s[ \t]+" org-comment-string))
"" h))
(h h)))
- (tags (and (not no-tags) (match-string 5))))
+ (tags (and (not no-tags) (match-string 5)))
+ (stats (and (not no-stats) (match-string 6))))
(mapconcat #'identity
- (delq nil (list todo priority headline tags))
+ (delq nil (list todo priority headline stats tags))
" "))))))
(defun org-heading-components ()
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index dc4a6a59f..f98918dae 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1887,6 +1887,19 @@
(equal "TODO [#A] H"
(org-test-with-temp-text "* TODO [#A] COMMENT H"
(org-get-heading nil nil nil t))))
+ ;; With NO-STATS, ignore statistics cookie.
+ (should
+ (equal "H"
+ (org-test-with-temp-text "* H [1/3]"
+ (org-get-heading nil nil nil nil t))))
+ (should
+ (equal "H"
+ (org-test-with-temp-text "* H"
+ (org-get-heading nil nil nil nil t))))
+ (should
+ (equal "TODO [#A] H"
+ (org-test-with-temp-text "* TODO [#A] H [33%]"
+ (org-get-heading nil nil nil nil t))))
;; On an empty headline, return value is consistent.
(should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
(should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
--
2.25.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Add NO-STATS switch to org-get-heading
2020-03-13 15:11 [PATCH] Add NO-STATS switch to org-get-heading Brice Waegeneire
@ 2020-03-13 17:22 ` Nicolas Goaziou
2020-03-13 17:37 ` Nicolas Goaziou
2020-03-13 17:41 ` Brice Waegeneire
2020-03-13 18:50 ` Adam Porter
1 sibling, 2 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2020-03-13 17:22 UTC (permalink / raw)
To: Brice Waegeneire; +Cc: emacs-orgmode
Hello,
Brice Waegeneire <brice@waegenei.re> writes:
> * lisp/org-element.el (org-element-context): Handle headlines only
> containing a statistics cookie.
> * lisp/org.el (test-org/get-heading): Add regex capture group 6 for
> statistics cookie.
> (org-get-heading): Add NO-STATS argument, if
> non-nil, will not return the statistics cookie.
> * testing/lisp/test-org.el (test-org/get-heading): Add 3 tests using the
> NO-STATS argument.
This assumes statistics cookie is always located at the end of the
title, before the tags. This is not required by the syntax.
Syntax can evolve, but it could introduce many backward
incompatibilities, so it must be discussed first.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add NO-STATS switch to org-get-heading
2020-03-13 17:22 ` Nicolas Goaziou
@ 2020-03-13 17:37 ` Nicolas Goaziou
2020-03-13 17:41 ` Brice Waegeneire
1 sibling, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2020-03-13 17:37 UTC (permalink / raw)
To: Brice Waegeneire; +Cc: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> This assumes statistics cookie is always located at the end of the
> title, before the tags. This is not required by the syntax.
>
> Syntax can evolve, but it could introduce many backward
> incompatibilities, so it must be discussed first.
Also, note that statistics cookies are not tied to headlines, unlike
tags or TODO keywords. They can be located almost anywhere in the
document (e.g., in plain lists). So, it seems strange to add it to
`org-get-heading'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add NO-STATS switch to org-get-heading
2020-03-13 17:22 ` Nicolas Goaziou
2020-03-13 17:37 ` Nicolas Goaziou
@ 2020-03-13 17:41 ` Brice Waegeneire
1 sibling, 0 replies; 6+ messages in thread
From: Brice Waegeneire @ 2020-03-13 17:41 UTC (permalink / raw)
To: Brice Waegeneire; +Cc: emacs-orgmode
Hello Nicolas,
On 2020-03-13 17:22, Nicolas Goaziou wrote:
>> * lisp/org-element.el (org-element-context): Handle headlines only
>> containing a statistics cookie.
>> * lisp/org.el (test-org/get-heading): Add regex capture group 6 for
>> statistics cookie.
>> (org-get-heading): Add NO-STATS argument, if
>> non-nil, will not return the statistics cookie.
>> * testing/lisp/test-org.el (test-org/get-heading): Add 3 tests using
>> the
>> NO-STATS argument.
>
> This assumes statistics cookie is always located at the end of the
> title, before the tags. This is not required by the syntax.
>
> Syntax can evolve, but it could introduce many backward
> incompatibilities, so it must be discussed first.
I wasn't sure about this. I don't remember ever seeing somebody putting
the
statistics cookie before the title but org-complex-heading-regexp-format
does support two position for the statistics cookie. Would adding
support
for the two locations to this patch make the review process faster?
I was just looking for a way to get a heading title without any
metadata.
Cheers.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add NO-STATS switch to org-get-heading
2020-03-13 15:11 [PATCH] Add NO-STATS switch to org-get-heading Brice Waegeneire
2020-03-13 17:22 ` Nicolas Goaziou
@ 2020-03-13 18:50 ` Adam Porter
2020-03-15 0:24 ` stardiviner
1 sibling, 1 reply; 6+ messages in thread
From: Adam Porter @ 2020-03-13 18:50 UTC (permalink / raw)
To: emacs-orgmode
Please don't add more arguments to org-get-heading. It used to have 2,
then it had 4, and now you want to add a 5th. Every time the function's
signature changes, it breaks code in third-party packages and user code
in random places, which requires the addition of messy compatibility
code and intermediate functions that do nothing but wrap org-get-heading
with a certain number of arguments.
It would be much preferable to make a new function that uses keyword
arguments so the addition of more arguments won't affect existing code.
Maybe it could be called org-entry-heading.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add NO-STATS switch to org-get-heading
2020-03-13 18:50 ` Adam Porter
@ 2020-03-15 0:24 ` stardiviner
0 siblings, 0 replies; 6+ messages in thread
From: stardiviner @ 2020-03-15 0:24 UTC (permalink / raw)
To: Adam Porter; +Cc: emacs-orgmode
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Adam Porter <adam@alphapapa.net> writes:
> Please don't add more arguments to org-get-heading. It used to have 2,
> then it had 4, and now you want to add a 5th. Every time the function's
> signature changes, it breaks code in third-party packages and user code
> in random places, which requires the addition of messy compatibility
> code and intermediate functions that do nothing but wrap org-get-heading
> with a certain number of arguments.
>
> It would be much preferable to make a new function that uses keyword
> arguments so the addition of more arguments won't affect existing code.
> Maybe it could be called org-entry-heading.
I agree, this statistic cookie is not very necessary for getting headline.
This totally can be done in tools by author self.
- --
[ stardiviner ]
I try to make every word tell the meaning what I want to express.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
-----BEGIN PGP SIGNATURE-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5tdckUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsPq7wgAtr+HkiPHuTmjGsrZaYJkAcTVjwHH
cg+drGKhZmGhADYeR5Sb2fmf8Vghn6DavhxjQrryIAFw5lic9n0DuqgzFe0TP/+Z
SCd8sixjSGqlmjouTcqXgo8QXqPbTJNQyYUwqLYwawyh44LW4AvMFo5UCihr+Mg6
PCDilLMlAV6w0ondqOwaMgbSooU1oZ11jVO5bacgJZzqTeLThMtn0+Cv5b3Lx0lH
j5jnWnJ2HSqYyI96xktWrDU+Wyy2mhKKrHrALl8HNiih3QemSuEJonYt/KsCA3JJ
SzATd0GNGGdg5v5z7k206yOgC+O6ViaeNb070i9I4wRdPDp0FWqHguCMIQ==
=twGf
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-03-15 0:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-13 15:11 [PATCH] Add NO-STATS switch to org-get-heading Brice Waegeneire
2020-03-13 17:22 ` Nicolas Goaziou
2020-03-13 17:37 ` Nicolas Goaziou
2020-03-13 17:41 ` Brice Waegeneire
2020-03-13 18:50 ` Adam Porter
2020-03-15 0:24 ` stardiviner
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).