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 EF7184196F0 for ; Tue, 27 Apr 2010 03:20:51 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] 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 n3q90oQcyyHY for ; Tue, 27 Apr 2010 03:20:51 -0700 (PDT) Received: from mail-ww0-f53.google.com (mail-ww0-f53.google.com [74.125.82.53]) by olra.theworths.org (Postfix) with ESMTP id BEC78431FC1 for ; Tue, 27 Apr 2010 03:20:50 -0700 (PDT) Received: by wwi18 with SMTP id 18so1081281wwi.26 for ; Tue, 27 Apr 2010 03:20:49 -0700 (PDT) Received: by 10.216.172.71 with SMTP id s49mr2241631wel.195.1272363649413; Tue, 27 Apr 2010 03:20:49 -0700 (PDT) Received: from ut.hh.sledj.net (host83-217-165-81.dsl.vispa.com [83.217.165.81]) by mx.google.com with ESMTPS id v59sm994124wec.15.2010.04.27.03.20.47 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 27 Apr 2010 03:20:48 -0700 (PDT) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 1829359413B; Tue, 27 Apr 2010 11:21:02 +0100 (BST) From: dme@dme.org To: notmuch@notmuchmail.org Subject: [PATCH] emacs/notmuch-wash.el: Add `notmuch-wash-convert-inline-patch-to-part'. Date: Tue, 27 Apr 2010 11:20:58 +0100 Message-Id: <1272363658-24500-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.0 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, 27 Apr 2010 10:20:52 -0000 From: David Edmondson Detect inline patches and convert them to fake attachments, in order that `diff-mode' highlighting can be applied to the patch. This can be enabled by customising `notmuch-show-insert-text/plain-hook'. --- emacs/notmuch-show.el | 3 ++- emacs/notmuch-wash.el | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index eb5335f..4b1baf3 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -71,7 +71,8 @@ any given message." "Functions used to improve the display of text/plain parts." :group 'notmuch :type 'hook - :options '(notmuch-wash-wrap-long-lines + :options '(notmuch-wash-convert-inline-patch-to-part + notmuch-wash-wrap-long-lines notmuch-wash-tidy-citations notmuch-wash-elide-blank-lines notmuch-wash-excerpt-citations)) diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index 57f0cc5..bf0a354 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -23,6 +23,8 @@ (require 'coolj) +(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth) + ;; (defvar notmuch-wash-signature-regexp @@ -231,4 +233,40 @@ When doing so, maintaining citation leaders in the wrapped text." ;; +(require 'diff-mode) + +(defvar diff-file-header-re) ; From `diff-mode.el'. + +(defun notmuch-wash-convert-inline-patch-to-part (depth) + "Convert an inline patch into a fake 'text/x-diff' attachment. + +Given that this function guesses whether a buffer includes a +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 "text/x-diff")) + (setq part (plist-put part :content (buffer-string))) + (setq part (plist-put part :id -1)) + (setq part (plist-put part :filename "inline patch")) + (delete-region (point-min) (point-max)) + (notmuch-show-insert-bodypart nil part depth)))))) + +;; + (provide 'notmuch-wash) -- 1.7.0