Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id D1BA3431FBC for ; Tue, 16 Feb 2010 01:10:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.187 X-Spam-Level: X-Spam-Status: No, score=-2.187 tagged_above=-999 required=5 tests=[AWL=0.412, BAYES_00=-2.599] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tJmK+IW+zLQM for ; Tue, 16 Feb 2010 01:10:43 -0800 (PST) Received: from mail-ew0-f222.google.com (mail-ew0-f222.google.com [209.85.219.222]) by olra.theworths.org (Postfix) with ESMTP id D4CC9431FAE for ; Tue, 16 Feb 2010 01:10:42 -0800 (PST) Received: by ewy22 with SMTP id 22so713045ewy.30 for ; Tue, 16 Feb 2010 01:10:42 -0800 (PST) Received: by 10.213.96.221 with SMTP id i29mr1180553ebn.99.1266311441701; Tue, 16 Feb 2010 01:10:41 -0800 (PST) Received: from aw.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1]) by mx.google.com with ESMTPS id 24sm17121947eyx.46.2010.02.16.01.10.40 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Feb 2010 01:10:41 -0800 (PST) Received: by aw.hh.sledj.net (Postfix, from userid 1000) id ABA037007C; Tue, 16 Feb 2010 09:10:23 +0000 (GMT) To: notmuch From: David Edmondson Date: Tue, 16 Feb 2010 09:10:23 +0000 Message-ID: <87hbph5yww.fsf@aw.hh.sledj.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Subject: [notmuch] [rfc] improved wrapping of long lines X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2010 09:10:44 -0000 --=-=-= It's annoying that the wrapping of long lines doesn't respect the indentation of the message. Here's an attempt to improve that. The wrapping code is in a separate file and has a silly name[1], but all of that is subject to change at the whim of Carl or his minions. If anyone tries this then I'd be interested in your feedback, particularly if it doesn't work or doesn't look the way that you expect. Footnotes: [1] It's a long-line wrapper... --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-notmuch.el-Improved-wrapping-of-long-lines-respect-t.patch >From d49ff05ef86b652ec4883d7075df4fb65c846342 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Tue, 16 Feb 2010 09:03:18 +0000 Subject: [PATCH] notmuch.el: Improved wrapping of long lines - respect the indentation level. --- Makefile.local | 2 +- notmuch-coolj.el | 40 ++++++++++++++++++++++++++++++++++++++++ notmuch.el | 9 ++++++--- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 notmuch-coolj.el diff --git a/Makefile.local b/Makefile.local index 04bac83..44a786a 100644 --- a/Makefile.local +++ b/Makefile.local @@ -1,4 +1,4 @@ -emacs: notmuch.elc +emacs: notmuch.elc notmuch-coolj.el notmuch_client_srcs = \ $(notmuch_compat_srcs) \ diff --git a/notmuch-coolj.el b/notmuch-coolj.el new file mode 100644 index 0000000..6b4da6d --- /dev/null +++ b/notmuch-coolj.el @@ -0,0 +1,40 @@ +(defgroup notmuch-coolj nil + "Automatic wrapping of long lines when displaying notmuch articles." + :group 'notmuch) + +(defcustom notmuch-coolj-prefix-regexp " *\\(>+ +\\)?" + "A regexp matching potential line prefixes.") + +(defun notmuch-coolj-wrap-region (beg end) + "Wrap lines in the region." + (goto-char beg) + (forward-line -1) + (while (not (>= (point) end)) + (notmuch-coolj-wrap-line) + (forward-line))) + +(defun notmuch-coolj-wrap-line () + "Wrap the current line, if necessary." + (let ((prefix (notmuch-coolj-determine-prefix)) + (start (point)) + (end (make-marker)) + (width (window-width))) + (set-marker end (save-excursion (end-of-line) (point))) + (while (> end (+ (point) width)) + (forward-char (window-width)) + (if (re-search-backward "[^ ]\\( \\)" start t) + (progn + (goto-char (match-beginning 1)) + (insert-before-markers ?\n) + (re-search-forward "\\( +\\)[^ ]" nil t) + (delete-region (match-beginning 1) (match-end 1)) + (backward-char 1) + (insert-before-markers prefix))) + (beginning-of-line)))) + +(defun notmuch-coolj-determine-prefix () + "Determine the prefix for the current line." + (if (looking-at notmuch-coolj-prefix-regexp) + (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) + +(provide 'notmuch-coolj) diff --git a/notmuch.el b/notmuch.el index ea74a72..d67b066 100644 --- a/notmuch.el +++ b/notmuch.el @@ -51,6 +51,8 @@ (require 'mm-view) (require 'message) +(require 'notmuch-coolj) + (defvar notmuch-show-mode-map (let ((map (make-sparse-keymap))) (define-key map "?" 'notmuch-help) @@ -777,7 +779,9 @@ is what to put on the button." (mm-display-part mime-message)))) ) (if (equal mime-type "text/plain") - (notmuch-show-markup-citations-region beg end depth)) + (progn + (notmuch-show-markup-citations-region beg end depth) + (notmuch-coolj-wrap-region beg end))) ; Advance to the next part (if any) (so the outer loop can ; determine whether we've left the current message. (if (re-search-forward notmuch-show-buttonize-begin-regexp nil t) @@ -1053,8 +1057,7 @@ All currently available key bindings: ; Make show mode a bit prettier, highlighting URLs and using word wrap (defun notmuch-show-pretty-hook () - (goto-address-mode 1) - (visual-line-mode)) + (goto-address-mode 1)) (add-hook 'notmuch-show-hook 'notmuch-show-pretty-hook) (add-hook 'notmuch-search-hook -- 1.6.6.1 --=-=-= dme. -- David Edmondson, http://dme.org --=-=-=--