Support completion boundaries when completing olp, tags, and agenda filter

* lisp/org-agenda.el (org-agenda-filter-completion-function):
* lisp/org-refile.el (org-olpath-completing-read):
* lisp/org-tags.el (org-tags-completion-function): Add support for
orderless/flex completion styles that require boundaries operation.
This commit is contained in:
Ihor Radchenko 2024-03-22 13:50:45 +03:00
parent 01cc01fc13
commit 5fa0f0c6fe
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 24 additions and 2 deletions

View File

@ -8194,10 +8194,12 @@ which see."
(confirm (lambda (x) (stringp x))) (confirm (lambda (x) (stringp x)))
(prefix "") (prefix "")
(operator "") (operator "")
table) table
begin)
(when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string) (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
(setq prefix (match-string 1 string) (setq prefix (match-string 1 string)
operator (match-string 2 string) operator (match-string 2 string)
begin (match-beginning 3)
string (match-string 3 string))) string (match-string 3 string)))
(cond (cond
((member operator '("+" "-" "" nil)) ((member operator '("+" "-" "" nil))
@ -8214,6 +8216,11 @@ which see."
(pcase flag (pcase flag
(`t (all-completions string table confirm)) (`t (all-completions string table confirm))
(`lambda (assoc string table)) ;exact match? (`lambda (assoc string table)) ;exact match?
(`(boundaries . ,suffix)
(let ((end (if (string-match "[-+<>=]" suffix)
(match-string 0 suffix)
(length suffix))))
`(boundaries ,(or begin 0) . ,end)))
(`nil (`nil
(pcase (try-completion string table confirm) (pcase (try-completion string table confirm)
((and completion (pred stringp)) ((and completion (pred stringp))

View File

@ -775,6 +775,14 @@ this function appends the default value from
(concat string (substring r 0 (match-end 0)) f) (concat string (substring r 0 (match-end 0)) f)
x))) x)))
(all-completions string thetable predicate)))) (all-completions string thetable predicate))))
((eq (car-safe action) 'boundaries)
;; See `completion-file-name-table'.
(let ((start (or (and (string-match "/" string)
(match-beginning 0 string))
(length string)))
(end (and (string-match "/" (cdr action))
(match-beginning 0 (cdr action)))))
`(boundaries ,start . ,end)))
;; Exact match? ;; Exact match?
((eq flag 'lambda) (assoc string thetable)))) ((eq flag 'lambda) (assoc string thetable))))
args))) args)))

View File

@ -12020,13 +12020,20 @@ function is passed as a collection function to `completing-read',
which see." which see."
(let ((completion-ignore-case nil) ;tags are case-sensitive (let ((completion-ignore-case nil) ;tags are case-sensitive
(confirm (lambda (x) (stringp (car x)))) (confirm (lambda (x) (stringp (car x))))
(prefix "")) (prefix "")
begin)
(when (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string) (when (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
(setq prefix (match-string 1 string)) (setq prefix (match-string 1 string))
(setq begin (match-beginning 2))
(setq string (match-string 2 string))) (setq string (match-string 2 string)))
(pcase flag (pcase flag
(`t (all-completions string org-last-tags-completion-table confirm)) (`t (all-completions string org-last-tags-completion-table confirm))
(`lambda (assoc string org-last-tags-completion-table)) ;exact match? (`lambda (assoc string org-last-tags-completion-table)) ;exact match?
(`(boundaries . ,suffix)
(let ((end (if (string-match "[-+:&,|]" suffix)
(match-string 0 suffix)
(length suffix))))
`(boundaries ,(or begin 0) . ,end)))
(`nil (`nil
(pcase (try-completion string org-last-tags-completion-table confirm) (pcase (try-completion string org-last-tags-completion-table confirm)
((and completion (pred stringp)) ((and completion (pred stringp))