--- /dev/null
+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 190AB429E5F\r
+ for <notmuch@notmuchmail.org>; Wed, 18 Jan 2012 00:00:32 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 x4IGnAyRk7X4 for <notmuch@notmuchmail.org>;\r
+ Wed, 18 Jan 2012 00:00:27 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+ [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 755CB429E27\r
+ for <notmuch@notmuchmail.org>; Wed, 18 Jan 2012 00:00:27 -0800 (PST)\r
+Received: by werp13 with SMTP id p13so1165800wer.26\r
+ for <notmuch@notmuchmail.org>; Wed, 18 Jan 2012 00:00:26 -0800 (PST)\r
+Received: by 10.216.131.91 with SMTP id l69mr5897649wei.28.1326873626115;\r
+ Wed, 18 Jan 2012 00:00:26 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+ (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+ by mx.google.com with ESMTPS id bj10sm21031695wib.9.2012.01.18.00.00.23\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Wed, 18 Jan 2012 00:00:24 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+ id 8AFDCA0397; Wed, 18 Jan 2012 08:00:22 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: =?UTF-8?q?=5BPATCH=5D=20emacs=3A=20Improved=20printing=20support=2E?=\r
+Date: Wed, 18 Jan 2012 08:00:21 +0000\r
+Message-Id: <1326873621-1701-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <m2vcobbaol.fsf@gmail.com>\r
+References: <m2vcobbaol.fsf@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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: Wed, 18 Jan 2012 08:00:32 -0000\r
+\r
+Add various functions to print notmuch messages and tie them together\r
+with a simple frontend.\r
+\r
+Add a binding ('#') in `notmuch-show-mode' to print the current\r
+message.\r
+---\r
+\r
+Updates based on Aaron's review - the comments were very useful in\r
+improving things - thanks!\r
+\r
+Add a keybinding to `notmuch-show-mode'.\r
+\r
+ emacs/Makefile.local | 3 +-\r
+ emacs/notmuch-print.el | 85 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch-show.el | 53 ++++++++++++++++++++++++++++++\r
+ 3 files changed, 140 insertions(+), 1 deletions(-)\r
+ create mode 100644 emacs/notmuch-print.el\r
+\r
+diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
+index 0c58b82..4fee0e8 100644\r
+--- a/emacs/Makefile.local\r
++++ b/emacs/Makefile.local\r
+@@ -13,7 +13,8 @@ emacs_sources := \\r
+ $(dir)/notmuch-maildir-fcc.el \\r
+ $(dir)/notmuch-message.el \\r
+ $(dir)/notmuch-crypto.el \\r
+- $(dir)/coolj.el\r
++ $(dir)/coolj.el \\r
++ $(dir)/notmuch-print.el\r
+ \r
+ emacs_images := \\r
+ $(srcdir)/$(dir)/notmuch-logo.png\r
+diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el\r
+new file mode 100644\r
+index 0000000..77f10bb\r
+--- /dev/null\r
++++ b/emacs/notmuch-print.el\r
+@@ -0,0 +1,85 @@\r
++;; notmuch-print.el --- printing messages from notmuch.\r
++;;\r
++;; Copyright © David Edmondson\r
++;;\r
++;; This file is part of Notmuch.\r
++;;\r
++;; Notmuch is free software: you can redistribute it and/or modify it\r
++;; 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
++;; Notmuch is distributed in the hope that it will be useful, but\r
++;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
++;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
++;; General Public License for more details.\r
++;;\r
++;; You should have received a copy of the GNU General Public License\r
++;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.\r
++;;\r
++;; Authors: David Edmondson <dme@dme.org>\r
++\r
++(defcustom notmuch-print-mechanism 'notmuch-print-lpr\r
++ "How should printing be done?"\r
++ :group 'notmuch\r
++ :type '(choice\r
++ (function :tag "Use lpr" notmuch-print-lpr)\r
++ (function :tag "Use ps-print" notmuch-print-ps-print)\r
++ (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)\r
++ (function :tag "Use muttprint" notmuch-print-muttprint)\r
++ (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)\r
++ (function :tag "Using a custom function")))\r
++\r
++;; Utility functions:\r
++\r
++(defun notmuch-print-run-evince (file)\r
++ "View FILE using 'evince'."\r
++ (start-process "evince" nil "evince" file))\r
++\r
++(defun notmuch-print-run-muttprint (&optional output)\r
++ "Pass the contents of the current buffer to 'muttprint'.\r
++\r
++Optional OUTPUT allows passing a list of flags to muttprint."\r
++ (apply #'call-process-region (point-min) (point-max)\r
++ ;; Reads from stdin.\r
++ "muttprint"\r
++ nil nil nil\r
++ ;; Show the tags.\r
++ "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"\r
++ output))\r
++\r
++;; User-visible functions:\r
++\r
++(defun notmuch-print-lpr (msg)\r
++ "Print a message buffer using lpr."\r
++ (lpr-buffer))\r
++\r
++(defun notmuch-print-ps-print (msg)\r
++ "Print a message buffer using the ps-print package."\r
++ (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
++ (rename-buffer subject t)\r
++ (ps-print-buffer)))\r
++\r
++(defun notmuch-print-ps-print/evince (msg)\r
++ "Preview a message buffer using ps-print and evince."\r
++ (let ((ps-file (make-temp-file "notmuch"))\r
++ (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
++ (rename-buffer subject t)\r
++ (ps-print-buffer ps-file)\r
++ (notmuch-print-run-evince ps-file)))\r
++\r
++(defun notmuch-print-muttprint (msg)\r
++ "Print a message using muttprint."\r
++ (notmuch-print-run-muttprint))\r
++ \r
++(defun notmuch-print-muttprint/evince (msg)\r
++ "Preview a message buffer using muttprint and evince."\r
++ (let ((ps-file (make-temp-file "notmuch")))\r
++ (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))\r
++ (notmuch-print-run-evince ps-file)))\r
++\r
++(defun notmuch-print-message (msg)\r
++ "Print a message using the user-selected mechanism."\r
++ (funcall notmuch-print-mechanism msg))\r
++\r
++(provide 'notmuch-print)\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 797f94b..db25565 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -34,6 +34,7 @@\r
+ (require 'notmuch-wash)\r
+ (require 'notmuch-mua)\r
+ (require 'notmuch-crypto)\r
++(require 'notmuch-print)\r
+ \r
+ (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
+ (declare-function notmuch-fontify-headers "notmuch" nil)\r
+@@ -186,6 +187,52 @@ indentation."\r
+ mm-handle (> (notmuch-count-attachments mm-handle) 1))))\r
+ (message "Done"))\r
+ \r
++(defun notmuch-show-with-message-as-text (fn)\r
++ "Apply FN to a text representation of the current message.\r
++\r
++FN is called with one argument, the message properties. It should\r
++operation on the contents of the current buffer."\r
++\r
++ ;; Remake the header to ensure that all information is available.\r
++ (let* ((to (notmuch-show-get-to))\r
++ (cc (notmuch-show-get-cc))\r
++ (from (notmuch-show-get-from))\r
++ (subject (notmuch-show-get-subject))\r
++ (date (notmuch-show-get-date))\r
++ (tags (notmuch-show-get-tags))\r
++ (depth (notmuch-show-get-depth))\r
++\r
++ (header (concat\r
++ "Subject: " subject "\n"\r
++ "To: " to "\n"\r
++ (if (not (string= cc ""))\r
++ (concat "Cc: " cc "\n")\r
++ "")\r
++ "From: " from "\n"\r
++ "Date: " date "\n"\r
++ (if tags\r
++ (concat "Tags: "\r
++ (mapconcat #'identity tags ", ") "\n")\r
++ "")))\r
++ (all (buffer-substring (notmuch-show-message-top)\r
++ (notmuch-show-message-bottom)))\r
++\r
++ (props (notmuch-show-get-message-properties)))\r
++ (with-temp-buffer\r
++ (insert all)\r
++ (indent-rigidly (point-min) (point-max) (- depth))\r
++ ;; Remove the original header.\r
++ (goto-char (point-min))\r
++ (re-search-forward "^$" (point-max) nil)\r
++ (delete-region (point-min) (point))\r
++ (insert header)\r
++ (funcall fn props))))\r
++\r
++(defun notmuch-show-print-message ()\r
++ "Print the current message."\r
++ (interactive)\r
++ (notmuch-show-with-message-as-text 'notmuch-print-message))\r
++\r
+ (defun notmuch-show-fontify-header ()\r
+ (let ((face (cond\r
+ ((looking-at "[Tt]o:")\r
+@@ -757,6 +804,8 @@ current buffer, if possible."\r
+ (overlay-put headers-overlay 'priority 10))\r
+ (overlay-put (make-overlay body-start body-end) 'invisible message-invis-spec)\r
+ \r
++ (plist-put msg :depth depth)\r
++\r
+ ;; Save the properties for this message. Currently this saves the\r
+ ;; entire message (augmented it with other stuff), which seems\r
+ ;; like overkill. We might save a reduced subset (for example, not\r
+@@ -947,6 +996,7 @@ thread id. If a prefix is given, crypto processing is toggled."\r
+ (define-key map " " 'notmuch-show-advance-and-archive)\r
+ (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)\r
+ (define-key map (kbd "RET") 'notmuch-show-toggle-message)\r
++ (define-key map "#" 'notmuch-show-print-message)\r
+ map)\r
+ "Keymap for \"notmuch show\" buffers.")\r
+ (fset 'notmuch-show-mode-map notmuch-show-mode-map)\r
+@@ -1107,6 +1157,9 @@ Some useful entries are:\r
+ (defun notmuch-show-get-to ()\r
+ (notmuch-show-get-header :To))\r
+ \r
++(defun notmuch-show-get-depth ()\r
++ (notmuch-show-get-prop :depth))\r
++\r
+ (defun notmuch-show-set-tags (tags)\r
+ "Set the tags of the current message."\r
+ (notmuch-show-set-prop :tags tags)\r
+-- \r
+1.7.7.3\r
+\r