diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 9ef160d16..4f7652ca3 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -72,6 +72,7 @@ (defvar crm-separator) (defvar org-end-time-was-given) (defvar org-keyword-properties) +(defvar org-use-fast-tag-selection) (defvar org-remember-default-headline) (defvar org-remember-templates) (defvar org-store-link-plist) @@ -1751,21 +1752,8 @@ Expansion occurs in a temporary Org mode buffer." (org-global-tags-completion-table (cond ((equal key "G") (org-agenda-files)) (file (list file)) - (t nil)))) - (org-add-colon-after-tag-completion t) - (ins (mapconcat - #'identity - (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 ":")) - (insert ins) - (unless (eq (char-after) ?:) (insert ":")) - (when (org-at-heading-p) (org-align-tags))))) + (t nil))))) + (org-input-tags))) ((or "C" "L") (let ((insert-fun (if (equal key "C") #'insert (lambda (s) (org-insert-link 0 s))))) diff --git a/lisp/org.el b/lisp/org.el index dd33028c6..6631d2a0a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11445,49 +11445,53 @@ in Lisp code use `org-set-tags' instead." 'region) (lambda () (when (org-invisible-p) (org-end-of-subtree nil t)))))) (t - (save-excursion - (org-back-to-heading) - (let* ((all-tags (org-get-tags)) - (table (setq org-last-tags-completion-table - (org--tag-add-to-alist - (and org-complete-tags-always-offer-all-agenda-tags - (org-global-tags-completion-table - (org-agenda-files))) - (or org-current-tag-alist (org-get-buffer-tags))))) - (current-tags - (cl-remove-if (lambda (tag) (get-text-property 0 'inherited tag)) - all-tags)) - (inherited-tags - (cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited tag)) - all-tags)) - (tags - (replace-regexp-in-string - ;; Ignore all forbidden characters in tags. - "[^[:alnum:]_@#%]+" ":" - (if (or (eq t org-use-fast-tag-selection) - (and org-use-fast-tag-selection - (delq nil (mapcar #'cdr table)))) - (org-fast-tag-selection - current-tags - inherited-tags - table - (and org-fast-tag-selection-include-todo org-todo-key-alist)) - (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))))) + (org-input-tags))) ;; `save-excursion' may not replace the point at the right ;; position. (when (and (save-excursion (skip-chars-backward "*") (bolp)) (looking-at-p " ")) (forward-char)))) +(defun org-input-tags () + "Test" + (save-excursion + (org-back-to-heading) + (let* ((all-tags (org-get-tags)) + (table (setq org-last-tags-completion-table + (org--tag-add-to-alist + (and org-complete-tags-always-offer-all-agenda-tags + (org-global-tags-completion-table + (org-agenda-files))) + (or org-current-tag-alist (org-get-buffer-tags))))) + (current-tags + (cl-remove-if (lambda (tag) (get-text-property 0 'inherited tag)) + all-tags)) + (inherited-tags + (cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited tag)) + all-tags)) + (tags + (replace-regexp-in-string + ;; Ignore all forbidden characters in tags. + "[^[:alnum:]_@#%]+" ":" + (if (or (eq t org-use-fast-tag-selection) + (and org-use-fast-tag-selection + (delq nil (mapcar #'cdr table)))) + (org-fast-tag-selection + current-tags + inherited-tags + table + (and org-fast-tag-selection-include-todo org-todo-key-alist)) + (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)))) + (defun org-align-tags (&optional all) "Align tags in current entry. When optional argument ALL is non-nil, align all tags in the