alphapapa / alphapapa/ement.el

(ement-room--render-html): Prefer shr-external-rendering-functions over cl-letf

オープン
#104 コメント 3 件 リアクション 0 件 担当者 1 名 @alphapapa が担当を希望しています GitHub で見る
compatibility enhancement priority:C
主要言語
Emacs Lisp
スター
604
フォーク
54
PR マージ指標
30日以内にマージされた PR はありません

説明

shr-external-rendering-functions exists to override how shr renders
HTML on a tag-by-tag case; this is used by eww in eww-display-html.
Using this variable is much cleaner than the cl-letf approach and
comes with the added bonus of having ement-specific rendering
functions variable allowing the user to modify how the HTML is
rendered. E.g., the user could override how the bold face is
rendering by saying

```
(defun ement-room-tag-b (dom)
(insert "*")
(shr-generic dom)
(insert "*"))

(push (cons 'b #'ement-room-tag-b) ement-room-rendering-functions)
```

If the intention of the binding ((symbol-function 'shr-fill-line) #'ignore) is
to make shr not break lines, then the diff to make
ement-room--render-html use shr-external-rendering-functions is at the
end.
AFAICT, when let-binding shr-max-width, the replies are indented
properly when using IRC-style with margins.

```
diff --git a/ement-room.el b/ement-room.el
index 1c7666e..9c9c2ec 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -3242,17 +3242,18 @@ HTML is rendered to Emacs text using `shr-insert-document'."
;; resized (i.e. the wrapping is adjusted automatically by redisplay
;; rather than requiring the message to be re-rendered to HTML).
(let ((shr-use-fonts ement-room-shr-use-fonts)
- (old-fn (symbol-function 'shr-tag-blockquote))) ;; Bind to a var to avoid unknown-function linting errors.
- (cl-letf (((symbol-function 'shr-fill-line) #'ignore)
- ((symbol-function 'shr-tag-blockquote)
- (lambda (dom)
- (let ((beg (point-marker)))
- (funcall old-fn dom)
- (add-text-properties beg (point-max)
- '(wrap-prefix " "
- line-prefix " "))))))
- (shr-insert-document
- (libxml-parse-html-region (point-min) (point-max))))))
+ (shr-max-width nil)
+ (shr-external-rendering-functions
+ (append shr-external-rendering-functions
+ `((blockquote
+ . ,(lambda (dom)
+ (let ((beg (point-marker)))
+ (shr-tag-blockquote dom)
+ (add-text-properties beg (point-max)
+ '(wrap-prefix " "
+ line-prefix " ")))))))))
+ (shr-insert-document
+ (libxml-parse-html-region (point-min) (point-max)))))
(string-trim (buffer-substring (point) (point-max)))))

(cl-defun ement-room--event-mentions-user-p (event user &optional (room ement-room))
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。