From 2dcd1e7234f9dd50ec41c7b09297f002c6572a86 Mon Sep 17 00:00:00 2001 From: Pieter Praet Date: Wed, 1 Feb 2012 14:50:00 +0100 Subject: emacs: globally replace non-branching "(if COND (progn ..." with "(when ..." Less code, same results, without sacrificing readability. --- emacs/notmuch-wash.el | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'emacs/notmuch-wash.el') diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index 5c1e830..67143e5 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -336,30 +336,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))))) ;; -- cgit v1.2.3 From 8281430558c1b2eafc847620cd84f5ce40bf6741 Mon Sep 17 00:00:00 2001 From: Dmitry Kurochkin Date: Sat, 4 Feb 2012 11:36:37 +0400 Subject: emacs: fix `notmuch-wash-region-to-button' to work at beginning of buffer `Notmuch-wash-region-to-button' is the function that creates hidden regions with buttons for signatures, citations and original messages. Before the change, it did not work correctly if the to-be-hidden region started at the beginning of a message: the visibility toggle button was hidden as well. The patch fixes this. There are two parts in the fix: * Use `insert-before-markers' instead of `insert' for creating the button, so that it does not get added to the hidden overlay. * Stop using PREFIX argument for adding a newline before the button. The newline should not be added before a button at the beginning of buffer. The corresponding test is fixed now. --- emacs/notmuch-wash.el | 24 ++++++++++++++---------- test/emacs-show | 1 - 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'emacs/notmuch-wash.el') diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index 67143e5..56981d0 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -136,12 +136,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 +161,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 +181,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 +198,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 +212,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")))))) ;; diff --git a/test/emacs-show b/test/emacs-show index 9800575..5700d2e 100755 --- a/test/emacs-show +++ b/test/emacs-show @@ -4,7 +4,6 @@ test_description="Testing emacs notmuch-show view" . test-lib.sh test_begin_subtest "Hiding Original Message region at beginning of a message" -test_subtest_known_broken message_id='OriginalMessageHiding.1@notmuchmail.org' add_message \ [id]="$message_id" \ -- cgit v1.2.3 From 88b922afdce6944d0f17d8cdf42372dfee8561c3 Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Fri, 17 Feb 2012 19:34:44 +0100 Subject: emacs: Add configurable wrapping width for notmuch-wash-wrap-long-lines This introduces a variable to control after how many characters a line is wrapped by notmuch-wash-wrap-long-lines (still wrapping at the window width if it is lower). --- emacs/notmuch-wash.el | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'emacs/notmuch-wash.el') diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index 56981d0..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) @@ -276,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)))) ;; -- cgit v1.2.3