Re: [PATCH v6] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2024-01-12 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> Thanks for updating, this patch looks great to me.

Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=dea7780d6

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH v6] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2024-01-11 Thread Christopher M. Miles

Thanks for updating, this patch looks great to me.

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


[PATCH v6] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2024-01-09 Thread Ihor Radchenko
I have incorporated my suggestions into an updated patch.

Note that I dropped the condition that new customization only works for
org-use-fast-tag-selection = 'auto.

Please let me know if anything you wanted to see in this patch is
missing.

>From 79fee381dc5ecbaed5bfe3ba66b11bb2a02aa97f Mon Sep 17 00:00:00 2001
Message-ID: <79fee381dc5ecbaed5bfe3ba66b11bb2a02aa97f.1704809509.git.yanta...@posteo.net>
From: stardiviner 
Date: Sat, 1 Jul 2023 18:29:02 +0800
Subject: [PATCH v6] org-fast-tag-selection: Limit the number of displayed tags

* lisp/org.el (org-fast-tag-selection): Do not print tags without
explicit bindings and tags outside groups when the number of displayed
tags exceeds new customization.
* lisp/org.el (org-fast-tag-selection-maximum-tags): Add new custom
option to set maximum tags number for fast tag selection.
(org--fast-tag-selection-keys): New internal variable holding keys
available for auto-assigning tag bindings.
* doc/org-manual.org (org-fast-tag-selection-maximum-tags): Add new
custom option documentation.
* etc/ORG-NEWS: Declare this new custom option.

Co-Authored-by: Ihor Radchenko 
Link: https://list.orgmode.org/orgmode/CAL1eYuK7GUx_=47e8+n5jh+zjndexy+cdmujpjjhnmcmivv...@mail.gmail.com/
---
 doc/org-manual.org |  5 
 etc/ORG-NEWS   |  5 
 lisp/org.el| 73 +++---
 3 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index acc6d07ff..bb4b6e625 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -5090,6 +5090,11 @@ ** Setting Tags
 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
+The number of tags displayed in the fast tag selection interface is
+limited by ~org-fast-tag-selection-maximum-tags~ to avoid running out
+of keyboard keys.  You can customize this variable.
+
 ** Tag Hierarchy
 :PROPERTIES:
 :DESCRIPTION: Create a hierarchy of tags.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b808357d8..847ddf614 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -371,6 +371,11 @@ The change is breaking when ~org-use-property-inheritance~ is set to ~t~.
 
 The =TEST= parameter is better served by Emacs debugging tools.
 ** New and changed options
+*** New option ~org-fast-tag-selection-maximum-tags~
+
+You can now limit the total number of tags displayed in the fast tag
+selection interface.  Useful in buffers with huge number of tags.
+
 *** New variable ~org-clock-out-removed-last-clock~
 
 The variable is intended to be used by ~org-clock-out-hook~.  It is a
diff --git a/lisp/org.el b/lisp/org.el
index 57379c26a..3d3099c48 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -2790,6 +2790,25 @@ (defcustom org-fast-tag-selection-single-key nil
 	  (const :tag "Yes" t)
 	  (const :tag "Expert" expert)))
 
