From fca33c6a0a7cff4737439289148616c95dbd3577 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Mon, 6 Jan 2025 18:56:20 +0100 Subject: [PATCH] forge-topic-wash-title-hook: New hook Closes #735. --- docs/forge.org | 9 ++++++++ docs/forge.texi | 9 ++++++++ lisp/forge-topic.el | 55 +++++++++++++++++++++++++++++---------------- lisp/forge.el | 2 +- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/docs/forge.org b/docs/forge.org index 3bccca1a..0bf54da9 100644 --- a/docs/forge.org +++ b/docs/forge.org @@ -1246,6 +1246,15 @@ then the remote is never removed. This option specifies the file used to store the forge database. +- User Option: forge-topic-wash-title-hook :: + + Functions used to highlight parts of each individual topic title. + + These functions are called in order, in a buffer that containing the + topic title. They should set text properties as they see fit, usually + just ~font-lock-face~. Before each function is called, point is at the + beginning of the buffer. + - User Option: forge-topic-repository-slug-width :: This option specifies the width of repository slugs (i.e., diff --git a/docs/forge.texi b/docs/forge.texi index 410ed53a..d9766576 100644 --- a/docs/forge.texi +++ b/docs/forge.texi @@ -1453,6 +1453,15 @@ under heavy development. This option specifies the file used to store the forge database. @end defopt +@defopt forge-topic-wash-title-hook +Functions used to highlight parts of each individual topic title. + +These functions are called in order, in a buffer that containing the +topic title. They should set text properties as they see fit, usually +just @code{font-lock-face}. Before each function is called, point is at the +beginning of the buffer. +@end defopt + @defopt forge-topic-repository-slug-width This option specifies the width of repository slugs (i.e., "OWNER/NAME"). diff --git a/lisp/forge-topic.el b/lisp/forge-topic.el index bb456101..f5772a8f 100644 --- a/lisp/forge-topic.el +++ b/lisp/forge-topic.el @@ -59,6 +59,19 @@ The following %-sequences are supported: :group 'forge :type 'boolean) +(defcustom forge-topic-wash-title-hook + (list #'magit-highlight-bracket-keywords) + "Functions used to highlight parts of each individual topic title. + +These functions are called in order, in a buffer that containing the +topic title. They should set text properties as they see fit, usually +just `font-lock-face'. Before each function is called, point is at the +beginning of the buffer." + :package-version '(forge . "0.4.7") + :group 'forge + :type 'hook + :options (list #'magit-highlight-bracket-keywords)) + (defcustom forge-topic-repository-slug-width 28 "Width of repository slugs (i.e., \"OWNER/NAME\")." :package-version '(forge . "0.4.0") @@ -828,25 +841,29 @@ can be selected from the start." (magit--propertize-face "no" 'magit-dimmed))) (defun forge--format-topic-title (topic) - (with-slots (title status state) topic - (magit-log-propertize-keywords - nil - (magit--propertize-face - title - `(,@(and (forge-pullreq-p topic) - (oref topic draft-p) - '(forge-pullreq-draft)) - ,(pcase status - ('unread 'forge-topic-unread) - ('pending 'forge-topic-pending) - ('done 'forge-topic-done)) - ,(pcase (list (eieio-object-class topic) state) - (`(forge-issue open) 'forge-issue-open) - (`(forge-issue completed) 'forge-issue-completed) - (`(forge-issue unplanned) 'forge-issue-unplanned) - (`(forge-pullreq open) 'forge-pullreq-open) - (`(forge-pullreq merged) 'forge-pullreq-merged) - (`(forge-pullreq rejected) 'forge-pullreq-rejected))))))) + (with-temp-buffer + (save-excursion + (with-slots (title status state) topic + (insert + (magit--propertize-face + title + `(,@(and (forge-pullreq-p topic) + (oref topic draft-p) + '(forge-pullreq-draft)) + ,(pcase status + ('unread 'forge-topic-unread) + ('pending 'forge-topic-pending) + ('done 'forge-topic-done)) + ,(pcase (list (eieio-object-class topic) state) + (`(forge-issue open) 'forge-issue-open) + (`(forge-issue completed) 'forge-issue-completed) + (`(forge-issue unplanned) 'forge-issue-unplanned) + (`(forge-pullreq open) 'forge-pullreq-open) + (`(forge-pullreq merged) 'forge-pullreq-merged) + (`(forge-pullreq rejected) 'forge-pullreq-rejected))))))) + (run-hook-wrapped 'forge-topic-wash-title-hook + (lambda (fn) (prog1 nil (save-excursion (funcall fn))))) + (buffer-string))) (defun forge--format-topic-milestone (topic) (and-let* ((id (oref topic milestone)) diff --git a/lisp/forge.el b/lisp/forge.el index a66d20ea..16120811 100644 --- a/lisp/forge.el +++ b/lisp/forge.el @@ -16,7 +16,7 @@ ;; (emacsql "4.1.0") ;; (ghub "4.2.0") ;; (let-alist "1.0.6") -;; (magit "4.2.0") +;; (magit "4.2.1") ;; (markdown-mode "2.6") ;; (seq "2.24") ;; (transient "0.8.2")