From 77fdbf8552a0a2ff451bf9071f6646ac016cb262 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Sat, 1 Jul 2023 18:29:02 +0800 Subject: [PATCH] org: Improve the tags fast selection performance * lisp/org.el (org-fast-tag-selection): Filter out only maximum number limited tags has fast selection bound when `org-use-fast-tag-selection' is 'auto and tags has fast select bound keys. * lisp/org.el (org-fast-tag-selection-maximum-tags): Add new custom option to set maximum tags number for fast tag selection. * doc/org-manual.org (org-fast-tag-selection-maximum-tags): Add new custom option document. * etc/ORG-NEWS: declare this new custom option. --- doc/org-manual.org | 10 ++++++++++ etc/ORG-NEWS | 11 +++++++++++ lisp/org.el | 14 +++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 3a49917d7..30fcf32dc 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -5073,6 +5073,16 @@ effect: start selection with {{{kbd(C-c C-c C-c)}}} instead of the special window is not even shown for single-key tag selection, it comes up only when you press an extra {{{kbd(C-c)}}}. +#+vindex: org-fast-tag-selection-maximum-tags +Limit the tags table when you have many tags. You can set the maximum +tags number for fast tag selection interface. When the variable +~org-use-fast-tag-selection~ is ~auto~ and +~org-fast-tag-selection-maximum-tags~ variable value number is smaller +than single key bound tags number, the fast tag selection will only +show single key bound tags, in contrary, will show the maximum number +limited tags. If ~org-use-fast-tag-selection~ is other values, will +show full tags. + ** Tag Hierarchy :PROPERTIES: :DESCRIPTION: Create a hierarchy of tags. diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index cb4bc632b..dfabbfbed 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -322,6 +322,17 @@ special repeaters ~++~ and ~.+~ are skipped. A capture template can target ~(here)~ which is the equivalent of invoking a capture template with a zero prefix. +*** Add new option ~org-fast-tag-selection-maximum-tags~ to limit fast tag selection interface displayed tags + +Limit the tags table when you have many tags. You can set the maximum +tags number for fast tag selection interface. When the variable +~org-use-fast-tag-selection~ is ~auto~ and +~org-fast-tag-selection-maximum-tags~ variable value number is smaller +than single key bound tags number, the fast tag selection will only +show single key bound tags, in contrary, will show the maximum number +limited tags. If ~org-use-fast-tag-selection~ is other values, will +show full tags. + ** Miscellaneous *** =org-crypt.el= now applies initial visibility settings to decrypted entries diff --git a/lisp/org.el b/lisp/org.el index fdb920864..f077cde12 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2775,6 +2775,12 @@ displaying the tags menu is not even shown, until you press `C-c' again." (const :tag "Yes" t) (const :tag "Expert" expert))) +(defcustom org-fast-tag-selection-maximum-tags 26 + "Set the maximum tags number for fast tag selection." + :group 'org-tags + :type 'number + :safe #'numberp) + (defvar org-fast-tag-selection-include-todo nil "Non-nil means fast tags selection interface will also offer TODO states. This is an undocumented feature, you should not rely on it.") @@ -11929,7 +11935,13 @@ these have keys assigned to them. If the keys are nil, a-z are automatically assigned. Returns the new tags string, or nil to not change the current settings." (let* (;; Combined alist of all the tags and todo keywords. - (tag-alist (append tag-table todo-table)) + (tag-alist (let* ((tags-table (append tag-table todo-table)) + (binding-tags (seq-filter 'cdr tags-table))) + (cl-case org-use-fast-tag-selection + (auto (if (length> binding-tags org-fast-tag-selection-maximum-tags) + binding-tags + (seq-take tags-table org-fast-tag-selection-maximum-tags))) + (t tags-table)))) ;; Max width occupied by a single tag record in the completion buffer. (field-width (+ 3 ; keep space for "[c]" binding. -- 2.39.2 (Apple Git-143)