1 Return-Path: <dme@dme.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 2CCE8431FBC
\r
6 for <notmuch@notmuchmail.org>; Tue, 16 Feb 2010 05:36:24 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.244 tagged_above=-999 required=5 tests=[AWL=0.355,
\r
12 BAYES_00=-2.599] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id q8CzRtX00a8J for <notmuch@notmuchmail.org>;
\r
16 Tue, 16 Feb 2010 05:36:22 -0800 (PST)
\r
17 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.158])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 5B723431FAE
\r
19 for <notmuch@notmuchmail.org>; Tue, 16 Feb 2010 05:36:22 -0800 (PST)
\r
20 Received: by fg-out-1718.google.com with SMTP id l26so661340fgb.2
\r
21 for <notmuch@notmuchmail.org>; Tue, 16 Feb 2010 05:36:21 -0800 (PST)
\r
22 Received: by 10.87.35.15 with SMTP id n15mr11596976fgj.14.1266327381284;
\r
23 Tue, 16 Feb 2010 05:36:21 -0800 (PST)
\r
24 Received: from aw.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])
\r
25 by mx.google.com with ESMTPS id e20sm2416549fga.25.2010.02.16.05.36.19
\r
26 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
27 Tue, 16 Feb 2010 05:36:20 -0800 (PST)
\r
28 Received: by aw.hh.sledj.net (Postfix, from userid 1000)
\r
29 id 98ECC3A005; Tue, 16 Feb 2010 13:36:02 +0000 (GMT)
\r
30 To: notmuch <notmuch@notmuchmail.org>
\r
31 In-Reply-To: <87hbph5yww.fsf@aw.hh.sledj.net>
\r
32 References: <87hbph5yww.fsf@aw.hh.sledj.net>
\r
33 From: David Edmondson <dme@dme.org>
\r
34 Date: Tue, 16 Feb 2010 13:36:02 +0000
\r
35 Message-ID: <87d4055mm5.fsf@aw.hh.sledj.net>
\r
37 Content-Type: multipart/mixed; boundary="=-=-="
\r
38 Subject: Re: [notmuch] [rfc] improved wrapping of long lines
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Tue, 16 Feb 2010 13:36:24 -0000
\r
55 On Tue, 16 Feb 2010 09:10:23 +0000, David Edmondson <dme@dme.org> wrote:
\r
56 > It's annoying that the wrapping of long lines doesn't respect the
\r
57 > indentation of the message. Here's an attempt to improve that.
\r
59 > The wrapping code is in a separate file and has a silly name[1], but all
\r
60 > of that is subject to change at the whim of Carl or his minions.
\r
62 > If anyone tries this then I'd be interested in your feedback,
\r
63 > particularly if it doesn't work or doesn't look the way that you expect.
\r
66 > [1] It's a long-line wrapper...
\r
68 Here's a better version, derived from longlines.el.
\r
72 Content-Type: text/x-diff
\r
73 Content-Disposition: inline;
\r
74 filename=0001-notmuch.el-Improved-wrapping-of-long-lines-respect-t.patch
\r
76 >From 0fc142a4e8fd4b8648bfdf2246759af1fc31c997 Mon Sep 17 00:00:00 2001
\r
77 From: David Edmondson <dme@dme.org>
\r
78 Date: Tue, 16 Feb 2010 13:34:29 +0000
\r
79 Subject: [PATCH] notmuch.el: Improved wrapping of long lines - respect the indentation
\r
83 Makefile.local | 8 ++-
\r
84 coolj.el | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
86 3 files changed, 156 insertions(+), 5 deletions(-)
\r
87 create mode 100644 coolj.el
\r
89 diff --git a/Makefile.local b/Makefile.local
\r
90 index 04bac83..0a1f203 100644
\r
91 --- a/Makefile.local
\r
92 +++ b/Makefile.local
\r
95 +# -*- mode:makefile -*-
\r
97 +emacs: notmuch.elc coolj.elc
\r
99 notmuch_client_srcs = \
\r
100 $(notmuch_compat_srcs) \
\r
101 @@ -42,6 +44,8 @@ install-emacs: install emacs
\r
103 install -m0644 notmuch.el $(DESTDIR)$(emacs_lispdir)
\r
104 install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)
\r
105 + install -m0644 coolj.el $(DESTDIR)$(emacs_lispdir)
\r
106 + install -m0644 coolj.elc $(DESTDIR)$(emacs_lispdir)
\r
109 install -d $(DESTDIR)$(desktop_dir)
\r
110 @@ -58,4 +62,4 @@ install-zsh:
\r
111 $(DESTDIR)$(zsh_completion_dir)/notmuch
\r
113 SRCS := $(SRCS) $(notmuch_client_srcs)
\r
114 -CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz
\r
115 +CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc notmuch.1.gz
\r
116 diff --git a/coolj.el b/coolj.el
\r
117 new file mode 100644
\r
118 index 0000000..77187dc
\r
122 +;;; coolj.el --- automatically wrap long lines -*- coding:utf-8 -*-
\r
124 +;; Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
\r
126 +;; Authors: Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
\r
127 +;; Alex Schroeder <alex@gnu.org>
\r
128 +;; Chong Yidong <cyd@stupidchicken.com>
\r
129 +;; Maintainer: David Edmondson <dme@dme.org>
\r
130 +;; Keywords: convenience, wp
\r
132 +;; This file is not part of GNU Emacs.
\r
134 +;; GNU Emacs is free software: you can redistribute it and/or modify
\r
135 +;; it under the terms of the GNU General Public License as published by
\r
136 +;; the Free Software Foundation, either version 3 of the License, or
\r
137 +;; (at your option) any later version.
\r
139 +;; GNU Emacs is distributed in the hope that it will be useful,
\r
140 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
141 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
142 +;; GNU General Public License for more details.
\r
144 +;; You should have received a copy of the GNU General Public License
\r
145 +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
\r
149 +;;; This is a simple derivative of some functionality from
\r
150 +;;; `longlines.el'. The key difference is that this version will
\r
151 +;;; insert a prefix at the head of each wrapped line. The prefix is
\r
152 +;;; calculated from the originating long line.
\r
154 +;;; No minor-mode is provided, the caller is expected to call
\r
155 +;;; `coolj-wrap-region' to wrap the region of interest.
\r
159 +(defgroup coolj nil
\r
160 + "Wrapping of long lines with prefix."
\r
163 +(defcustom coolj-wrap-follows-window-size t
\r
164 + "Non-nil means wrap text to the window size.
\r
165 +Otherwise respect `fill-column'."
\r
169 +(defcustom coolj-line-prefix-regexp "^ *\\(>+ \\)*"
\r
170 + "Regular expression that matches line prefixes."
\r
174 +(defvar coolj-wrap-point nil)
\r
176 +(make-variable-buffer-local 'coolj-wrap-point)
\r
178 +(defun coolj-determine-prefix ()
\r
179 + "Determine the prefix for the current line."
\r
181 + (beginning-of-line)
\r
182 + (if (re-search-forward coolj-line-prefix-regexp nil t)
\r
183 + (buffer-substring (match-beginning 0) (match-end 0))
\r
186 +(defun coolj-wrap-buffer ()
\r
187 + "Wrap the current buffer."
\r
188 + (coolj-wrap-region (point-min) (point-max)))
\r
190 +(defun coolj-wrap-region (beg end)
\r
191 + "Wrap each successive line, starting with the line before BEG.
\r
192 +Stop when we reach lines after END that don't need wrapping, or the
\r
193 +end of the buffer."
\r
194 + (setq fill-column (if coolj-wrap-follows-window-size
\r
197 + (let ((mod (buffer-modified-p)))
\r
198 + (setq coolj-wrap-point (point))
\r
200 + (forward-line -1)
\r
201 + ;; Two successful coolj-wrap-line's in a row mean successive
\r
202 + ;; lines don't need wrapping.
\r
203 + (while (null (and (coolj-wrap-line)
\r
205 + (and (>= (point) end)
\r
206 + (coolj-wrap-line))))))
\r
207 + (goto-char coolj-wrap-point)
\r
208 + (set-buffer-modified-p mod)))
\r
210 +(defun coolj-wrap-line ()
\r
211 + "If the current line needs to be wrapped, wrap it and return nil.
\r
212 +If wrapping is performed, point remains on the line. If the line does
\r
213 +not need to be wrapped, move point to the next line and return t."
\r
214 + (let ((prefix (coolj-determine-prefix)))
\r
215 + (if (coolj-set-breakpoint prefix)
\r
217 + (insert-before-markers ?\n)
\r
218 + (backward-char 1)
\r
221 + (insert-before-markers prefix)
\r
226 +(defun coolj-set-breakpoint (prefix)
\r
227 + "Place point where we should break the current line, and return t.
\r
228 +If the line should not be broken, return nil; point remains on the
\r
230 + (move-to-column fill-column)
\r
231 + (if (and (re-search-forward "[^ ]" (line-end-position) 1)
\r
232 + (> (current-column) fill-column))
\r
233 + ;; This line is too long. Can we break it?
\r
234 + (or (coolj-find-break-backward prefix)
\r
235 + (progn (move-to-column fill-column)
\r
236 + (coolj-find-break-forward)))))
\r
238 +(defun coolj-find-break-backward (prefix)
\r
239 + "Move point backward to the first available breakpoint and return t.
\r
240 +If no breakpoint is found, return nil."
\r
241 + (let ((end-of-prefix (+ (line-beginning-position) (length prefix))))
\r
242 + (and (search-backward " " end-of-prefix 1)
\r
244 + (skip-chars-backward " " end-of-prefix)
\r
246 + (progn (forward-char 1)
\r
247 + (if (and fill-nobreak-predicate
\r
248 + (run-hook-with-args-until-success
\r
249 + 'fill-nobreak-predicate))
\r
250 + (progn (skip-chars-backward " " end-of-prefix)
\r
251 + (coolj-find-break-backward prefix))
\r
254 +(defun coolj-find-break-forward ()
\r
255 + "Move point forward to the first available breakpoint and return t.
\r
256 +If no break point is found, return nil."
\r
257 + (and (search-forward " " (line-end-position) 1)
\r
258 + (progn (skip-chars-forward " " (line-end-position))
\r
260 + (if (and fill-nobreak-predicate
\r
261 + (run-hook-with-args-until-success
\r
262 + 'fill-nobreak-predicate))
\r
263 + (coolj-find-break-forward)
\r
267 diff --git a/notmuch.el b/notmuch.el
\r
268 index ea74a72..8ff82ee 100644
\r
277 (defvar notmuch-show-mode-map
\r
278 (let ((map (make-sparse-keymap)))
\r
279 @@ -777,7 +778,9 @@ is what to put on the button."
\r
280 (mm-display-part mime-message))))
\r
282 (if (equal mime-type "text/plain")
\r
283 - (notmuch-show-markup-citations-region beg end depth))
\r
285 + (coolj-wrap-region beg end)
\r
286 + (notmuch-show-markup-citations-region beg end depth)))
\r
287 ; Advance to the next part (if any) (so the outer loop can
\r
288 ; determine whether we've left the current message.
\r
289 (if (re-search-forward notmuch-show-buttonize-begin-regexp nil t)
\r
290 @@ -1053,8 +1056,7 @@ All currently available key bindings:
\r
291 ; Make show mode a bit prettier, highlighting URLs and using word wrap
\r
293 (defun notmuch-show-pretty-hook ()
\r
294 - (goto-address-mode 1)
\r
295 - (visual-line-mode))
\r
296 + (goto-address-mode 1))
\r
298 (add-hook 'notmuch-show-hook 'notmuch-show-pretty-hook)
\r
299 (add-hook 'notmuch-search-hook
\r
309 David Edmondson, http://dme.org
\r