summaryrefslogtreecommitdiff
path: root/.gnus
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2024-01-07 23:37:00 +0100
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2024-01-08 00:03:28 +0100
commitf9226f2dd0cf05fe7ff69bfe1b2cefa516c8c4f5 (patch)
tree49b3e70b7600a786319c31ed0873f47f0464c16e /.gnus
parent44fbf0a42d69ec2d6bfb04412179e926ec003f5f (diff)
downloaddotfiles-f9226f2dd0cf05fe7ff69bfe1b2cefa516c8c4f5.tar.xz
Make Gnus leverage visual-line-mode
Set shr-fill-text to nil; this automatically causes eww to enable visual-line-mode. For Gnus, the dance is a bit more involved. Not 100% happy with where I landed, but at least I gave myself an escape hatch by rebinding C-c d v in summary buffers. Also, * lift size restriction when fontifying citations: it mostly only ever causes fontification failures when people review big patches, * tweak header order slightly, * align shr heading faces with eighters-title-* faces.
Diffstat (limited to '.gnus')
-rw-r--r--.gnus95
1 files changed, 85 insertions, 10 deletions
diff --git a/.gnus b/.gnus
index 8472771..37a17af 100644
--- a/.gnus
+++ b/.gnus
@@ -56,6 +56,7 @@
(t
. "%F"))
;; Articles.
+ gnus-cite-parse-max-size nil
gnus-header-face-alist
'(("From" nil gnus-header-from)
("Subject" nil gnus-header-subject)
@@ -67,20 +68,26 @@
;; What, when.
"^Subject:" "^Summary:" "^Keywords:" "^Date:"
;; Who.
- "^From:" "^Followup-To:" "^To:" "^Cc:" "^Newsgroups:" "^Organization:")
- gnus-treat-display-smileys nil)
+ "^From:" "^Organization:" "^Followup-To:" "^To:" "^Cc:" "^Newsgroups:")
+ gnus-treat-display-smileys nil
+ ;; Do not fill anything; let visual-line-mode wrap text.
+ gnus-article-unfold-long-headers t
+ gnus-treat-fill-article nil
+ gnus-treat-fill-long-lines nil
+ gnus-treat-fold-headers nil)
+
+;;; Summary tweaks.
+
+(defun my/gnus-toggle-article-wrap ()
+ (interactive)
+ (with-current-buffer gnus-article-buffer
+ (visual-line-mode 'toggle)))
(add-hook 'gnus-summary-mode-hook
(lambda ()
(setq fill-column 120)
- (my/centered-mode)))
-(add-hook 'gnus-article-mode-hook
- (lambda ()
- (setq fill-column 80
- my/centered-set-right-margin t)
- (my/centered-mode)))
-
-;;; Summary tweaks.
+ (my/centered-mode)
+ (keymap-local-set "C-c d v" 'my/gnus-toggle-article-wrap)))
;; message-subject-re-regexp is used both in Gnus summary buffers to
;; detect and elide similar subjects in a thread, and by message mode
@@ -119,6 +126,74 @@
(setq gnus-summary-to-prefix sent-prefix
gnus-summary-newsgroup-prefix sent-prefix))
+;;; Article tweaks.
+
+(defun my/gnus-article-has-html ()
+ (seq-some
+ (lambda (handle)
+ (and (listp handle)
+ (string= (mm-handle-media-type handle) "text/html")))
+ gnus-article-mime-handles))
+
+(defun my/gnus-article-should-wrap ()
+ (save-excursion
+ (message-goto-body)
+ (let ((should-wrap nil)
+ (has-html (my/gnus-article-has-html)))
+ (while-let (((not should-wrap))
+ ((not (eobp)))
+ (current-line (thing-at-point 'line)))
+ (setq should-wrap
+ (and
+ ;; The line is bigger than the target width.
+ (> (length current-line) fill-column)
+ ;; The line is not boring (citation, diff addition/removal).
+ (not (string-match-p "\\`[>+-]" current-line))
+ ;; Lines that start with spaces are boring, unless this
+ ;; is an HTML part: those are choked with <table> tags
+ ;; that shr left-pads with spaces.
+ ;; NB: HAS-HTML is a naive heuristic: we are assuming
+ ;; that "any text/html part is present" means "we are
+ ;; looking at this text/html part".
+ (or (not (string-match-p "\\` " current-line)) has-html)))
+ (forward-line))
+ should-wrap)))
+
+;; Keep article buffer centered; enable visual-line-mode when it helps
+;; (long lines that are not part of citations nor patches).
+;;
+;; Use article-prepare hook instead of article-mode hook to ensure
+;; visual-line-mode will be set and effectively clear truncate-lines.
+;;
+;; The sequence goes like this: gnus-article-prepare first calls
+;; gnus-article-setup-buffer, which
+;;
+;; (1) sets truncate-lines from gnus-article-truncate-lines,
+;; (2) calls gnus-article-mode, which runs gnus-article-mode-hook.
+;;
+;; But then gnus-article-prepare calls gnus-display-mime, which may
+;; end up calling mm-shr, which *might* end up calling shr-tag-table,
+;; which unconditionally turns truncate-lines back on.
+;;
+;; Then gnus-article-prepare runs gnus-article-prepare-hook: that's
+;; our cue to run visual-line-mode, which will set truncate-lines back
+;; *off*.
+;;
+;; eww does not have this problem because it checks shr-fill-text &
+;; turns visual-line-mode "late enough"; though the display of tables
+;; remains less than ideal since rows are wrapped. Ideally
+;; shr-tag-table should switch to an alternative layout when
+;; shr-fill-text is nil.
+
+(defun my/gnus-article-setup ()
+ (setq fill-column 80
+ my/centered-set-right-margin t)
+ (my/centered-mode)
+ (when (my/gnus-article-should-wrap)
+ (visual-line-mode)))
+
+(add-hook 'gnus-article-prepare-hook 'my/gnus-article-setup)
+
;;; Key bindings.
;;
;; m compose