Fix: (org-ql-completing-read) Warn about empty headings

This commit is contained in:
Adam Porter 2023-09-26 20:48:59 -05:00
parent be20dc3d5b
commit 56e203110b
3 changed files with 49 additions and 39 deletions

View file

@ -549,6 +549,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
+ Query parser ignores leading whitespace (e.g. preventing errors while the user is typing a query into ~org-ql-find~). + Query parser ignores leading whitespace (e.g. preventing errors while the user is typing a query into ~org-ql-find~).
+ Use of ~org-ql-find~ with ~:query-prefix~ argument prevented selection of results. ([[https://github.com/alphapapa/org-ql/issues/351][#351]]. Thanks to [[https://github.com/danielfleischer][Daniel Fleischer]] for reporting.) + Use of ~org-ql-find~ with ~:query-prefix~ argument prevented selection of results. ([[https://github.com/alphapapa/org-ql/issues/351][#351]]. Thanks to [[https://github.com/danielfleischer][Daniel Fleischer]] for reporting.)
+ Handle narrowed buffers correctly in ~org-ql-find~. + Handle narrowed buffers correctly in ~org-ql-find~.
+ Warn about empty headings in ~org-ql-completing-read~ (the Org format allows a heading line to have no text, but it's useless for this purpose, and usually indicates unnoticed corruption).
** 0.7.1 ** 0.7.1

View file

@ -117,14 +117,20 @@ single predicate)."
;; optional arguments in a certain Org version, so in those versions, it will ;; optional arguments in a certain Org version, so in those versions, it will
;; return priority cookies and comment strings. ;; return priority cookies and comment strings.
(let ((heading (org-link-display-format (org-entry-get (point) "ITEM")))) (let ((heading (org-link-display-format (org-entry-get (point) "ITEM"))))
(when (gethash heading table) (if (string-empty-p heading)
;; Disambiguate heading (even adding the path isn't enough, because that could ;; A heading's string can be empty, but we can't use one because it
;; also be duplicated). ;; wouldn't be useful to the user; and if one is found, it's very
(if-let ((suffix (gethash heading disambiguations))) ;; likely to indicate an unnoticed mistake or corruption in the
(setf heading (format "%s <%s>" heading (cl-incf suffix))) ;; file: so display a warning and don't record it as a candidate.
(setf heading (format "%s <%s>" heading (puthash heading 2 disambiguations))))) (warn "Empty heading at %S in %S" (point) (buffer-name))
(let ((marker (point-marker))) (when (gethash heading table)
(puthash (propertize heading 'org-marker marker) marker table)))) ;; Disambiguate heading (even adding the path isn't enough, because that could
;; also be duplicated).
(if-let ((suffix (gethash heading disambiguations)))
(setf heading (format "%s <%s>" heading (cl-incf suffix)))
(setf heading (format "%s <%s>" heading (puthash heading 2 disambiguations)))))
(let ((marker (point-marker)))
(puthash (propertize heading 'org-marker marker) marker table)))))
(path (marker) (path (marker)
(org-with-point-at marker (org-with-point-at marker
(let* ((path (thread-first (org-get-outline-path nil t) (let* ((path (thread-first (org-get-outline-path nil t)

View file

@ -1038,6 +1038,9 @@ File: README.info, Node: 072-pre, Next: 071, Up: Changelog
(https://github.com/alphapapa/org-ql/issues/351). Thanks to Daniel (https://github.com/alphapapa/org-ql/issues/351). Thanks to Daniel
Fleischer (https://github.com/danielfleischer) for reporting.) Fleischer (https://github.com/danielfleischer) for reporting.)
• Handle narrowed buffers correctly in org-ql-find. • Handle narrowed buffers correctly in org-ql-find.
• Warn about empty headings in org-ql-completing-read (the Org
format allows a heading line to have no text, but its useless for
this purpose, and usually indicates unnoticed corruption).
 
File: README.info, Node: 071, Next: 07, Prev: 072-pre, Up: Changelog File: README.info, Node: 071, Next: 07, Prev: 072-pre, Up: Changelog
@ -1779,37 +1782,37 @@ Node: Links37257
Node: Tips37944 Node: Tips37944
Node: Changelog38268 Node: Changelog38268
Node: 072-pre39053 Node: 072-pre39053
Node: 07139760 Node: 07139972
Node: 0740573 Node: 0740785
Node: 06343497 Node: 06343709
Node: 06244028 Node: 06244240
Node: 06144333 Node: 06144545
Node: 0644901 Node: 0645113
Node: 05247955 Node: 05248167
Node: 05148255 Node: 05148467
Node: 0548678 Node: 0548890
Node: 04950209 Node: 04950421
Node: 04850491 Node: 04850703
Node: 04750840 Node: 04751052
Node: 04651249 Node: 04651461
Node: 04551657 Node: 04551869
Node: 04452018 Node: 04452230
Node: 04352377 Node: 04352589
Node: 04252580 Node: 04252792
Node: 04152741 Node: 04152953
Node: 0452988 Node: 0453200
Node: 03257089 Node: 03257301
Node: 03157492 Node: 03157704
Node: 0357689 Node: 0357901
Node: 02360989 Node: 02361201
Node: 02261223 Node: 02261435
Node: 02161503 Node: 02161715
Node: 0261708 Node: 0261920
Node: 0165786 Node: 0165998
Node: Notes65887 Node: Notes66099
Node: Comparison with Org Agenda searches66049 Node: Comparison with Org Agenda searches66261
Node: org-sidebar66938 Node: org-sidebar67150
Node: License67217 Node: License67429
 
End Tag Table End Tag Table