From: Morgan Smith <morgan.j.smith@outlook.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Testing: Add tests for `org-tags-sort-function'
Date: Tue, 10 Dec 2024 19:05:12 -0500 [thread overview]
Message-ID: <CH3PR84MB3424D8D8059255B092C2EAA2C53E2@CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <875xrdzyvs.fsf@outlook.com> (Morgan Smith's message of "Mon, 02 Sep 2024 14:36:23 -0400")
[-- Attachment #1: Type: text/plain, Size: 1515 bytes --]
Hello!
Morgan Smith <morgan.j.smith@outlook.com> writes:
> Ihor Radchenko <yantar92@posteo.net> writes:
>>> + ;; TODO: a value of `nil' sorts it! That's not what the
>>> + ;; defcustom :type of `org-tags-sort-function' says! It
>>> + ;; says "No sorting".
>>
>> Right. When sort function is not set agenda specifically (but not other
>> users of org-tags-sort-function) falls back to alphabetical sorting.
>
> As far as I can tell the only place where it doesn't fall back is in
> `org-set-tags'.
>
>> In fact, the docstring does not at all mention that
>> `org-tags-sort-function' is honored at all:
>>
>> (defcustom org-agenda-sorting-strategy ...
>> ...
>> tag-up Sort alphabetically by last tag, A-Z.
>> tag-down Sort alphabetically by last tag, Z-A.
>>
>> We need to fix this docstring documenting `org-tags-sort-function', I think.
>
> I don't understand what is happening in `org-entries-lessp' or how it
> even manages to use `org-agenda-sorting-strategy' so I'm going to
> refrain from trying to document things I don't understand.
I've polished the patch slightly but it's almost identical to what I
submitted before. There is one remaining issue as you can see above but
I'm trying my best to ignore it. I believe this patch can be applied
before the issue is fixed. I would like this patch to be accepted so I
can build off of it to submit another patch that includes an alternative
function to set `org-tags-sort-function' to.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Testing-Add-tests-for-org-tags-sort-function.patch --]
[-- Type: text/x-patch, Size: 2580 bytes --]
From e0ec4bf01230b3e38276daf709dce9e459f1b3e0 Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Sat, 15 Jun 2024 11:27:34 -0400
Subject: [PATCH] Testing: Add tests for `org-tags-sort-function'
* testing/lisp/test-org-agenda.el (test-org-agenda/tags-sorting): New
test.
---
testing/lisp/test-org-agenda.el | 44 +++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 778f91e8e..5f9916232 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -655,6 +655,50 @@ Sunday 7 January 2024
(buffer-string))))))
(org-test-agenda--kill-all-agendas))))
+(ert-deftest test-org-agenda/tags-sorting ()
+ "Test if `org-agenda' sorts tags according to `org-tags-sort-function'."
+ (let ((org-agenda-custom-commands
+ '(("f" "no fluff" todo ""
+ ((org-agenda-todo-keyword-format "")
+ (org-agenda-overriding-header "")
+ (org-agenda-prefix-format "")
+ (org-agenda-remove-tags t)
+ (org-agenda-sorting-strategy '(tag-up)))))))
+ (org-test-agenda-with-agenda
+ (string-join
+ '("* TODO group_a :group_a:"
+ "* TODO tag_a_1 :tag_a_1:"
+ "* TODO tag_a_2 :tag_a_2:"
+ "* TODO tag_b_1 :tag_b_1:"
+ "* TODO tag_b_2 :tag_b_2:"
+ "* TODO groupless :groupless:"
+ "* TODO lonely :lonely:")
+ "\n")
+ (dolist (org-tags-sort-function '(nil org-string< org-string> ignore))
+ (should
+ (string-equal
+ (string-trim
+ (progn
+ (org-agenda nil "f")
+ (substring-no-properties (buffer-string))))
+ (pcase org-tags-sort-function
+ ;; Not sorted
+ ('ignore
+ (string-join
+ '("group_a" "tag_a_1" "tag_a_2" "tag_b_1" "tag_b_2" "groupless" "lonely")
+ "\n"))
+ ;; TODO: a value of `nil' sorts it! That's not what the
+ ;; defcustom :type of `org-tags-sort-function' says! It
+ ;; says "No sorting".
+ ((or 'nil 'org-string<)
+ (string-join
+ '("group_a" "groupless" "lonely" "tag_a_1" "tag_a_2" "tag_b_1" "tag_b_2")
+ "\n"))
+ ('org-string>
+ (string-join
+ '("tag_b_2" "tag_b_1" "tag_a_2" "tag_a_1" "lonely" "groupless" "group_a")
+ "\n")))))))))
+
(ert-deftest test-org-agenda/goto-date ()
"Test `org-agenda-goto-date'."
(unwind-protect
--
2.46.0
prev parent reply other threads:[~2024-12-11 0:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-15 15:27 [PATCH] Testing: Add tests for `org-tags-sort-function' Morgan Smith
2024-09-01 13:33 ` Ihor Radchenko
2024-09-02 18:36 ` Morgan Smith
[not found] ` <875xrdzyvs.fsf@outlook.com>
2024-12-11 0:05 ` Morgan Smith [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CH3PR84MB3424D8D8059255B092C2EAA2C53E2@CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM \
--to=morgan.j.smith@outlook.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).