Skip to content

Commit 8be6b3a

Browse files
committed
Change: Workaround font-lock issue in magit-section
Fixes #331.
1 parent 2e6bb2e commit 8be6b3a

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

README.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ Ement.el doesn't support encrypted rooms natively, but it can be used transparen
313313
*Fixes*
314314

315315
+ Call ~eww-browse-url~ instead of ~browse-url~ in ~ement-room-browse-mxc~ (because the latter is not useful for authenticated media if the user has configured it to use a different browser). ([[https://github.com/alphapapa/ement.el/pull/323][#323]]. Thanks to [[https://github.com/viiru-][Arto Jantunen]].)
316+
+ Workaround change in ~magit-section~ that broke fontification in room-list and directory buffers. (See [[https://github.com/alphapapa/ement.el/issues/331][#331]].)
316317

317318
** 0.16
318319

ement-directory.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
(_ (when-let ((room (cl-find id (ement-session-rooms session)
9494
:key #'ement-room-id :test #'equal))
9595
((ement--room-direct-p room session)))
96-
(propertize "People" 'face 'ement-room-list-direct))))))
96+
(ement-propertize "People"
97+
'face 'ement-room-list-direct))))))
9798

9899
(defcustom ement-directory-default-keys
99100
'((joined-p
@@ -143,8 +144,8 @@
143144
'ement-room-list-name)))))
144145
;; NOTE: We can't use `ement--room-display-name' because these aren't room structs,
145146
;; and we don't have membership data.
146-
(propertize (or name canonical-alias "[unnamed]")
147-
'face face)))
147+
(ement-propertize (or name canonical-alias "[unnamed]")
148+
'face face)))
148149

149150
(ement-directory-define-column "Alias" (:max-width 25)
150151
(pcase-let (((map ('canonical_alias alias)) item))
@@ -419,8 +420,8 @@ SPACE may be a room ID or an `ement-room' struct."
419420
;; TODO: Use space's alias where possible.
420421
:buffer-name (format "*Ement Directory: space %s" (ement--format-room space session))
421422
:root-section-name (format "*Ement Directory: rooms in %s %s"
422-
(propertize "space"
423-
'face 'font-lock-type-face)
423+
(ement-propertize "space"
424+
'face 'font-lock-type-face)
424425
(ement--format-room space session))
425426
:init-fn (lambda ()
426427
(setf (alist-get 'session ement-directory-etc) session

ement-macros.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,30 @@ BODY may begin with property list arguments, including:
228228
ement-session session)))
229229
,@body)))
230230

231+
(defmacro ement-propertize (string &rest properties)
232+
"Like `propertize', but auto-set `font-lock-face' property.
233+
If the `face' property is set, also set the `font-lock-face' property to
234+
the same value."
235+
;; This is a workaround for a change in `magit-section'; see
236+
;; <https://github.com/alphapapa/ement.el/issues/331>. By setting both face properties,
237+
;; we should preserve backward compatibility. Someday this can be removed and we'll
238+
;; just call `propertize' again.
239+
(declare (indent defun))
240+
(when (and (member ''face properties)
241+
(not (member ''font-lock-face properties)))
242+
(pcase (plist-get properties ''face #'equal)
243+
((or (pred atom) `(quote ,(pred atom)))
244+
`(propertize ,string ,@properties
245+
'font-lock-face ,(plist-get properties ''face #'equal)))
246+
(_
247+
;; Avoid evaluating the 'face property's form twice.
248+
(let ((value-form (plist-get properties ''face #'equal))
249+
(value-var (gensym "ement-propertize-")))
250+
(setf (plist-get properties ''face #'equal) value-var
251+
(plist-get properties ''font-lock-face #'equal) value-var)
252+
`(let ((,value-var ,value-form))
253+
(propertize ,string ,@properties)))))))
254+
231255
;;;; Variables
232256

233257

ement-room-list.el

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ from recent to non-recent for rooms updated in the past hour."
254254
(ement-room-list-define-key people ()
255255
(pcase-let ((`[,room ,session] item))
256256
(when (ement--room-direct-p room session)
257-
(propertize "People" 'face 'ement-room-list-direct))))
257+
(ement-propertize "People" 'face 'ement-room-list-direct))))
258258

259259
(ement-room-list-define-key space (&key name id)
260260
(pcase-let* ((`[,room ,session] item)
@@ -285,7 +285,7 @@ from recent to non-recent for rooms updated in the past hour."
285285
(_
286286
;; TODO: How to handle this better? (though it should be very rare)
287287
(string-join (mapcar #'format-space parents) ", "))))))
288-
(propertize key 'face 'ement-room-list-space)))))
288+
(ement-propertize key 'face 'ement-room-list-space)))))
289289

290290
(ement-room-list-define-key space-p ()
291291
"Groups rooms that are themselves spaces."
@@ -355,7 +355,7 @@ from recent to non-recent for rooms updated in the past hour."
355355
:then #'identity
356356
(pcase-let ((`[,room ,_session] item))
357357
(when (ement--room-favourite-p room)
358-
(propertize "Favourite" 'face 'ement-room-list-favourite))))
358+
(ement-propertize "Favourite" 'face 'ement-room-list-favourite))))
359359

360360
(ement-room-list-define-key low-priority ()
361361
:then #'identity
@@ -462,10 +462,10 @@ from recent to non-recent for rooms updated in the past hour."
462462
(push 'ement-room-list-invited (map-elt face :inherit)))
463463
('leave
464464
(push 'ement-room-list-left (map-elt face :inherit))))
465-
(propertize display-name
466-
'face face
467-
'mouse-face 'highlight
468-
'keymap ement-room-list-button-map))
465+
(ement-propertize display-name
466+
'face face
467+
'mouse-face 'highlight
468+
'keymap ement-room-list-button-map))
469469
"")))
470470

471471
(ement-room-list-define-column #("Unread" 0 6 (help-echo "Unread events (Notifications:Highlights)")) (:align 'right)
@@ -475,13 +475,13 @@ from recent to non-recent for rooms updated in the past hour."
475475
(and (equal 0 notification_count)
476476
(equal 0 highlight_count)))
477477
""
478-
(concat (propertize (number-to-string notification_count)
479-
'face (if (zerop highlight_count)
480-
'default
481-
'ement-room-mention))
478+
(concat (ement-propertize (number-to-string notification_count)
479+
'face (if (zerop highlight_count)
480+
'default
481+
'ement-room-mention))
482482
":"
483-
(propertize (number-to-string highlight_count)
484-
'face 'highlight)))))
483+
(ement-propertize (number-to-string highlight_count)
484+
'face 'highlight)))))
485485

486486
(ement-room-list-define-column "Latest" ()
487487
(pcase-let ((`[,(cl-struct ement-room latest-ts) ,_session] item))
@@ -498,8 +498,9 @@ from recent to non-recent for rooms updated in the past hour."
498498
(face (list :foreground (elt ement-room-list-timestamp-colors n)))
499499
(formatted-ts (ement--human-format-duration difference-seconds 'abbreviate)))
500500
(string-match (rx (1+ digit) (repeat 1 alpha)) formatted-ts)
501-
(propertize (match-string 0 formatted-ts) 'face face
502-
'help-echo formatted-ts))
501+
(ement-propertize (match-string 0 formatted-ts)
502+
'face face
503+
'help-echo formatted-ts))
503504
"")))
504505

505506
(ement-room-list-define-column "Topic" (:max-width 35)
@@ -508,11 +509,11 @@ from recent to non-recent for rooms updated in the past hour."
508509
(when topic
509510
(setf topic (replace-regexp-in-string "\n" " " topic 'fixedcase 'literal)))
510511
(pcase status
511-
('invite (concat (propertize "[invited]"
512-
'face 'ement-room-list-invited)
512+
('invite (concat (ement-propertize "[invited]"
513+
'face 'ement-room-list-invited)
513514
" " topic))
514-
('leave (concat (propertize "[left]"
515-
'face 'ement-room-list-left)
515+
('leave (concat (ement-propertize "[left]"
516+
'face 'ement-room-list-left)
516517
" " topic))
517518
(_ (or topic "")))))
518519

0 commit comments

Comments
 (0)