+(defvar org--fast-tag-selection-keys
+  (string-to-list "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~")
+  "List of chars to be used as bindings by `org-fast-tag-selection'.")
+
+(defcustom org-fast-tag-selection-maximum-tags (length org--fast-tag-selection-keys)
+  "Set the maximum tags number for fast tag selection.
+This variable only affects tags without explicit key bindings outside
+tag groups.  All the tags with user bindings and all the tags
+corresponding to tag groups are always displayed.
+
+When the number of tags with bindings + tags inside tag groups is
+smaller than `org-fast-tag-selection-maximum-tags', tags without
+explicit bindings will be assigned a binding and displayed up to the
+limit."
+  :package-version '(Org . "9.7")
+  :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.")
@@ -11983,9 +12002,8 @@ (defun org-fast-tag-selection (current-tags inherited-tags tag-table  t
 	 (inherited-face 'org-done)
 	 (current-face 'org-todo)
  ;; Characters available for auto-assignment.
- (tag-binding-char-list
-  (eval-when-compile
-(string-to-list "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~")))
+ (tag-binding-char-list org--fast-tag-selection-keys)
+ (tag-binding-chars-left org-fast-tag-selection-maximum-tags)
  field-number ; current tag column in the completion buffer.
  tag-binding-spec ; Alist element.
  current-tag current-tag-char auto-tag-char
@@ -11995,6 +12013,22 @@ (defun org-fast-tag-selection (current-tags inherited-tags tag-table  t
 	 (exit-after-next org-fast-tag-selection-single-key)
 	 (done-keywords org-done-keywords)
 	 groups ingroup intaggroup)
+;; Calculate the number of tags with explicit user bindings + tags in groups.
+;; These tags will be displayed unconditionally.  Other tags will
+;; be displayed only when there 

Re: [PATCH v5] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-07-01 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> Ok, I update and re-generated the patch, also add new document and Org NEWS 
> entries.

Thanks!
See my comments below.

> * 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.

Why only for 'auto?

> * doc/org-manual.org (org-fast-tag-selection-maximum-tags): Add new
> custom option document.

*documentation.

> --- 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

#+vindex entry will not be visible in the rendered manual. So, the first
 sentence of the paragraph reads awkwardly.

Also, please use double space between sentences. It is the convention
for Org manual, docstrings, and commit messages. See
doc/Documentation_Standards.org

> +(defcustom org-fast-tag-selection-maximum-tags 26
> +  "Set the maximum tags number for fast tag selection."
> +  :group 'org-tags
> +  :type 'number
> +  :safe #'numberp)

Why 26?
We use a-zA-Z{|}~

;; Characters available for auto-assignment.
 (tag-binding-char-list
  (eval-when-compile
(string-to-list 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~")))

Also, please add :package-version keyword in the defcustom.

>(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

May you please instead:

1. Store the total number of bound tags, but using a bit more complex
   filter (`(:startgroup "foo")', `(:endgroup "bar")' are also valid alist
   members, but do not correspond to tag bindings). See `(pcase
   tag-binding-spec ...)'
2. Store the total number of tag in tag groups. See `ingroup'.
3. Add these two numbers and compare them with
   `org-fast-tag-selection-maximum-tags', calculating how many extra
   tags can be displayed.
4. Do not filter `tag-alist', but instead plug a code into `(while (setq
   tag-binding-spec (pop tag-alist)) ...)', counting how many tags are in
   There, in `;; Insert the tag.', only insert the tag when (1) tag has
   binding - (cdr tag-binding-spec); (2) tag is in a group - ingroup;
   (3) we still have space for extra tags, according to (3), then also
   decrease the leftover tag count.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[PATCH v5] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-07-01 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> I improved the code a little. Can't figure out how to implement upper logic.
>> Can you finish the last part? Thanks
>>
>> #+begin_src emacs-lisp
>> (setq tbl (let* ((tags-grouped (org-tag-alist-to-groups fulltable))
>>...
>
> I tried to improve the code readability in `org-fast-tag-selection'.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=a19654583c6f2070096402bc712591a0a2c80d01
>
> May you look at it again and see if you can manage to implement a full
> patch now?

Ok, I update and re-generated the patch, also add new document and Org NEWS 
entries.

Review it, if has problem, notify me to modify. Thanks



