aboutsummaryrefslogtreecommitdiff
path: root/emacs/notmuch-wash.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/notmuch-wash.el')
-rw-r--r--emacs/notmuch-wash.el107
1 files changed, 63 insertions, 44 deletions
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 5c1e830..7d003a2 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -87,6 +87,14 @@ If there is one more line than the sum of
`notmuch-wash-citation-lines-suffix', show that, otherwise
collapse the remaining lines into a button.")
+(defvar notmuch-wash-wrap-lines-length nil
+ "Wrap line after at most this many characters.
+
+If this is nil, lines in messages will be wrapped to fit in the
+current window. If this is a number, lines will be wrapped after
+this many characters or at the window width (whichever one is
+lower).")
+
(defun notmuch-wash-toggle-invisible-action (cite-button)
(let ((invis-spec (button-get cite-button 'invisibility-spec)))
(if (invisible-p invis-spec)
@@ -136,12 +144,13 @@ collapse the remaining lines into a button.")
(lines-count (count-lines (overlay-start overlay) (overlay-end overlay))))
(format label-format lines-count)))
-(defun notmuch-wash-region-to-button (msg beg end type prefix)
+(defun notmuch-wash-region-to-button (msg beg end type &optional prefix)
"Auxiliary function to do the actual making of overlays and buttons
BEG and END are buffer locations. TYPE should a string, either
-\"citation\" or \"signature\". PREFIX is some arbitrary text to
-insert before the button, probably for indentation."
+\"citation\" or \"signature\". Optional PREFIX is some arbitrary
+text to insert before the button, probably for indentation. Note
+that PREFIX should not include a newline."
;; This uses some slightly tricky conversions between strings and
;; symbols because of the way the button code works. Note that
@@ -160,12 +169,15 @@ insert before the button, probably for indentation."
(overlay-put overlay 'type type)
(goto-char (1+ end))
(save-excursion
- (goto-char (1- beg))
- (insert prefix)
- (insert-button (notmuch-wash-button-label overlay)
+ (goto-char beg)
+ (if prefix
+ (insert-before-markers prefix))
+ (let ((button-beg (point)))
+ (insert-before-markers (notmuch-wash-button-label overlay) "\n")
+ (make-button button-beg (1- (point))
'invisibility-spec invis-spec
'overlay overlay
- :type button-type))))
+ :type button-type)))))
(defun notmuch-wash-excerpt-citations (msg depth)
"Excerpt citations and up to one signature."
@@ -177,7 +189,7 @@ insert before the button, probably for indentation."
(msg-end (point-max))
(msg-lines (count-lines msg-start msg-end)))
(notmuch-wash-region-to-button
- msg msg-start msg-end "original" "\n")))
+ msg msg-start msg-end "original")))
(while (and (< (point) (point-max))
(re-search-forward notmuch-wash-citation-regexp nil t))
(let* ((cite-start (match-beginning 0))
@@ -194,7 +206,7 @@ insert before the button, probably for indentation."
(forward-line (- notmuch-wash-citation-lines-suffix))
(notmuch-wash-region-to-button
msg hidden-start (point-marker)
- "citation" "\n")))))
+ "citation")))))
(if (and (not (eobp))
(re-search-forward notmuch-wash-signature-regexp nil t))
(let* ((sig-start (match-beginning 0))
@@ -208,7 +220,7 @@ insert before the button, probably for indentation."
(overlay-put (make-overlay sig-start-marker sig-end-marker) 'face 'message-cited-text)
(notmuch-wash-region-to-button
msg sig-start-marker sig-end-marker
- "signature" "\n"))))))
+ "signature"))))))
;;
@@ -272,16 +284,24 @@ Perform several transformations on the message body:
;;
(defun notmuch-wash-wrap-long-lines (msg depth)
- "Wrap any long lines in the message to the width of the window.
-
-When doing so, maintaining citation leaders in the wrapped text."
-
- (let ((coolj-wrap-follows-window-size nil)
- (fill-column (- (window-width)
- depth
- ;; 2 to avoid poor interaction with
- ;; `word-wrap'.
- 2)))
+ "Wrap long lines in the message.
+
+If `notmuch-wash-wrap-lines-length' is a number, this will wrap
+the message lines to the minimum of the width of the window or
+its value. Otherwise, this function will wrap long lines in the
+message at the window width. When doing so, citation leaders in
+the wrapped text are maintained."
+
+ (let* ((coolj-wrap-follows-window-size nil)
+ (limit (if (numberp notmuch-wash-wrap-lines-length)
+ (min notmuch-wash-wrap-lines-length
+ (window-width))
+ (window-width)))
+ (fill-column (- limit
+ depth
+ ;; 2 to avoid poor interaction with
+ ;; `word-wrap'.
+ 2)))
(coolj-wrap-region (point-min) (point-max))))
;;
@@ -336,30 +356,29 @@ patch and then guesses the extent of the patch, there is scope
for error."
(goto-char (point-min))
- (if (re-search-forward diff-file-header-re nil t)
- (progn
- (beginning-of-line -1)
- (let ((patch-start (point))
- (patch-end (point-max))
- part)
- (goto-char patch-start)
- (if (or
- ;; Patch ends with signature.
- (re-search-forward notmuch-wash-signature-regexp nil t)
- ;; Patch ends with bugtraq comment.
- (re-search-forward "^\\*\\*\\* " nil t))
- (setq patch-end (match-beginning 0)))
- (save-restriction
- (narrow-to-region patch-start patch-end)
- (setq part (plist-put part :content-type "inline-patch-fake-part"))
- (setq part (plist-put part :content (buffer-string)))
- (setq part (plist-put part :id -1))
- (setq part (plist-put part :filename
- (notmuch-wash-subject-to-patch-filename
- (plist-get
- (plist-get msg :headers) :Subject))))
- (delete-region (point-min) (point-max))
- (notmuch-show-insert-bodypart nil part depth))))))
+ (when (re-search-forward diff-file-header-re nil t)
+ (beginning-of-line -1)
+ (let ((patch-start (point))
+ (patch-end (point-max))
+ part)
+ (goto-char patch-start)
+ (if (or
+ ;; Patch ends with signature.
+ (re-search-forward notmuch-wash-signature-regexp nil t)
+ ;; Patch ends with bugtraq comment.
+ (re-search-forward "^\\*\\*\\* " nil t))
+ (setq patch-end (match-beginning 0)))
+ (save-restriction
+ (narrow-to-region patch-start patch-end)
+ (setq part (plist-put part :content-type "inline-patch-fake-part"))
+ (setq part (plist-put part :content (buffer-string)))
+ (setq part (plist-put part :id -1))
+ (setq part (plist-put part :filename
+ (notmuch-wash-subject-to-patch-filename
+ (plist-get
+ (plist-get msg :headers) :Subject))))
+ (delete-region (point-min) (point-max))
+ (notmuch-show-insert-bodypart nil part depth)))))
;;