forked from mirrors/org-mode
org: Use crm for completing tags
* lisp/org-capture.el (org-capture-fill-template): Changed to use completing-read-multiple. * lisp/org.el (org-set-tags-command): Changed to use completing-read-multiple. (org-change-tag-in-region): Changed to use a simple completion table. * testing/lisp/test-org.el (test-org/set-tags-command): Fixed tests. Change various places which use `completing-read' to read tags using a custom completion function to instead use `completing-read-multiple' with a completion table instead. This makes tab completion play better with alternative completion frameworks such as vertico, selectrum, etc. `org-change-tag-in-region' only reads a single tag, so it is changed to use a completion table with `completing-read'. This also makes it play better with alternative completion frameworks. Note that there is still one use for `org-tags-completion-function', which is for completing tag matches. Completing tag matches is different from completing lists of tags since the separators (+, -, etc) have semantic meaning. This commit does not address that use case.
This commit is contained in:
parent
fdb98a436b
commit
622f9fa76c
|
@ -409,6 +409,12 @@ The function does not allow for a third optional parameter anymore.
|
|||
If a babel src block produces a raw LaTeX environment, it will now be
|
||||
recognised as a result, and so replaced when re-evaluated.
|
||||
|
||||
*** Tag completion now uses =completing-read-multiple=
|
||||
|
||||
Tag completion now uses =completing-read-multiple= with a simple
|
||||
completion table, which should allow better interoperability with
|
||||
custom completion functions.
|
||||
|
||||
* Version 9.4
|
||||
** Incompatible changes
|
||||
*** Possibly broken internal file links: please check and fix
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
(declare-function org-table-goto-line "org-table" (N))
|
||||
|
||||
(defvar dired-buffers)
|
||||
(defvar crm-separator)
|
||||
(defvar org-end-time-was-given)
|
||||
(defvar org-keyword-properties)
|
||||
(defvar org-remember-default-headline)
|
||||
|
@ -1739,12 +1740,11 @@ The template may still contain \"%?\" for cursor positioning."
|
|||
(org-add-colon-after-tag-completion t)
|
||||
(ins (mapconcat
|
||||
#'identity
|
||||
(org-split-string
|
||||
(completing-read
|
||||
(if prompt (concat prompt ": ") "Tags: ")
|
||||
'org-tags-completion-function nil nil nil
|
||||
'org-tags-history)
|
||||
"[^[:alnum:]_@#%]+")
|
||||
(let ((crm-separator "[ \t]*:[ \t]*"))
|
||||
(completing-read-multiple
|
||||
(if prompt (concat prompt ": ") "Tags: ")
|
||||
org-last-tags-completion-table nil nil nil
|
||||
'org-tags-history))
|
||||
":")))
|
||||
(when (org-string-nw-p ins)
|
||||
(unless (eq (char-before) ?:) (insert ":"))
|
||||
|
|
19
lisp/org.el
19
lisp/org.el
|
@ -201,6 +201,8 @@ Stars are put in group 1 and the trimmed body in group 2.")
|
|||
;; load languages based on value of `org-babel-load-languages'
|
||||
(defvar org-babel-load-languages)
|
||||
|
||||
(defvar crm-separator) ; dynamically scoped param
|
||||
|
||||
;;;###autoload
|
||||
(defun org-babel-do-load-languages (sym value)
|
||||
"Load the languages defined in `org-babel-load-languages'."
|
||||
|
@ -12054,12 +12056,15 @@ in Lisp code use `org-set-tags' instead."
|
|||
inherited-tags
|
||||
table
|
||||
(and org-fast-tag-selection-include-todo org-todo-key-alist))
|
||||
(let ((org-add-colon-after-tag-completion (< 1 (length table))))
|
||||
(org-trim (completing-read
|
||||
"Tags: "
|
||||
#'org-tags-completion-function
|
||||
nil nil (org-make-tag-string current-tags)
|
||||
'org-tags-history)))))))
|
||||
(let ((org-add-colon-after-tag-completion (< 1 (length table)))
|
||||
(crm-separator "[ \t]*:[ \t]*"))
|
||||
(mapconcat #'identity
|
||||
(completing-read-multiple
|
||||
"Tags: "
|
||||
org-last-tags-completion-table
|
||||
nil nil (org-make-tag-string current-tags)
|
||||
'org-tags-history)
|
||||
":"))))))
|
||||
(org-set-tags tags)))))
|
||||
;; `save-excursion' may not replace the point at the right
|
||||
;; position.
|
||||
|
@ -12139,7 +12144,7 @@ This works in the agenda, and also in an Org buffer."
|
|||
(org-global-tags-completion-table))
|
||||
(org-global-tags-completion-table))))
|
||||
(completing-read
|
||||
"Tag: " 'org-tags-completion-function nil nil nil
|
||||
"Tag: " org-last-tags-completion-table nil nil nil
|
||||
'org-tags-history))
|
||||
(progn
|
||||
(message "[s]et or [r]emove? ")
|
||||
|
|
|
@ -6969,8 +6969,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal "* H1 :foo:"
|
||||
(org-test-with-temp-text "* H1"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
@ -6979,8 +6979,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal "* H1 :foo:\nContents"
|
||||
(org-test-with-temp-text "* H1\n<point>Contents"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
@ -6988,30 +6988,20 @@ Paragraph<point>"
|
|||
(should-not
|
||||
(equal "* H1 :foo:\nContents2"
|
||||
(org-test-with-temp-text "* H1\n<point>Contents2"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
(org-at-heading-p))))
|
||||
;; Strip all forbidden characters from user-entered tags.
|
||||
(should
|
||||
(equal "* H1 :foo:"
|
||||
(org-test-with-temp-text "* H1"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ": foo *:")))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
(buffer-string))))
|
||||
;; When a region is active and
|
||||
;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
|
||||
;; same value in all headlines in region.
|
||||
(should
|
||||
(equal "* H1 :foo:\nContents\n* H2 :foo:"
|
||||
(org-test-with-temp-text "* H1\nContents\n* H2"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-loop-over-headlines-in-active-region t)
|
||||
(org-tags-column 1))
|
||||
|
@ -7023,8 +7013,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal "* H1\nContents\n* H2 :foo:"
|
||||
(org-test-with-temp-text "* H1\nContents\n* H2"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-loop-over-headlines-in-active-region nil)
|
||||
(org-tags-column 1))
|
||||
|
@ -7043,8 +7033,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal ":foo:"
|
||||
(org-test-with-temp-text "* <point>"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
@ -7053,8 +7043,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal "* H1 :foo:"
|
||||
(org-test-with-temp-text "* H1"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
@ -7063,8 +7053,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal "* H1 :foo:"
|
||||
(org-test-with-temp-text "*<point>* H1"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
@ -7073,8 +7063,8 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal " b :foo:"
|
||||
(org-test-with-temp-text "* a<point> b"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(lambda (&rest args) ":foo:")))
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (&rest args) '("foo"))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
@ -7083,9 +7073,9 @@ Paragraph<point>"
|
|||
(should
|
||||
(equal "b :foo:"
|
||||
(org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
|
||||
(cl-letf (((symbol-function 'completing-read)
|
||||
(cl-letf (((symbol-function 'completing-read-multiple)
|
||||
(lambda (prompt coll &optional pred req initial &rest args)
|
||||
initial)))
|
||||
(list initial))))
|
||||
(let ((org-use-fast-tag-selection nil)
|
||||
(org-tags-column 1))
|
||||
(org-set-tags-command)))
|
||||
|
|
Loading…
Reference in New Issue