From f09d222aaecd2a41857dcc857c8578964ac18e97 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Thu, 27 Jun 2024 17:40:46 +0200 Subject: [PATCH] forge-insert-{issues,pullreqs}: Add SPEC and HEADING arguments This allows wrapping these functions, while overriding certain aspects, to define additional section inserters that apply additional filtering. In `forge--insert-topics' use the heading as the "value", which is necessary to tell different sections apart. See #676. Usage example: (defun forge-insert-assigned-issues () "Insert a list of issues that are assigned to you. Mostly honor the buffer's filtering spec, overriding only the `assignee' slot." (when-let (((forge-db t)) (repo (forge-get-repository :tracked?)) (user (ghub--username repo)) (spec (clone forge--buffer-topics-spec))) (oset spec assignee user) (forge-insert-issues spec "Assigned issues"))) (magit-add-section-hook 'magit-status-sections-hook #'forge-insert-assigned-issues #'forge-insert-issues t) --- lisp/forge-issue.el | 14 ++++++++------ lisp/forge-pullreq.el | 14 ++++++++------ lisp/forge-topic.el | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lisp/forge-issue.el b/lisp/forge-issue.el index 7d3d2b1b..49a98ed6 100644 --- a/lisp/forge-issue.el +++ b/lisp/forge-issue.el @@ -180,16 +180,18 @@ can be selected from the start." " " #'forge-visit-this-topic " " #'forge-topic-menu) -(defun forge-insert-issues () - "Insert a list of issues." +(cl-defun forge-insert-issues (&optional (spec nil sspec) heading) + "Insert a list of issues, according to `forge--buffer-topics-spec'. +Optional SPEC can be used to override that filtering specification, +and optional HEADING to change the section heading." (when-let (((forge-db t)) (repo (forge-get-repository :tracked?)) ((oref repo issues-p)) - (spec forge--buffer-topics-spec) - ((memq (oref spec type) '(topic issue))) - (spec (clone spec))) + (spec (if sspec spec (clone forge--buffer-topics-spec))) + ((memq (oref spec type) '(topic issue)))) (oset spec type 'issue) - (forge--insert-topics 'issues "Issues" + (forge--insert-topics 'issues + (or heading "Issues") (forge--list-topics spec repo)))) ;;; _ diff --git a/lisp/forge-pullreq.el b/lisp/forge-pullreq.el index 411cc85a..68896412 100644 --- a/lisp/forge-pullreq.el +++ b/lisp/forge-pullreq.el @@ -225,15 +225,17 @@ can be selected from the start." " " #'forge-visit-this-topic " " #'forge-topic-menu) -(defun forge-insert-pullreqs () - "Insert a list of pull-requests." +(cl-defun forge-insert-pullreqs (&optional (spec nil sspec) heading) + "Insert a list of pull-requests, according to `forge--buffer-topics-spec'. +Optional SPEC can be used to override that filtering specification, +and optional HEADING to change the section heading." (when-let (((forge-db t)) (repo (forge-get-repository :tracked?)) - (spec forge--buffer-topics-spec) - ((memq (oref spec type) '(topic pullreq))) - (spec (clone spec))) + (spec (if sspec spec (clone forge--buffer-topics-spec))) + ((memq (oref spec type) '(topic pullreq)))) (oset spec type 'pullreq) - (forge--insert-topics 'pullreqs "Pull requests" + (forge--insert-topics 'pullreqs + (or heading "Pull requests") (forge--list-topics spec repo)))) (defun forge--insert-pullreq-commits (pullreq &optional all) diff --git a/lisp/forge-topic.el b/lisp/forge-topic.el index df3f3977..d55b4aef 100644 --- a/lisp/forge-topic.el +++ b/lisp/forge-topic.el @@ -892,7 +892,7 @@ can be selected from the start." (defun forge--insert-topics (type heading topics) (when topics (let ((width (apply #'max (--map (length (oref it slug)) topics)))) - (magit-insert-section ((eval type) nil t) + (magit-insert-section ((eval type) heading t) (magit-insert-heading (concat (magit--propertize-face (concat heading " ") 'magit-section-heading)