[PATCH] emacs: Improved printing support.
authorDavid Edmondson <dme@dme.org>
Tue, 3 Jan 2012 14:12:26 +0000 (14:12 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:34 +0000 (09:41 -0800)
64/88b7967835eeccc6e7b61497a82479f76b38de [new file with mode: 0644]

diff --git a/64/88b7967835eeccc6e7b61497a82479f76b38de b/64/88b7967835eeccc6e7b61497a82479f76b38de
new file mode 100644 (file)
index 0000000..eb24eb6
--- /dev/null
@@ -0,0 +1,257 @@
+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 A7B62429E21\r
+       for <notmuch@notmuchmail.org>; Tue,  3 Jan 2012 06:12:36 -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 9zxfH4lJxgla for <notmuch@notmuchmail.org>;\r
+       Tue,  3 Jan 2012 06:12:35 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+       [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 5736D431FD0\r
+       for <notmuch@notmuchmail.org>; Tue,  3 Jan 2012 06:12:35 -0800 (PST)\r
+Received: by wibhq2 with SMTP id hq2so10819131wib.26\r
+       for <notmuch@notmuchmail.org>; Tue, 03 Jan 2012 06:12:32 -0800 (PST)\r
+Received: by 10.180.96.72 with SMTP id dq8mr113778815wib.10.1325599952094;\r
+       Tue, 03 Jan 2012 06:12:32 -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\r
+       fv13sm22624432wbb.21.2012.01.03.06.12.30\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 03 Jan 2012 06:12:30 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id A43AAA05D6; Tue,  3 Jan 2012 14:12:27 +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: Tue,  3 Jan 2012 14:12:26 +0000\r
+Message-Id: <1325599946-5936-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1325240897-27525-1-git-send-email-dme@dme.org>\r
+References: <1325240897-27525-1-git-send-email-dme@dme.org>\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: Tue, 03 Jan 2012 14:12:36 -0000\r
+\r
+Add various functions to print notmuch messages and tie them together\r
+with a simple frontend. No keybinding is currently made to encourage\r
+paper saving.\r
+---\r
+\r
+Fix the lack of shell quoting for muttprint. Rename the ps-print\r
+buffers to have a relevant name.\r
+\r
+ emacs/Makefile.local   |    3 +-\r
+ emacs/notmuch-print.el |   79 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch-show.el  |   51 +++++++++++++++++++++++++++++++\r
+ 3 files changed, 132 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..d4b7ed4\r
+--- /dev/null\r
++++ b/emacs/notmuch-print.el\r
+@@ -0,0 +1,79 @@\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
++(defmacro notmuch-print-with-file (filename &rest body)\r
++  `(with-temp-buffer\r
++     (insert-file-contents ,filename)\r
++     (set-buffer-modified-p nil)\r
++     ,@body))\r
++\r
++(defun notmuch-print-lpr (filename msg)\r
++  (notmuch-print-with-file filename\r
++                         (lpr-buffer)))\r
++\r
++(defun notmuch-print-ps-print (filename msg)\r
++  (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
++    (notmuch-print-with-file filename\r
++                           (rename-buffer subject t)\r
++                           (ps-print-buffer))))\r
++\r
++(defun notmuch-print-ps-print/evince (filename msg)\r
++  (let ((ps-file (make-temp-file "notmuch"))\r
++      (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
++    (notmuch-print-with-file filename\r
++                           (rename-buffer subject t)\r
++                           (ps-print-buffer ps-file)\r
++                           (async-shell-command (concat "evince " ps-file)))))\r
++\r
++(defun notmuch-print-muttprint (filename msg)\r
++  (shell-command\r
++   (concat "muttprint "\r
++         "--file " (shell-quote-argument filename) " "\r
++         ;; Show the tags.\r
++         "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/'")))\r
++\r
++(defun notmuch-print-muttprint/evince (filename msg)\r
++  (let ((ps-file (make-temp-file "notmuch")))\r
++    (call-process-shell-command\r
++     (concat "muttprint "\r
++           "--file " (shell-quote-argument filename) " "\r
++           ;; Show the tags.\r
++           "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/' "\r
++           "--printer 'TO_FILE:" (shell-quote-argument ps-file) "'"))\r
++    (async-shell-command (concat "evince " ps-file))))\r
++\r
++(defun notmuch-print-message (filename msg)\r
++  (funcall notmuch-print-mechanism filename msg))\r
++\r
++;;\r
++\r
++(provide 'notmuch-print)\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 5502efd..55ccfc5 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,51 @@ 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 function `fn' to a text representation of the current\r
++message."\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 '(lambda (tag) tag) tags ", ") "\n")\r
++                  "")))\r
++       (all (buffer-substring (notmuch-show-message-top)\r
++                              (notmuch-show-message-bottom)))\r
++\r
++       (file (make-temp-file "notmuch")))\r
++    (with-temp-file file\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 file (notmuch-show-get-message-properties))\r
++    (delete-file file)))\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
+@@ -760,6 +806,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
+@@ -1111,6 +1159,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