]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-wash.el
emacs: Shorten long lines
[notmuch] / emacs / notmuch-wash.el
index a76b4f5b589ab0d0f1ada7ced2bc024e31a5b91b..3a9ffdd0daf75af50deb80504ffeae9ee98410ff 100644 (file)
@@ -1,4 +1,4 @@
-;; notmuch-wash.el --- cleaning up message bodies
+;;; notmuch-wash.el --- cleaning up message bodies
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
 ;; General Public License for more details.
 ;;
 ;; You should have received a copy of the GNU General Public License
-;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
+;; along with Notmuch.  If not, see <https://www.gnu.org/licenses/>.
 ;;
 ;; Authors: Carl Worth <cworth@cworth.org>
 ;;          David Edmondson <dme@dme.org>
 
+;;; Code:
+
 (require 'coolj)
+(require 'notmuch-lib)
 
-(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth &optional hide))
+(declare-function notmuch-show-insert-bodypart "notmuch-show"
+                 (msg part depth &optional hide))
+(defvar notmuch-show-indent-messages-width)
 
 ;;
 
@@ -119,8 +124,8 @@ collapse the remaining lines into a button."
 
 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)."
+this many characters (ignoring indentation due to thread depth)
+or at the window width (whichever one is lower)."
   :type '(choice (const :tag "window width" nil)
                 (integer :tag "number of characters"))
   :group 'notmuch-wash)
@@ -183,13 +188,16 @@ message parts."
   (let* ((type (overlay-get overlay 'type))
         (invis-spec (overlay-get overlay 'invisible))
         (state (if (invisible-p invis-spec) "hidden" "visible"))
-        (label-format (symbol-value (intern-soft (concat "notmuch-wash-button-"
-                                                         type "-" state "-format"))))
-        (lines-count (count-lines (overlay-start overlay) (overlay-end overlay))))
+        (label-format (symbol-value
+                       (intern-soft
+                        (format "notmuch-wash-button-%s-%s-format"
+                                type state))))
+        (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 &optional prefix)
-  "Auxiliary function to do the actual making of overlays and buttons
+  "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\". Optional PREFIX is some arbitrary
@@ -235,7 +243,8 @@ that PREFIX should not include a newline."
     (let* ((cite-start (match-beginning 0))
           (cite-end (match-end 0))
           (cite-lines (count-lines cite-start cite-end)))
-      (overlay-put (make-overlay cite-start cite-end) 'face 'notmuch-wash-cited-text)
+      (overlay-put (make-overlay cite-start cite-end)
+                  'face 'notmuch-wash-cited-text)
       (when (> cite-lines (+ notmuch-wash-citation-lines-prefix
                             notmuch-wash-citation-lines-suffix
                             1))
@@ -257,7 +266,8 @@ that PREFIX should not include a newline."
                  (sig-end-marker (make-marker)))
              (set-marker sig-start-marker sig-start)
              (set-marker sig-end-marker (point-max))
-             (overlay-put (make-overlay sig-start-marker sig-end-marker) 'face 'message-cited-text)
+             (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"))))))
@@ -333,12 +343,13 @@ message at the window width. When doing so, citation leaders in
 the wrapped text are maintained."
 
   (let* ((coolj-wrap-follows-window-size nil)
+        (indent (* depth notmuch-show-indent-messages-width))
         (limit (if (numberp notmuch-wash-wrap-lines-length)
-                   (min notmuch-wash-wrap-lines-length
+                   (min (+ notmuch-wash-wrap-lines-length indent)
                         (window-width))
                  (window-width)))
         (fill-column (- limit
-                        depth
+                        indent
                         ;; 2 to avoid poor interaction with
                         ;; `word-wrap'.
                         2)))
@@ -423,3 +434,5 @@ for error."
 ;;
 
 (provide 'notmuch-wash)
+
+;;; notmuch-wash.el ends here