aboutsummaryrefslogtreecommitdiff
path: root/pearl.el
diff options
context:
space:
mode:
Diffstat (limited to 'pearl.el')
-rw-r--r--pearl.el38
1 files changed, 27 insertions, 11 deletions
diff --git a/pearl.el b/pearl.el
index 56b6d44..3f65617 100644
--- a/pearl.el
+++ b/pearl.el
@@ -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))))))