2021-01-10 15:00:47 +01:00
|
|
|
;;; notmuch-print.el --- printing messages from notmuch -*- lexical-binding: t -*-
|
2012-01-18 09:00:21 +01:00
|
|
|
;;
|
|
|
|
;; Copyright © David Edmondson
|
|
|
|
;;
|
|
|
|
;; This file is part of Notmuch.
|
|
|
|
;;
|
|
|
|
;; Notmuch is free software: you can redistribute it and/or modify it
|
|
|
|
;; under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; Notmuch is distributed in the hope that it will be useful, but
|
|
|
|
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;; General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2016-06-02 18:26:14 +02:00
|
|
|
;; along with Notmuch. If not, see <https://www.gnu.org/licenses/>.
|
2012-01-18 09:00:21 +01:00
|
|
|
;;
|
|
|
|
;; Authors: David Edmondson <dme@dme.org>
|
|
|
|
|
2016-04-13 09:58:47 +02:00
|
|
|
;;; Code:
|
|
|
|
|
2012-01-30 11:16:01 +01:00
|
|
|
(require 'notmuch-lib)
|
|
|
|
|
2012-01-25 09:52:15 +01:00
|
|
|
(declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Options
|
|
|
|
|
2012-01-18 09:00:21 +01:00
|
|
|
(defcustom notmuch-print-mechanism 'notmuch-print-lpr
|
|
|
|
"How should printing be done?"
|
2012-04-16 04:57:45 +02:00
|
|
|
:group 'notmuch-show
|
2012-01-18 09:00:21 +01:00
|
|
|
:type '(choice
|
|
|
|
(function :tag "Use lpr" notmuch-print-lpr)
|
|
|
|
(function :tag "Use ps-print" notmuch-print-ps-print)
|
|
|
|
(function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)
|
|
|
|
(function :tag "Use muttprint" notmuch-print-muttprint)
|
|
|
|
(function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
|
|
|
|
(function :tag "Using a custom function")))
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Utility functions
|
2012-01-18 09:00:21 +01:00
|
|
|
|
|
|
|
(defun notmuch-print-run-evince (file)
|
|
|
|
"View FILE using 'evince'."
|
|
|
|
(start-process "evince" nil "evince" file))
|
|
|
|
|
|
|
|
(defun notmuch-print-run-muttprint (&optional output)
|
|
|
|
"Pass the contents of the current buffer to 'muttprint'.
|
|
|
|
|
|
|
|
Optional OUTPUT allows passing a list of flags to muttprint."
|
|
|
|
(apply #'call-process-region (point-min) (point-max)
|
|
|
|
;; Reads from stdin.
|
|
|
|
"muttprint"
|
|
|
|
nil nil nil
|
|
|
|
;; Show the tags.
|
|
|
|
"--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
|
|
|
|
output))
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; User-visible functions
|
2012-01-18 09:00:21 +01:00
|
|
|
|
2021-01-10 15:00:48 +01:00
|
|
|
(defun notmuch-print-lpr (_msg)
|
2012-01-18 09:00:21 +01:00
|
|
|
"Print a message buffer using lpr."
|
|
|
|
(lpr-buffer))
|
|
|
|
|
|
|
|
(defun notmuch-print-ps-print (msg)
|
|
|
|
"Print a message buffer using the ps-print package."
|
2012-01-30 11:16:01 +01:00
|
|
|
(let ((subject (notmuch-prettify-subject
|
|
|
|
(plist-get (notmuch-show-get-prop :headers msg) :Subject))))
|
2012-01-18 09:00:21 +01:00
|
|
|
(rename-buffer subject t)
|
|
|
|
(ps-print-buffer)))
|
|
|
|
|
|
|
|
(defun notmuch-print-ps-print/evince (msg)
|
|
|
|
"Preview a message buffer using ps-print and evince."
|
2019-01-30 12:15:59 +01:00
|
|
|
(let ((ps-file (make-temp-file "notmuch" nil ".ps"))
|
2012-01-30 11:16:01 +01:00
|
|
|
(subject (notmuch-prettify-subject
|
|
|
|
(plist-get (notmuch-show-get-prop :headers msg) :Subject))))
|
2012-01-18 09:00:21 +01:00
|
|
|
(rename-buffer subject t)
|
|
|
|
(ps-print-buffer ps-file)
|
|
|
|
(notmuch-print-run-evince ps-file)))
|
|
|
|
|
2021-01-10 15:00:48 +01:00
|
|
|
(defun notmuch-print-muttprint (_msg)
|
2012-01-18 09:00:21 +01:00
|
|
|
"Print a message using muttprint."
|
|
|
|
(notmuch-print-run-muttprint))
|
|
|
|
|
2021-01-10 15:00:48 +01:00
|
|
|
(defun notmuch-print-muttprint/evince (_msg)
|
2012-01-18 09:00:21 +01:00
|
|
|
"Preview a message buffer using muttprint and evince."
|
2019-01-30 12:15:59 +01:00
|
|
|
(let ((ps-file (make-temp-file "notmuch" nil ".ps")))
|
2012-01-18 09:00:21 +01:00
|
|
|
(notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
|
|
|
|
(notmuch-print-run-evince ps-file)))
|
|
|
|
|
|
|
|
(defun notmuch-print-message (msg)
|
|
|
|
"Print a message using the user-selected mechanism."
|
2012-01-25 14:48:33 +01:00
|
|
|
(set-buffer-modified-p nil)
|
2012-01-18 09:00:21 +01:00
|
|
|
(funcall notmuch-print-mechanism msg))
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; _
|
|
|
|
|
2012-01-18 09:00:21 +01:00
|
|
|
(provide 'notmuch-print)
|
2016-04-13 09:58:47 +02:00
|
|
|
|
|
|
|
;;; notmuch-print.el ends here
|