From 05f4904616b95a17332d7573e44a4aad2dc4033e Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Wed, 18 Jan 2012 08:00:21 +0000 Subject: emacs: Improved printing support. Add various functions to print notmuch messages and tie them together with a simple frontend. Add a binding ('#') in `notmuch-show-mode' to print the current message. one trailing space removed by db. --- emacs/notmuch-print.el | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 emacs/notmuch-print.el (limited to 'emacs/notmuch-print.el') diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el new file mode 100644 index 0000000..f96ccbe --- /dev/null +++ b/emacs/notmuch-print.el @@ -0,0 +1,85 @@ +;; notmuch-print.el --- printing messages from notmuch. +;; +;; 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 +;; along with Notmuch. If not, see . +;; +;; Authors: David Edmondson + +(defcustom notmuch-print-mechanism 'notmuch-print-lpr + "How should printing be done?" + :group 'notmuch + :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"))) + +;; Utility functions: + +(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)) + +;; User-visible functions: + +(defun notmuch-print-lpr (msg) + "Print a message buffer using lpr." + (lpr-buffer)) + +(defun notmuch-print-ps-print (msg) + "Print a message buffer using the ps-print package." + (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subject))) + (rename-buffer subject t) + (ps-print-buffer))) + +(defun notmuch-print-ps-print/evince (msg) + "Preview a message buffer using ps-print and evince." + (let ((ps-file (make-temp-file "notmuch")) + (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject))) + (rename-buffer subject t) + (ps-print-buffer ps-file) + (notmuch-print-run-evince ps-file))) + +(defun notmuch-print-muttprint (msg) + "Print a message using muttprint." + (notmuch-print-run-muttprint)) + +(defun notmuch-print-muttprint/evince (msg) + "Preview a message buffer using muttprint and evince." + (let ((ps-file (make-temp-file "notmuch"))) + (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." + (funcall notmuch-print-mechanism msg)) + +(provide 'notmuch-print) -- cgit v1.2.3 From 76f5da775e21b40aaa654e4a69f64770bb4801bd Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Wed, 25 Jan 2012 08:52:15 +0000 Subject: emacs: Fix a notmuch-print.el compiler warning. `notmuch-show-get-prop' should be declared. --- emacs/notmuch-print.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'emacs/notmuch-print.el') diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el index f96ccbe..fd86288 100644 --- a/emacs/notmuch-print.el +++ b/emacs/notmuch-print.el @@ -19,6 +19,8 @@ ;; ;; Authors: David Edmondson +(declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props)) + (defcustom notmuch-print-mechanism 'notmuch-print-lpr "How should printing be done?" :group 'notmuch -- cgit v1.2.3 From 6f388fa711188813d670aa086f2a6acdbeead69a Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Wed, 25 Jan 2012 13:48:33 +0000 Subject: emacs: Don't mark messages as "unsaved" when printing. `ps-print-buffer' notes that a buffer is unsaved unless `buffer-modified-p' returns `nil', so ensure that it does. --- emacs/notmuch-print.el | 1 + 1 file changed, 1 insertion(+) (limited to 'emacs/notmuch-print.el') diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el index fd86288..880f96d 100644 --- a/emacs/notmuch-print.el +++ b/emacs/notmuch-print.el @@ -82,6 +82,7 @@ Optional OUTPUT allows passing a list of flags to muttprint." (defun notmuch-print-message (msg) "Print a message using the user-selected mechanism." + (set-buffer-modified-p nil) (funcall notmuch-print-mechanism msg)) (provide 'notmuch-print) -- cgit v1.2.3 From 6bd3d8af5431542f352f084b6366e88b98b019a1 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Mon, 30 Jan 2012 10:16:01 +0000 Subject: emacs: Prefer '[No Subject]' to blank subjects. --- emacs/notmuch-lib.el | 9 +++++++++ emacs/notmuch-print.el | 8 ++++++-- emacs/notmuch-show.el | 5 ++++- emacs/notmuch.el | 21 +++++++++------------ 4 files changed, 28 insertions(+), 15 deletions(-) (limited to 'emacs/notmuch-print.el') diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index c906ca7..d315f76 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -133,6 +133,15 @@ the user hasn't set this variable with the old or new value." (interactive) (kill-buffer (current-buffer))) +(defun notmuch-prettify-subject (subject) + ;; This function is used by `notmuch-search-process-filter' which + ;; requires that we not disrupt its' matching state. + (save-match-data + (if (and subject + (string-match "^[ \t]*$" subject)) + "[No Subject]" + subject))) + ;; (defun notmuch-common-do-stash (text) diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el index 880f96d..6653d97 100644 --- a/emacs/notmuch-print.el +++ b/emacs/notmuch-print.el @@ -19,6 +19,8 @@ ;; ;; Authors: David Edmondson +(require 'notmuch-lib) + (declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props)) (defcustom notmuch-print-mechanism 'notmuch-print-lpr @@ -58,14 +60,16 @@ Optional OUTPUT allows passing a list of flags to muttprint." (defun notmuch-print-ps-print (msg) "Print a message buffer using the ps-print package." - (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subject))) + (let ((subject (notmuch-prettify-subject + (plist-get (notmuch-show-get-prop :headers msg) :Subject)))) (rename-buffer subject t) (ps-print-buffer))) (defun notmuch-print-ps-print/evince (msg) "Preview a message buffer using ps-print and evince." (let ((ps-file (make-temp-file "notmuch")) - (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject))) + (subject (notmuch-prettify-subject + (plist-get (notmuch-show-get-prop :headers msg) :Subject)))) (rename-buffer subject t) (ps-print-buffer ps-file) (notmuch-print-run-evince ps-file))) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 0a945ea..3a1a8c8 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -1018,7 +1018,7 @@ buffer." (notmuch-show-next-open-message)) ;; Set the header line to the subject of the first open message. - (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject))) + (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-pretty-subject))) (notmuch-show-mark-read))) @@ -1250,6 +1250,9 @@ Some useful entries are: (defun notmuch-show-get-depth () (notmuch-show-get-prop :depth)) +(defun notmuch-show-get-pretty-subject () + (notmuch-prettify-subject (notmuch-show-get-subject))) + (defun notmuch-show-set-tags (tags) "Set the tags of the current message." (notmuch-show-set-prop :tags tags) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 05c2ff7..cd04ffd 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -467,18 +467,14 @@ Complete list of currently available key bindings: "Display the currently selected thread." (interactive "P") (let ((thread-id (notmuch-search-find-thread-id)) - (subject (notmuch-search-find-subject))) + (subject (notmuch-prettify-subject (notmuch-search-find-subject)))) (if (> (length thread-id) 0) - (progn - (if (string-match "^[ \t]*$" subject) - (setq subject "[No Subject]")) - - (notmuch-show thread-id - (current-buffer) - notmuch-search-query-string - ;; Name the buffer based on the subject. - (concat "*" (truncate-string-to-width subject 30 nil nil t) "*") - crypto-switch)) + (notmuch-show thread-id + (current-buffer) + notmuch-search-query-string + ;; Name the buffer based on the subject. + (concat "*" (truncate-string-to-width subject 30 nil nil t) "*") + crypto-switch) (message "End of search results.")))) (defun notmuch-search-reply-to-thread (&optional prompt-for-sender) @@ -853,7 +849,8 @@ non-authors is found, assume that all of the authors match." (if (/= (match-beginning 1) line) (insert (concat "Error: Unexpected output from notmuch search:\n" (substring string line (match-beginning 1)) "\n"))) (let ((beg (point))) - (notmuch-search-show-result date count authors subject tags) + (notmuch-search-show-result date count authors + (notmuch-prettify-subject subject) tags) (notmuch-search-color-line beg (point) tag-list) (put-text-property beg (point) 'notmuch-search-thread-id thread-id) (put-text-property beg (point) 'notmuch-search-authors authors) -- cgit v1.2.3 From ff53fb468e160c8c6910078cfa92dcb6b5caa728 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 15 Apr 2012 22:57:45 -0400 Subject: emacs: Put notmuch-print-mechanism in custom group notmuch-show --- emacs/notmuch-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'emacs/notmuch-print.el') diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el index 6653d97..8c18f4b 100644 --- a/emacs/notmuch-print.el +++ b/emacs/notmuch-print.el @@ -25,7 +25,7 @@ (defcustom notmuch-print-mechanism 'notmuch-print-lpr "How should printing be done?" - :group 'notmuch + :group 'notmuch-show :type '(choice (function :tag "Use lpr" notmuch-print-lpr) (function :tag "Use ps-print" notmuch-print-ps-print) -- cgit v1.2.3