0001-org-Improve-the-tags-fast-selection-performance.patch
Description: 

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH v4.1] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-06-30 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> I improved the code a little. Can't figure out how to implement upper logic.
> Can you finish the last part? Thanks
>
> #+begin_src emacs-lisp
> (setq tbl (let* ((tags-grouped (org-tag-alist-to-groups fulltable))
>...

I tried to improve the code readability in `org-fast-tag-selection'.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=a19654583c6f2070096402bc712591a0a2c80d01

May you look at it again and see if you can manage to implement a full
patch now?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[PATCH v4.1] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-16 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
 (seq-take (seq-uniq (append bound-tags 
 fulltable))
   org-fast-tag-selection-maximum-tags))
>>>
>>> This will behave awkwardly with tag groups. You may better use 
>>> `org--tag-add-to-alist'.
>>
>> I think here should use `append' instead of `org--tag-add-to-alist' to merge.
>
> Yeah. `org--tag-add-to-alist' does not tell it, but it actually prefers
> keeping duplicate tag copies from its second argument.
>
> Yet, however, tags with their binding assigned might occur inside a
> group. Your code will incorrectly pull them out.
>
> I think that the right approach to handle tag groups and explicitly
> bound tags is showing them all the time, even when the total number of
> tags exceeds the limit:
>
> 1. If a tag is bound explicitly (cdr non-nil) show it
> 2. If a tag is inside a group - show it
> 3. If there is still some room left, show up to the limit.
>
> My logic is that tag groups and bound tags can only be customized by the
> user. So, it makes sense to display them all the time - users likely
> expect such behaviour.
>
> WDYT?

I improved the code a little. Can't figure out how to implement upper logic.
Can you finish the last part? Thanks

#+begin_src emacs-lisp
(setq tbl (let* ((tags-grouped (org-tag-alist-to-groups fulltable))
 (fulltable-accurate (flatten-list 
(org-tag-alist-to-groups fulltable)))
 (bound-tags (seq-filter 'cdr fulltable)))
;; TODO: consider tag groups.
;; the right approach to handle tag groups and explicitly
;; bound tags is showing them all the time, even when the 
total number of
;; tags exceeds the limit
;; 
;; 1. If a tag is bound explicitly (cdr non-nil) show it
;; 2. If a tag is inside a group - show it
;; 3. If there is still some room left, show up to the 
limit.
(if (length< fulltable-accurate 
org-fast-tag-selection-maximum-tags)
fulltable
  (if (length< bound-tags 
org-fast-tag-selection-maximum-tags)
  (progn
(insert (format-message "Tags are limited displayed 
by `org-fast-tag-selection-maximum-tags'.\n"))
;; TODO:
(seq-take (seq-uniq (org--tag-add-to-alist 
bound-tags fulltable))
  org-fast-tag-selection-maximum-tags))
(insert "Tags are limited displayed only has key 
bound.\n")
bound-tags)))
  char ?a cnt 0)
#+end_src

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH v4] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-16 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>>> (seq-take (seq-uniq (append bound-tags 
>>> fulltable))
>>>   org-fast-tag-selection-maximum-tags))
>>
>> This will behave awkwardly with tag groups. You may better use 
>> `org--tag-add-to-alist'.
>
> I think here should use `append' instead of `org--tag-add-to-alist' to merge.

Yeah. `org--tag-add-to-alist' does not tell it, but it actually prefers
keeping duplicate tag copies from its second argument.

Yet, however, tags with their binding assigned might occur inside a
group. Your code will incorrectly pull them out.

I think that the right approach to handle tag groups and explicitly
bound tags is showing them all the time, even when the total number of
tags exceeds the limit:

1. If a tag is bound explicitly (cdr non-nil) show it
2. If a tag is inside a group - show it
3. If there is still some room left, show up to the limit.

My logic is that tag groups and bound tags can only be customized by the
user. So, it makes sense to display them all the time - users likely
expect such behaviour.

WDYT?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[PATCH v4] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-16 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> Updated version which fix the `message` error in upper code:
>
> Thanks!
>
>> #+begin_src emacs-lisp
>> (setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
>> (if (length< fulltable 
>> org-fast-tag-selection-maximum-tags)
>
> Because of (:startgroup) markers and similar things, this condition is
> not fully accurate. See `org-tag-alist' docstring.
>
> You may also need to consider special alist items in the rest of the code.
>
I added a let-binding to modify fulltable at first to filter out special tag 
markers.

