Re: [notmuch] [rfc] improved wrapping of long lines
authorDavid Edmondson <dme@dme.org>
Tue, 16 Feb 2010 13:36:02 +0000 (13:36 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:12 +0000 (09:36 -0800)
a6/7c46a9054fc9a688aefbdb93772aa6eb416fec [new file with mode: 0644]

diff --git a/a6/7c46a9054fc9a688aefbdb93772aa6eb416fec b/a6/7c46a9054fc9a688aefbdb93772aa6eb416fec
new file mode 100644 (file)
index 0000000..a00eeec
--- /dev/null
@@ -0,0 +1,311 @@
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2CCE8431FBC\r
+       for <notmuch@notmuchmail.org>; Tue, 16 Feb 2010 05:36:24 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.244\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.244 tagged_above=-999 required=5 tests=[AWL=0.355,\r
+       BAYES_00=-2.599] autolearn=ham\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id q8CzRtX00a8J for <notmuch@notmuchmail.org>;\r
+       Tue, 16 Feb 2010 05:36:22 -0800 (PST)\r
+Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.158])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5B723431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 16 Feb 2010 05:36:22 -0800 (PST)\r
+Received: by fg-out-1718.google.com with SMTP id l26so661340fgb.2\r
+       for <notmuch@notmuchmail.org>; Tue, 16 Feb 2010 05:36:21 -0800 (PST)\r
+Received: by 10.87.35.15 with SMTP id n15mr11596976fgj.14.1266327381284;\r
+       Tue, 16 Feb 2010 05:36:21 -0800 (PST)\r
+Received: from aw.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])\r
+       by mx.google.com with ESMTPS id e20sm2416549fga.25.2010.02.16.05.36.19\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Tue, 16 Feb 2010 05:36:20 -0800 (PST)\r
+Received: by aw.hh.sledj.net (Postfix, from userid 1000)\r
+       id 98ECC3A005; Tue, 16 Feb 2010 13:36:02 +0000 (GMT)\r
+To: notmuch <notmuch@notmuchmail.org>\r
+In-Reply-To: <87hbph5yww.fsf@aw.hh.sledj.net>\r
+References: <87hbph5yww.fsf@aw.hh.sledj.net>\r
+From: David Edmondson <dme@dme.org>\r
+Date: Tue, 16 Feb 2010 13:36:02 +0000\r
+Message-ID: <87d4055mm5.fsf@aw.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+Subject: Re: [notmuch] [rfc] improved wrapping of long lines\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 16 Feb 2010 13:36:24 -0000\r
+\r
+--=-=-=\r
+\r
+On Tue, 16 Feb 2010 09:10:23 +0000, David Edmondson <dme@dme.org> wrote:\r
+> It's annoying that the wrapping of long lines doesn't respect the\r
+> indentation of the message. Here's an attempt to improve that.\r
+> \r
+> The wrapping code is in a separate file and has a silly name[1], but all\r
+> of that is subject to change at the whim of Carl or his minions.\r
+> \r
+> If anyone tries this then I'd be interested in your feedback,\r
+> particularly if it doesn't work or doesn't look the way that you expect.\r
+> \r
+> Footnotes: \r
+> [1]  It's a long-line wrapper...\r
+\r
+Here's a better version, derived from longlines.el.\r
+\r
+\r
+--=-=-=\r
+Content-Type: text/x-diff\r
+Content-Disposition: inline;\r
+ filename=0001-notmuch.el-Improved-wrapping-of-long-lines-respect-t.patch\r
+\r
+>From 0fc142a4e8fd4b8648bfdf2246759af1fc31c997 Mon Sep 17 00:00:00 2001\r
+From: David Edmondson <dme@dme.org>\r
+Date: Tue, 16 Feb 2010 13:34:29 +0000\r
+Subject: [PATCH] notmuch.el: Improved wrapping of long lines - respect the indentation\r
+ level.\r
+\r
+---\r
+ Makefile.local |    8 ++-\r
+ coolj.el       |  145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch.el     |    8 ++-\r
+ 3 files changed, 156 insertions(+), 5 deletions(-)\r
+ create mode 100644 coolj.el\r
+\r
+diff --git a/Makefile.local b/Makefile.local\r
+index 04bac83..0a1f203 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -1,4 +1,6 @@\r
+-emacs: notmuch.elc\r
++# -*- mode:makefile -*-\r
++\r
++emacs: notmuch.elc coolj.elc\r
\r
+ notmuch_client_srcs =         \\r
+       $(notmuch_compat_srcs)  \\r
+@@ -42,6 +44,8 @@ install-emacs: install emacs\r
+       done ;\r
+       install -m0644 notmuch.el $(DESTDIR)$(emacs_lispdir)\r
+       install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)\r
++      install -m0644 coolj.el $(DESTDIR)$(emacs_lispdir)\r
++      install -m0644 coolj.elc $(DESTDIR)$(emacs_lispdir)\r
\r
+ install-desktop:\r
+       install -d $(DESTDIR)$(desktop_dir)\r
+@@ -58,4 +62,4 @@ install-zsh:\r
+               $(DESTDIR)$(zsh_completion_dir)/notmuch\r
\r
+ SRCS  := $(SRCS) $(notmuch_client_srcs)\r
+-CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz\r
++CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc notmuch.1.gz\r
+diff --git a/coolj.el b/coolj.el\r
+new file mode 100644\r
+index 0000000..77187dc\r
+--- /dev/null\r
++++ b/coolj.el\r
+@@ -0,0 +1,145 @@\r
++;;; coolj.el --- automatically wrap long lines  -*- coding:utf-8 -*-\r
++\r
++;; Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.\r
++\r
++;; Authors:    Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>\r
++;;             Alex Schroeder <alex@gnu.org>\r
++;;             Chong Yidong <cyd@stupidchicken.com>\r
++;; Maintainer: David Edmondson <dme@dme.org>\r
++;; Keywords: convenience, wp\r
++\r
++;; This file is not part of GNU Emacs.\r
++\r
++;; GNU Emacs is free software: you can redistribute it and/or modify\r
++;; it under the terms of the GNU General Public License as published by\r
++;; the Free Software Foundation, either version 3 of the License, or\r
++;; (at your option) any later version.\r
++\r
++;; GNU Emacs is distributed in the hope that it will be useful,\r
++;; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++;; GNU General Public License for more details.\r
++\r
++;; You should have received a copy of the GNU General Public License\r
++;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.\r
++\r
++;;; Commentary:\r
++\r
++;;; This is a simple derivative of some functionality from\r
++;;; `longlines.el'. The key difference is that this version will\r
++;;; insert a prefix at the head of each wrapped line. The prefix is\r
++;;; calculated from the originating long line.\r
++\r
++;;; No minor-mode is provided, the caller is expected to call\r
++;;; `coolj-wrap-region' to wrap the region of interest.\r
++\r
++;;; Code:\r
++\r
++(defgroup coolj nil\r
++  "Wrapping of long lines with prefix."\r
++  :group 'fill)\r
++\r
++(defcustom coolj-wrap-follows-window-size t\r
++  "Non-nil means wrap text to the window size.\r
++Otherwise respect `fill-column'."\r
++  :group 'coolj\r
++  :type 'boolean)\r
++\r
++(defcustom coolj-line-prefix-regexp "^ *\\(>+ \\)*"\r
++  "Regular expression that matches line prefixes."\r
++  :group 'coolj\r
++  :type 'regexp)\r
++\r
++(defvar coolj-wrap-point nil)\r
++\r
++(make-variable-buffer-local 'coolj-wrap-point)\r
++\r
++(defun coolj-determine-prefix ()\r
++  "Determine the prefix for the current line."\r
++  (save-excursion\r
++    (beginning-of-line)\r
++    (if (re-search-forward coolj-line-prefix-regexp nil t)\r
++      (buffer-substring (match-beginning 0) (match-end 0))\r
++      "")))\r
++\r
++(defun coolj-wrap-buffer ()\r
++  "Wrap the current buffer."\r
++  (coolj-wrap-region (point-min) (point-max)))\r
++\r
++(defun coolj-wrap-region (beg end)\r
++  "Wrap each successive line, starting with the line before BEG.\r
++Stop when we reach lines after END that don't need wrapping, or the\r
++end of the buffer."\r
++  (setq fill-column (if coolj-wrap-follows-window-size\r
++                      (window-width)\r
++                    fill-column))\r
++  (let ((mod (buffer-modified-p)))\r
++    (setq coolj-wrap-point (point))\r
++    (goto-char beg)\r
++    (forward-line -1)\r
++    ;; Two successful coolj-wrap-line's in a row mean successive\r
++    ;; lines don't need wrapping.\r
++    (while (null (and (coolj-wrap-line)\r
++                    (or (eobp)\r
++                        (and (>= (point) end)\r
++                             (coolj-wrap-line))))))\r
++    (goto-char coolj-wrap-point)\r
++    (set-buffer-modified-p mod)))\r
++\r
++(defun coolj-wrap-line ()\r
++  "If the current line needs to be wrapped, wrap it and return nil.\r
++If wrapping is performed, point remains on the line.  If the line does\r
++not need to be wrapped, move point to the next line and return t."\r
++  (let ((prefix (coolj-determine-prefix)))\r
++    (if (coolj-set-breakpoint prefix)\r
++      (progn\r
++        (insert-before-markers ?\n)\r
++        (backward-char 1)\r
++        (delete-char -1)\r
++        (forward-char 1)\r
++        (insert-before-markers prefix)\r
++        nil)\r
++      (forward-line 1)\r
++      t)))\r
++\r
++(defun coolj-set-breakpoint (prefix)\r
++  "Place point where we should break the current line, and return t.\r
++If the line should not be broken, return nil; point remains on the\r
++line."\r
++  (move-to-column fill-column)\r
++  (if (and (re-search-forward "[^ ]" (line-end-position) 1)\r
++           (> (current-column) fill-column))\r
++      ;; This line is too long.  Can we break it?\r
++      (or (coolj-find-break-backward prefix)\r
++          (progn (move-to-column fill-column)\r
++                 (coolj-find-break-forward)))))\r
++\r
++(defun coolj-find-break-backward (prefix)\r
++  "Move point backward to the first available breakpoint and return t.\r
++If no breakpoint is found, return nil."\r
++  (let ((end-of-prefix (+ (line-beginning-position) (length prefix))))\r
++    (and (search-backward " " end-of-prefix 1)\r
++       (save-excursion\r
++         (skip-chars-backward " " end-of-prefix)\r
++         (null (bolp)))\r
++       (progn (forward-char 1)\r
++              (if (and fill-nobreak-predicate\r
++                       (run-hook-with-args-until-success\r
++                        'fill-nobreak-predicate))\r
++                  (progn (skip-chars-backward " " end-of-prefix)\r
++                         (coolj-find-break-backward prefix))\r
++                t)))))\r
++\r
++(defun coolj-find-break-forward ()\r
++  "Move point forward to the first available breakpoint and return t.\r
++If no break point is found, return nil."\r
++  (and (search-forward " " (line-end-position) 1)\r
++       (progn (skip-chars-forward " " (line-end-position))\r
++              (null (eolp)))\r
++       (if (and fill-nobreak-predicate\r
++                (run-hook-with-args-until-success\r
++                 'fill-nobreak-predicate))\r
++           (coolj-find-break-forward)\r
++         t)))\r
++\r
++(provide 'coolj)\r
+diff --git a/notmuch.el b/notmuch.el\r
+index ea74a72..8ff82ee 100644\r
+--- a/notmuch.el\r
++++ b/notmuch.el\r
+@@ -50,6 +50,7 @@\r
+ (require 'cl)\r
+ (require 'mm-view)\r
+ (require 'message)\r
++(require 'coolj)\r
\r
+ (defvar notmuch-show-mode-map\r
+   (let ((map (make-sparse-keymap)))\r
+@@ -777,7 +778,9 @@ is what to put on the button."\r
+                           (mm-display-part mime-message))))\r
+                 )\r
+             (if (equal mime-type "text/plain")\r
+-                (notmuch-show-markup-citations-region beg end depth))\r
++                (progn\r
++                  (coolj-wrap-region beg end)\r
++                  (notmuch-show-markup-citations-region beg end depth)))\r
+               ; Advance to the next part (if any) (so the outer loop can\r
+               ; determine whether we've left the current message.\r
+               (if (re-search-forward notmuch-show-buttonize-begin-regexp nil t)\r
+@@ -1053,8 +1056,7 @@ All currently available key bindings:\r
+ ; Make show mode a bit prettier, highlighting URLs and using word wrap\r
\r
+ (defun notmuch-show-pretty-hook ()\r
+-  (goto-address-mode 1)\r
+-  (visual-line-mode))\r
++  (goto-address-mode 1))\r
\r
+ (add-hook 'notmuch-show-hook 'notmuch-show-pretty-hook)\r
+ (add-hook 'notmuch-search-hook\r
+-- \r
+1.6.6.1\r
+\r
+\r
+--=-=-=\r
+\r
+\r
+dme.\r
+-- \r
+David Edmondson, http://dme.org\r
+\r
+--=-=-=--\r