config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

notmuch-print.el (3328B)


      1 ;;; notmuch-print.el --- printing messages from notmuch  -*- lexical-binding: t -*-
      2 ;;
      3 ;; Copyright © David Edmondson
      4 ;;
      5 ;; This file is part of Notmuch.
      6 ;;
      7 ;; Notmuch is free software: you can redistribute it and/or modify it
      8 ;; under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation, either version 3 of the License, or
     10 ;; (at your option) any later version.
     11 ;;
     12 ;; Notmuch is distributed in the hope that it will be useful, but
     13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 ;; General Public License for more details.
     16 ;;
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with Notmuch.  If not, see <https://www.gnu.org/licenses/>.
     19 ;;
     20 ;; Authors: David Edmondson <dme@dme.org>
     21 
     22 ;;; Code:
     23 
     24 (require 'notmuch-lib)
     25 
     26 (declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
     27 
     28 ;;; Options
     29 
     30 (defcustom notmuch-print-mechanism 'notmuch-print-lpr
     31   "How should printing be done?"
     32   :group 'notmuch-show
     33   :type '(choice
     34 	  (function :tag "Use lpr" notmuch-print-lpr)
     35 	  (function :tag "Use ps-print" notmuch-print-ps-print)
     36 	  (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)
     37 	  (function :tag "Use muttprint" notmuch-print-muttprint)
     38 	  (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
     39 	  (function :tag "Using a custom function")))
     40 
     41 ;;; Utility functions
     42 
     43 (defun notmuch-print-run-evince (file)
     44   "View FILE using `evince'."
     45   (start-process "evince" nil "evince" file))
     46 
     47 (defun notmuch-print-run-muttprint (&optional output)
     48   "Pass the contents of the current buffer to `muttprint'.
     49 
     50 Optional OUTPUT allows passing a list of flags to muttprint."
     51   (apply #'notmuch--call-process-region (point-min) (point-max)
     52 	 ;; Reads from stdin.
     53 	 "muttprint"
     54 	 nil nil nil
     55 	 ;; Show the tags.
     56 	 "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
     57 	 output))
     58 
     59 ;;; User-visible functions
     60 
     61 (defun notmuch-print-lpr (_msg)
     62   "Print a message buffer using lpr."
     63   (lpr-buffer))
     64 
     65 (defun notmuch-print-ps-print (msg)
     66   "Print a message buffer using the ps-print package."
     67   (let ((subject (notmuch-prettify-subject
     68 		  (plist-get (notmuch-show-get-prop :headers msg) :Subject))))
     69     (rename-buffer subject t)
     70     (ps-print-buffer)))
     71 
     72 (defun notmuch-print-ps-print/evince (msg)
     73   "Preview a message buffer using ps-print and evince."
     74   (let ((ps-file (make-temp-file "notmuch" nil ".ps"))
     75 	(subject (notmuch-prettify-subject
     76 		  (plist-get (notmuch-show-get-prop :headers msg) :Subject))))
     77     (rename-buffer subject t)
     78     (ps-print-buffer ps-file)
     79     (notmuch-print-run-evince ps-file)))
     80 
     81 (defun notmuch-print-muttprint (_msg)
     82   "Print a message using muttprint."
     83   (notmuch-print-run-muttprint))
     84 
     85 (defun notmuch-print-muttprint/evince (_msg)
     86   "Preview a message buffer using muttprint and evince."
     87   (let ((ps-file (make-temp-file "notmuch" nil ".ps")))
     88     (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
     89     (notmuch-print-run-evince ps-file)))
     90 
     91 (defun notmuch-print-message (msg)
     92   "Print a message using the user-selected mechanism."
     93   (set-buffer-modified-p nil)
     94   (funcall notmuch-print-mechanism msg))
     95 
     96 ;;; _
     97 
     98 (provide 'notmuch-print)
     99 
    100 ;;; notmuch-print.el ends here