>> fulltable
>>   (if (length< bound-tags 
>> org-fast-tag-selection-maximum-tags)
>>   (progn
>> (insert "Tags are limited displayed by 
>> `org-fast-tag-selection-maximum-tags'.\n")
>
> If you want to have proper Elisp symbol markup when using `...', use
> `format-message'.

Updated.

>
>> (seq-take (seq-uniq (append bound-tags 
>> fulltable))
>>   org-fast-tag-selection-maximum-tags))
>
> This will behave awkwardly with tag groups. You may better use 
> `org--tag-add-to-alist'.

I think here should use `append' instead of `org--tag-add-to-alist' to merge.

Using `append':

#+begin_example
Inherited:  video
Current:

Tags are limited displayed by ‘org-fast-tag-selection-maximum-tags’.
  [d] drill   [z] crypt 
  [A] ARCHIVE 
  [E] noexport[P] private   
  [D] deprecated  
  [O] outdated[t] translate 
  [i] idea
  [h] book[b] bookmark  
  [w] work
  [a] appointment [m] meeting   
  [u] urgent  
  [X] SEX [k] wiki  
  [C] code
  [e] Emacs   [o] Org_mode  
  [G] git 
  [L] Linux   [M] macOS 
  [W] Windows 
  [l] LISP[c] Clojure   
  [s] ClojureScript   
  [J] Java[S] Shell 
  [p] Python  
  [r] Ruby[j] JavaScript
  [d] database
  [f] LOG [g] @marks
  [n] on  
  [q] off [v] star  
  [x] like
  [y] favorite[{] suggested 
  [|] heart   
  [}] smile   [~] brain 
  [ ] check   
  [ ] alert   [ ] important 
  [ ] flag
  [ ] error   [ ] label 
  
#+end_example

Using `org--tag-add-to-alist':

#+begin_example
Inherited:  video
Current:

Tags are limited displayed by ‘org-fast-tag-selection-maximum-tags’.
  [d] drill   [z] crypt 
  [f] LOG 
  [A] ARCHIVE [E] noexport  
  [P] private 
  [D] deprecated  [O] outdated  
  [g] @marks  
  [n] on  [q] off   
  [v] star
  [x] like[y] favorite  
  [{] suggested   
  [|] heart   [}] smile 
  [~] brain   
  [ ] check   [ ] alert 
  [ ] important   
  [ ] flag[ ] error 
  [ ] label   
  [ ] question[ ] info  
  [ ] quote   
  [ ] table   [t] translate 
  [ ] language
  [i] idea[ ] comment   

[PATCH v4] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-16 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> Updated version which fix the `message` error in upper code:
>
> Thanks!
>
>> #+begin_src emacs-lisp
>> (setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
>> (if (length< fulltable 
>> org-fast-tag-selection-maximum-tags)
>
> Because of (:startgroup) markers and similar things, this condition is
> not fully accurate. See `org-tag-alist' docstring.
>
> You may also need to consider special alist items in the rest of the code.
>
I added a let-binding to modify fulltable at first to filter out special tag 
markers.

>> fulltable
>>   (if (length< bound-tags 
>> org-fast-tag-selection-maximum-tags)
>>   (progn
>> (insert "Tags are limited displayed by 
>> `org-fast-tag-selection-maximum-tags'.\n")
>
> If you want to have proper Elisp symbol markup when using `...', use
> `format-message'.

Updated.

>
>> (seq-take (seq-uniq (append bound-tags 
>> fulltable))
>>   org-fast-tag-selection-maximum-tags))
>
> This will behave awkwardly with tag groups. You may better use 
> `org--tag-add-to-alist'.

I think here should use `append' instead of `org--tag-add-to-alist' to merge.

Using `append':

#+begin_example
Inherited:  video
Current:

Tags are limited displayed by ‘org-fast-tag-selection-maximum-tags’.
  [d] drill   [z] crypt 
  [A] ARCHIVE 
  [E] noexport[P] private   
  [D] deprecated  
  [O] outdated[t] translate 
  [i] idea
  [h] book[b] bookmark  
  [w] work
  [a] appointment [m] meeting   
  [u] urgent  
  [X] SEX [k] wiki  
  [C] code
  [e] Emacs   [o] Org_mode  
  [G] git 
  [L] Linux   [M] macOS 
  [W] Windows 
  [l] LISP[c] Clojure   
  [s] ClojureScript   
  [J] Java[S] Shell 
  [p] Python  
  [r] Ruby[j] JavaScript
  [d] database
  [f] LOG [g] @marks
  [n] on  
  [q] off [v] star  
  [x] like
  [y] favorite[{] suggested 
  [|] heart   
  [}] smile   [~] brain 
  [ ] check   
  [ ] alert   [ ] important 
  [ ] flag
  [ ] error   [ ] label 
  
#+end_example

Using `org--tag-add-to-alist':

#+begin_example
Inherited:  video
Current:

Tags are limited displayed by ‘org-fast-tag-selection-maximum-tags’.
  [d] drill   [z] crypt 
  [f] LOG 
  [A] ARCHIVE [E] noexport  
  [P] private 
  [D] deprecated  [O] outdated  
  [g] @marks  
  [n] on  [q] off   
  [v] star
  [x] like[y] favorite  
  [{] suggested   
  [|] heart   [}] smile 
  [~] brain   
  [ ] check   [ ] alert 
  [ ] important   
  [ ] flag[ ] error 
  [ ] label   
  [ ] question[ ] info  
  [ ] quote   
  [ ] table   [t] translate 
  [ ] language
  [i] idea[ ] comment   

Re: [PATCH v3.1] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-16 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> Updated version which fix the `message` error in upper code:

Thanks!

> #+begin_src emacs-lisp
> (setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
> (if (length< fulltable 
> org-fast-tag-selection-maximum-tags)

Because of (:startgroup) markers and similar things, this condition is
not fully accurate. See `org-tag-alist' docstring.

You may also need to consider special alist items in the rest of the code.

> fulltable
>   (if (length< bound-tags 
> org-fast-tag-selection-maximum-tags)
>   (progn
> (insert "Tags are limited displayed by 
> `org-fast-tag-selection-maximum-tags'.\n")

If you want to have proper Elisp symbol markup when using `...', use 
`format-message'.

> (seq-take (seq-uniq (append bound-tags fulltable))
>   org-fast-tag-selection-maximum-tags))

This will behave awkwardly with tag groups. You may better use 
`org--tag-add-to-alist'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[PATCH v3.1] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-15 Thread Christopher M. Miles

"Christopher M. Miles"  writes:

> [[PGP Signed Part:Undecided]]
>
> Ihor Radchenko  writes:
>
>> "Christopher M. Miles"  writes:
>>
 You are almost there.
 Just run your code only when (lentgh> fulltable 26).

 Of course, 26 should be a defcustom rather than a hard-coded constant.
 And do the same for `org-fast-todo-selection'.
>>>
>>> Ok, I added defcustom option, and add cl-case condition on custom option
>>> `org-use-fast-tag-selection'.
>>
>> I do not think that we need to care about the value of
>> `org-use-fast-tag-selection'.  Instead, just
>>
>> 1. If the total number of tags does not exceed
>>`org-fast-tag-selection-maximum-tags', display them all.
>> 2. If the total number of tags is larger, just display all the bound
>>tags + any extra tags, up to `org-fast-tag-selection-maximum-tags',
>>and add a note in the tag selection buffer that more tags are not
>>displayed.
>
> Ok, I re-implemented the mechanism like bellowing, can you check whether it 
> fits?
>
> #+begin_src emacs-lisp
> (setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
> (if (length< fulltable 
> org-fast-tag-selection-maximum-tags)
> fulltable
>   (if (length< bound-tags 
> org-fast-tag-selection-maximum-tags)
>   (progn
> (seq-take (seq-uniq (append bound-tags fulltable))
>   org-fast-tag-selection-maximum-tags)
> (message "Tags are limited displayed by 
> `org-fast-tag-selection-maximum-tags'."))
> bound-tags
> (message "Tags are limited displayed only has key 
> bound."
>   char ?a cnt 0)
> #+end_src

Updated version which fix the `message` error in upper code:

#+begin_src emacs-lisp
(setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
(if (length< fulltable org-fast-tag-selection-maximum-tags)
fulltable
  (if (length< bound-tags 
org-fast-tag-selection-maximum-tags)
  (progn
(insert "Tags are limited displayed by 
`org-fast-tag-selection-maximum-tags'.\n")
(seq-take (seq-uniq (append bound-tags fulltable))
  org-fast-tag-selection-maximum-tags))
(insert "Tags are limited displayed only has key 
bound.\n")
bound-tags)))
  char ?a cnt 0)
#+end_src

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


[PATCH v3] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-15 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> You are almost there.
>>> Just run your code only when (lentgh> fulltable 26).
>>>
>>> Of course, 26 should be a defcustom rather than a hard-coded constant.
>>> And do the same for `org-fast-todo-selection'.
>>
>> Ok, I added defcustom option, and add cl-case condition on custom option
>> `org-use-fast-tag-selection'.
>
> I do not think that we need to care about the value of
> `org-use-fast-tag-selection'.  Instead, just
>
> 1. If the total number of tags does not exceed
>`org-fast-tag-selection-maximum-tags', display them all.
> 2. If the total number of tags is larger, just display all the bound
>tags + any extra tags, up to `org-fast-tag-selection-maximum-tags',
>and add a note in the tag selection buffer that more tags are not
>displayed.

Ok, I re-implemented the mechanism like bellowing, can you check whether it 
fits?

#+begin_src emacs-lisp
(setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
(if (length< fulltable org-fast-tag-selection-maximum-tags)
fulltable
  (if (length< bound-tags 
org-fast-tag-selection-maximum-tags)
  (progn
(seq-take (seq-uniq (append bound-tags fulltable))
  org-fast-tag-selection-maximum-tags)
(message "Tags are limited displayed by 
`org-fast-tag-selection-maximum-tags'."))
bound-tags
(message "Tags are limited displayed only has key 
bound."
  char ?a cnt 0)
#+end_src

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH v2] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-15 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> I do not think that we need to care about the value of
>> `org-use-fast-tag-selection'.  Instead, just
>>
>> 1. If the total number of tags does not exceed
>>`org-fast-tag-selection-maximum-tags', display them all.
>> 2. If the total number of tags is larger, just display all the bound
>>tags + any extra tags, up to `org-fast-tag-selection-maximum-tags',
>>and add a note in the tag selection buffer that more tags are not
>>displayed.
>
> I think we should consider the option `org-use-fast-tag-selection'.
> Because it controls the behavior that whether auto assign short-key to
> tags. Make condition decision based on this option is needed. I hope you
> can reconsider this.

We probably have a misunderstanding about the role of
`org-use-fast-tag-selection'.

`org-use-fast-tag-selection' _currently_ determines whether to display
the tag selection window at all:

Non-nil means use fast tag selection scheme.

This is a special interface to select and deselect tags with single keys.
When nil, fast selection is never used.
When the symbol auto, fast selection is used if and only if selection
characters for tags have been configured, either through the variable
org-tag-alist or through a #+TAGS line in the buffer.
When t, fast selection is always used and selection keys are assigned
automatically if necessary.

Even when the value is t, not 'auto, the user bindings for tags are
honored. `org-fast-tag-selection' never checks the value of
`org-use-fast-tag-selection'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH v2] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-15 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> You are almost there.
>>> Just run your code only when (lentgh> fulltable 26).
>>>
>>> Of course, 26 should be a defcustom rather than a hard-coded constant.
>>> And do the same for `org-fast-todo-selection'.
>>
>> Ok, I added defcustom option, and add cl-case condition on custom option
>> `org-use-fast-tag-selection'.
>
> I do not think that we need to care about the value of
> `org-use-fast-tag-selection'.  Instead, just
>
> 1. If the total number of tags does not exceed
>`org-fast-tag-selection-maximum-tags', display them all.
> 2. If the total number of tags is larger, just display all the bound
>tags + any extra tags, up to `org-fast-tag-selection-maximum-tags',
>and add a note in the tag selection buffer that more tags are not
>displayed.

I think we should consider the option `org-use-fast-tag-selection'.
Because it controls the behavior that whether auto assign short-key to
tags. Make condition decision based on this option is needed. I hope you
can reconsider this.

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH v2] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-15 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> You are almost there.
>> Just run your code only when (lentgh> fulltable 26).
>>
>> Of course, 26 should be a defcustom rather than a hard-coded constant.
>> And do the same for `org-fast-todo-selection'.
>
> Ok, I added defcustom option, and add cl-case condition on custom option
> `org-use-fast-tag-selection'.

I do not think that we need to care about the value of
`org-use-fast-tag-selection'.  Instead, just

1. If the total number of tags does not exceed
   `org-fast-tag-selection-maximum-tags', display them all.
2. If the total number of tags is larger, just display all the bound
   tags + any extra tags, up to `org-fast-tag-selection-maximum-tags',
   and add a note in the tag selection buffer that more tags are not
   displayed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[PATCH v2] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-14 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
 #+begin_src emacs-lisp
 (let ((bound-tags (seq-filter 'cdr temp-fulltable)))
   (if (length> bound-tags 0)
   bound-tags
 (seq-take temp-fulltable 26)))
 #+end_src
>>>
>>> This will unconditionally drop auto-labeled tags when user-bound tags
>>> exist, even if the total number of tags in buffer does not exceed 26.
>>
>> I try to read the source code of `org-fast-tag-selection', but the code is 
>> hard to read.
>
> Yeah. I agree. But we have what we have.
>
>> I don't know how to keep auto-labeled tags. Do you have any suggestions?
>
> You are almost there.
> Just run your code only when (lentgh> fulltable 26).
>
> Of course, 26 should be a defcustom rather than a hard-coded constant.
> And do the same for `org-fast-todo-selection'.

Ok, I added defcustom option, and add cl-case condition on custom option
`org-use-fast-tag-selection'.



0001-org-Improve-the-tags-fast-selection-performance.patch
Description: 

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-14 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>>> #+begin_src emacs-lisp
>>> (let ((bound-tags (seq-filter 'cdr temp-fulltable)))
>>>   (if (length> bound-tags 0)
>>>   bound-tags
>>> (seq-take temp-fulltable 26)))
>>> #+end_src
>>
>> This will unconditionally drop auto-labeled tags when user-bound tags
>> exist, even if the total number of tags in buffer does not exceed 26.
>
> I try to read the source code of `org-fast-tag-selection', but the code is 
> hard to read.

Yeah. I agree. But we have what we have.

> I don't know how to keep auto-labeled tags. Do you have any suggestions?

You are almost there.
Just run your code only when (lentgh> fulltable 26).

Of course, 26 should be a defcustom rather than a hard-coded constant.
And do the same for `org-fast-todo-selection'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-14 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> Sorry, wrong code, here is the correct code snippet:
>>
>> #+begin_src emacs-lisp
>> (let ((bound-tags (seq-filter 'cdr temp-fulltable)))
>>   (if (length> bound-tags 0)
>>   bound-tags
>> (seq-take temp-fulltable 26)))
>> #+end_src
>
> This will unconditionally drop auto-labeled tags when user-bound tags
> exist, even if the total number of tags in buffer does not exceed 26.

I try to read the source code of `org-fast-tag-selection', but the code is hard 
to read.
I don't know how to keep auto-labeled tags. Do you have any suggestions?


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-14 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> Sorry, wrong code, here is the correct code snippet:
>
> #+begin_src emacs-lisp
> (let ((bound-tags (seq-filter 'cdr temp-fulltable)))
>   (if (length> bound-tags 0)
>   bound-tags
> (seq-take temp-fulltable 26)))
> #+end_src

This will unconditionally drop auto-labeled tags when user-bound tags
exist, even if the total number of tags in buffer does not exceed 26.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-14 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> What about like this?
>>
>> #+begin_src emacs-lisp
>> (setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
>> (if (length> shortkeys 0)
>> bound-tags
>>   (seq-take fulltable 26)))
>>   char ?a cnt 0)
>> #+end_src
>
> What do you mean by "shortkeys"?

Sorry, wrong code, here is the correct code snippet:

#+begin_src emacs-lisp
(let ((bound-tags (seq-filter 'cdr temp-fulltable)))
  (if (length> bound-tags 0)
  bound-tags
(seq-take temp-fulltable 26)))
#+end_src

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-14 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> What about like this?
>
> #+begin_src emacs-lisp
> (setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
> (if (length> shortkeys 0)
> bound-tags
>   (seq-take fulltable 26)))
>   char ?a cnt 0)
> #+end_src

What do you mean by "shortkeys"?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> It would be great if you can come up with a patch.
>>> 1. Keeping tags with explicitly assigned key binding indeed makes sense
>>> 2. If we limit the number of displayed tags (on top of explicitly
>>>assigned), it should be a defcustom.
>>
>> Here is the patch.
>> -(setq tbl fulltable char ?a cnt 0)
>> +(setq tbl (seq-filter 'cdr fulltable) char ?a cnt 0)
>
> Thanks, but it will make the tag selection useless for people who did
> not customize explicit tag bindings.
>
> You should instead only filter when the number of tags exceeds some
> customized value.

What about like this?

#+begin_src emacs-lisp
(setq tbl (let ((bound-tags (seq-filter 'cdr fulltable)))
(if (length> shortkeys 0)
bound-tags
  (seq-take fulltable 26)))
  char ?a cnt 0)
#+end_src

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> It would be great if you can come up with a patch.
>> 1. Keeping tags with explicitly assigned key binding indeed makes sense
>> 2. If we limit the number of displayed tags (on top of explicitly
>>assigned), it should be a defcustom.
>
> Here is the patch.
> - (setq tbl fulltable char ?a cnt 0)
> + (setq tbl (seq-filter 'cdr fulltable) char ?a cnt 0)

Thanks, but it will make the tag selection useless for people who did
not customize explicit tag bindings.

You should instead only filter when the number of tags exceeds some
customized value.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[PATCH] Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread Christopher M. Miles

Ihor Radchenko  writes:

> stardiviner  writes:
>
>> I applied your diff with a testing. This indeed solved the performance
>> issue.
>> Will this be updated in Org-mode source code?
>> Also I come up with one thing, filter out tags which have shortcut
>> keybinding bound. Because user defined shortcut key defined tags are not
>> always on head of list.
>
> It would be great if you can come up with a patch.
> 1. Keeping tags with explicitly assigned key binding indeed makes sense
> 2. If we limit the number of displayed tags (on top of explicitly
>assigned), it should be a defcustom.

Here is the patch.



0001-org-Improve-the-tags-fast-selection-performance.patch
Description: 

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread Christopher M. Miles

Ihor Radchenko  writes:

> stardiviner  writes:
>
>> I have a large `org-tag-alist` value that contains about ~7000 tags.
>> When I press [C-c C-q] `org-set-tags-command`. Emacs suspends a long time.
>
> Indeed. That's because `org-fast-tag-selection' tries to put all those
> 7k tags into tag selection window.
>
> We can probably limit the maximum number of tags in the quick selection
> window.
>
> Can you try the attached simple diff for `org-fast-tag-selection' and
> check if it is enough to solve the hang?
>
> diff --git a/lisp/org.el b/lisp/org.el
> index c148409d9..d745fd01e 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -11765,7 +11765,7 @@ (defun org-fast-tag-selection (current inherited 
> table  todo-table)
>   (org-fast-tag-insert "Current" current c-face "\n\n")
>   (org-fast-tag-show-exit exit-after-next)
>   (org-set-current-tags-overlay current ov-prefix)
> - (setq tbl fulltable char ?a cnt 0)
> + (setq tbl (seq-take fulltable 26) char ?a cnt 0)
>   (while (setq e (pop tbl))
> (cond
>  ((eq (car e) :startgroup)

I applied your diff with a testing. This indeed solved the performance issue.
Will this be updated in Org-mode source code?

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread Ihor Radchenko
stardiviner  writes:

> I applied your diff with a testing. This indeed solved the performance
> issue.
> Will this be updated in Org-mode source code?
> Also I come up with one thing, filter out tags which have shortcut
> keybinding bound. Because user defined shortcut key defined tags are not
> always on head of list.

It would be great if you can come up with a patch.
1. Keeping tags with explicitly assigned key binding indeed makes sense
2. If we limit the number of displayed tags (on top of explicitly
   assigned), it should be a defcustom.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread stardiviner
I applied your diff with a testing. This indeed solved the performance
issue.
Will this be updated in Org-mode source code?
Also I come up with one thing, filter out tags which have shortcut
keybinding bound. Because user defined shortcut key defined tags are not
always on head of list.

[stardiviner] GPG key ID: 47C32433
IRC(freeenode): stardiviner Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/


On Sat, May 13, 2023 at 3:39 PM Ihor Radchenko  wrote:

> stardiviner  writes:
>
> > I have a large `org-tag-alist` value that contains about ~7000 tags.
> > When I press [C-c C-q] `org-set-tags-command`. Emacs suspends a long
> time.
>
> Indeed. That's because `org-fast-tag-selection' tries to put all those
> 7k tags into tag selection window.
>
> We can probably limit the maximum number of tags in the quick selection
> window.
>
> Can you try the attached simple diff for `org-fast-tag-selection' and
> check if it is enough to solve the hang?
>
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at .
> Support Org development at ,
> or support my work at 
>


Re: Improve the performance of `org-set-tags-command` on large `org-tag-alist`

2023-05-13 Thread Ihor Radchenko
stardiviner  writes:

> I have a large `org-tag-alist` value that contains about ~7000 tags.
> When I press [C-c C-q] `org-set-tags-command`. Emacs suspends a long time.

Indeed. That's because `org-fast-tag-selection' tries to put all those
7k tags into tag selection window.

We can probably limit the maximum number of tags in the quick selection
window.

Can you try the attached simple diff for `org-fast-tag-selection' and
check if it is enough to solve the hang?

diff --git a/lisp/org.el b/lisp/org.el
index c148409d9..d745fd01e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11765,7 +11765,7 @@ (defun org-fast-tag-selection (current inherited table  todo-table)
 	(org-fast-tag-insert "Current" current c-face "\n\n")
 	(org-fast-tag-show-exit exit-after-next)
 	(org-set-current-tags-overlay current ov-prefix)
-	(setq tbl fulltable char ?a cnt 0)
+	(setq tbl (seq-take fulltable 26) char ?a cnt 0)
 	(while (setq e (pop tbl))
 	  (cond
 	   ((eq (car e) :startgroup)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at