diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 17:21:29 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 17:21:29 -0500 |
| commit | cc599d3e9d37c200d49f723ff8e8ce694acd33f8 (patch) | |
| tree | 6ee899bcd4a0a45c946329859d671ff6825efce7 /pearl.el | |
| parent | bb30b0f9146722b279832a991540917c3fa3cb81 (diff) | |
| download | pearl-cc599d3e9d37c200d49f723ff8e8ce694acd33f8.tar.gz pearl-cc599d3e9d37c200d49f723ff8e8ce694acd33f8.zip | |
feat: make comment sort order configurable, newest-first by default
I added pearl-comment-sort-order to choose how an issue's comments render under the Comments heading: newest-first (the default, most recent on top) or oldest-first (chronological, like an email thread). Both the render sort and the add-comment insertion point honor it, so a new comment lands at the top for newest-first and at the bottom for oldest-first.
Diffstat (limited to 'pearl.el')
| -rw-r--r-- | pearl.el | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -1812,18 +1812,30 @@ path; nil (the single-issue thread) yields no marker." (if (plist-get count-info :overflow) "+" "")) "")) +(defcustom pearl-comment-sort-order 'newest-first + "Order in which an issue's comments render under the Comments heading. +`newest-first' puts the most recent comment at the top, and a newly added +comment is inserted there. `oldest-first' reads top-to-bottom, oldest to +newest, like an email thread, and a new comment appends at the bottom." + :type '(choice (const :tag "Newest first (most recent on top)" newest-first) + (const :tag "Oldest first (chronological)" oldest-first)) + :group 'pearl) + (defun pearl--format-comments (comments &optional count-info) "Format COMMENTS (a list of normalized comment plists) as a Comments subtree. -Comments render oldest-first under a level-3 `Comments' heading. Returns the -empty string when COMMENTS is nil, so an issue with no comments renders no -subtree. COUNT-INFO, when non-nil, adds a `💬 shown/total' marker to the -heading (the bulk list passes the issue's `:comment-count')." +Comments render under a level-3 `Comments' heading, ordered per +`pearl-comment-sort-order'. +Returns the empty string when COMMENTS is nil, so an issue with no comments +renders no subtree. COUNT-INFO, when non-nil, adds a `💬 shown/total' marker to +the heading (the bulk list passes the issue's `:comment-count')." (if (null comments) "" - (let ((sorted (sort (copy-sequence comments) - (lambda (a b) - (string< (or (plist-get a :created-at) "") - (or (plist-get b :created-at) "")))))) + (let* ((newest-first (eq pearl-comment-sort-order 'newest-first)) + (sorted (sort (copy-sequence comments) + (lambda (a b) + (let ((ca (or (plist-get a :created-at) "")) + (cb (or (plist-get b :created-at) ""))) + (if newest-first (string> ca cb) (string< ca cb))))))) (concat "*** Comments" (pearl--comment-count-marker count-info) "\n" (mapconcat #'pearl--format-comment sorted ""))))) @@ -2487,8 +2499,10 @@ GraphQL/transport failure or a non-success payload." (defun pearl--append-comment-to-issue (comment) "Insert COMMENT (a normalized plist) under the issue subtree at point. -Appends after any existing comments in the issue's `Comments' subtree, creating -that subtree at the end of the issue when it does not exist yet." +A new comment is the newest, so it lands where `pearl-comment-sort-order' puts +the newest: at the top of the `Comments' subtree (just under the heading) for +`newest-first', or after the last comment for `oldest-first'. Creates the +subtree at the end of the issue when it does not exist yet." (save-excursion (org-back-to-heading t) (let* ((issue-end (save-excursion (org-end-of-subtree t t) (point))) @@ -2500,7 +2514,9 @@ that subtree at the end of the issue when it does not exist yet." (if comments-pos (progn (goto-char comments-pos) - (org-end-of-subtree t t) + (if (eq pearl-comment-sort-order 'newest-first) + (forward-line 1) ; just under the heading, before the first comment + (org-end-of-subtree t t)) ; after the last comment (insert (pearl--format-comment comment))) (goto-char issue-end) (insert "*** Comments\n" (pearl--format-comment comment)))))) |
