Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Custom message format spec for notification buffers #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ Ement.el doesn't support encrypted rooms natively, but it can be used transparen
*Additions*

+ When option ~ement-room-images~ is disabled (preventing automatic download and display of images), individual images may be shown by clicking the button in their events.
+ New options ~ement-notifications-message-format-spec~ and ~ement-notifications-room-button-separator~ allow the notification buffer message rendering to be customised. (Thanks to [[https://github.com/phil-s][Phil Sainty]].)

*Changes*

Expand Down
38 changes: 35 additions & 3 deletions ement-notifications.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,38 @@ Used to avoid overlapping requests.")
(defvar ement-room-message-format-spec)
(defvar ement-room-sender-in-left-margin)

;;;; Customization

(defcustom ement-notifications-room-button-separator
(rx ">" (or " " eol))
"Regexp identifying how notification button properties will be applied.
The button will cover the text up until the end of the first match.

See `ement-notifications-message-format-spec'."
:type 'regexp
:group 'ement-notify)

(defcustom ement-notifications-message-format-spec "%o%O »%W %S> %B%R%t"
"Format *Ement Notifications* buffer messages according to this spec.

See `ement-room-message-format-spec' for format details.

The regexp `ement-notifications-room-button-separator' should match a
position between the room/sender and the message body. With the default
regexp, the format-spec must contain a \">\" character followed by
either a space or a newline.

Applying the button properties only to the room and sender names allows
any buttons in the rest of the message to remain usable."
:type '(choice (const :tag "Default" "%o%O »%W %S> %B%R%t")
(string :tag "Custom format"))
:set #'ement-room-message-format-spec-setter
:set-after '(ement-room-message-format-spec)
;; This file must be loaded before calling the setter to define the
;; `ement-room-user' face used in it.
:require 'ement-room
:group 'ement-notify)

;;;; Commands

;;;###autoload
Expand Down Expand Up @@ -212,7 +244,7 @@ to `ement-api', which see."
:key #'ement-room-id :test #'equal)
(error "ement-notifications-log-to-buffer: Can't find room <%s>; discarding notification" room-id)))
(ement-room-sender-in-left-margin nil)
(ement-room-message-format-spec "%o%O »%W %S> %B%R%t")
(ement-room-message-format-spec ement-notifications-message-format-spec)
(new-node (ement-room--insert-event event))
(inhibit-read-only t)
(start) (end))
Expand All @@ -221,7 +253,7 @@ to `ement-api', which see."
;; allowing buttons in the rest of the message to remain separate.
(setf start (point)
end (save-excursion
(re-search-forward (rx "> "))))
(re-search-forward ement-notifications-room-button-separator)))
(add-text-properties start end '( button (t)
category default-button
action ement-notify-button-action))
Expand Down Expand Up @@ -269,7 +301,7 @@ to `ement-api', which see."
(setf ement-room-sender-in-left-margin nil
left-margin-width 0
right-margin-width 8)
(setq-local ement-room-message-format-spec "[%o%O] %S> %B%R%t"
(setq-local ement-room-message-format-spec ement-notifications-message-format-spec
bookmark-make-record-function #'ement-notifications-bookmark-make-record))

;;;; Bookmark support
Expand Down
7 changes: 6 additions & 1 deletion ement-room.el
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ non-nil, set the variables buffer-locally (i.e. when called from
(message "Ement: Kill and reopen room buffers to display in new format")))))

(defcustom ement-room-message-format-spec "%S%L%B%r%R%t"
;; Formatter definitions: (occur "(\\ement-room-define-event-formatter")
"Format messages according to this spec.
It may contain these specifiers:

Expand All @@ -878,7 +879,9 @@ It may contain these specifiers:

Note that margin sizes must be set manually with
`ement-room-left-margin-width' and
`ement-room-right-margin-width'."
`ement-room-right-margin-width'.

See also `ement-notifications-message-format-spec'."
:type '(choice (const :tag "IRC-style using margins" "%S%L%B%r%R%t")
(const :tag "IRC-style without margins" "[%t] %S> %B%r")
(const :tag "IRC-style without margins, with wrap-prefix" "[%t] %S> %W%B%r")
Expand Down Expand Up @@ -4000,6 +4003,8 @@ Formats according to `ement-room-message-format-spec', which see."
(cl-defun ement-room--format-message (event room session &optional (format ement-room-message-format-spec))
"Return EVENT in ROOM on SESSION formatted according to FORMAT.
Format defaults to `ement-room-message-format-spec', which see."
;; Formatter definitions: (occur "(\\ement-room-define-event-formatter")
;;
;; Bind this locally so formatters can modify it for this call.
(let ((ement-room--format-message-margin-p)
(left-margin-width ement-room-left-margin-width)
Expand Down
Loading