Skip to content

Commit

Permalink
forge-topic-wash-title-hook: New hook
Browse files Browse the repository at this point in the history
Closes #735.
  • Loading branch information
tarsius committed Jan 6, 2025
1 parent 0c90606 commit fca33c6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 20 deletions.
9 changes: 9 additions & 0 deletions docs/forge.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand Down
9 changes: 9 additions & 0 deletions docs/forge.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
55 changes: 36 additions & 19 deletions lisp/forge-topic.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lisp/forge.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit fca33c6

Please sign in to comment.