diff --git a/emacs/Makefile.am b/emacs/Makefile.am index 3fa100df..6c082d48 100644 --- a/emacs/Makefile.am +++ b/emacs/Makefile.am @@ -24,13 +24,12 @@ mu4e_TEXINFOS=fdl.texi lispdir=${prefix}/share/emacs/site-lisp/mu4e/ dist_lisp_LISP= \ - mu4e-utils.el \ + mu4e-compose.el \ mu4e-hdrs.el \ mu4e-main.el \ mu4e-proc.el \ - mu4e-raw-view.el \ - mu4e-compose.el \ mu4e-speedbar.el \ + mu4e-utils.el \ mu4e-vars.el \ mu4e-version.el \ mu4e-view.el \ diff --git a/emacs/mu4e-raw-view.el b/emacs/mu4e-raw-view.el deleted file mode 100644 index b42a2654..00000000 --- a/emacs/mu4e-raw-view.el +++ /dev/null @@ -1,110 +0,0 @@ -;;; mu4e-raw-view.el -- part of mu4e, the mu mail user agent -;; -;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema - -;; Author: Dirk-Jan C. Binnema -;; Maintainer: Dirk-Jan C. Binnema - -;; This file is not part of GNU Emacs. -;; -;; GNU Emacs 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. - -;; GNU Emacs 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 GNU Emacs. If not, see . - -;;; Commentary: - -;; In this file we define mu4e-view-mode (+ helper functions), which is used for -;; viewing e-mail messages - -;;; Code: -(eval-when-compile (require 'cl)) - -(require 'mu4e-utils) ;; utility functions - -;; raw mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; some buffer-local variables -(defconst mu4e-raw-view-buffer-name "*mu4e-raw-view*" - "*internal* Name for the raw message view buffer") - -(defvar mu4e-raw-view-buffer nil "*internal* The raw view buffer.") - -(defvar mu4e-raw-view-mode-map nil - "Keymap for \"*mu4e-raw-view*\" buffers.") - -(unless mu4e-raw-view-mode-map - (setq mu4e-raw-view-mode-map - (let ((map (make-sparse-keymap))) - - (define-key map "q" 'mu4e-raw-view-quit-buffer) - (define-key map "." 'mu4e-raw-view-quit-buffer) - - ;; intra-message navigation - (define-key map (kbd "SPC") 'scroll-up) - (define-key map (kbd "") - '(lambda () (interactive) (goto-char (point-min)))) - (define-key map (kbd "") - '(lambda () (interactive) (goto-char (point-max)))) - (define-key map (kbd "RET") - '(lambda () (interactive) (scroll-up 1))) - (define-key map (kbd "") - '(lambda () (interactive) (scroll-up -1))) - map))) - -(fset 'mu4e-raw-view-mode-map mu4e-raw-view-mode-map) - -(define-derived-mode mu4e-raw-view-mode special-mode - "mu4e:raw" - "Major mode for viewing of raw e-mail message in mu4e. -\\{mu4e-raw-view-mode-map}.") - - -(defun mu4e-raw-view-message (msg view-buffer) - "Display the raw contents of message MSG in a new buffer." - (let ((buf (get-buffer-create mu4e-raw-view-buffer-name)) - (inhibit-read-only t) - (file (plist-get msg :path))) - (unless (and file (file-readable-p file)) - (error "Not a readable file: %S" file)) - (with-current-buffer buf - (erase-buffer) - (insert-file-contents file) - ;; initialize view-mode - (mu4e-raw-view-mode) - (setq mu4e-raw-view-buffer view-buffer) - (switch-to-buffer buf) - (goto-char (point-min))))) - - -(defun mu4e-view-shell-command-on-raw-message (msg view-buffer cmd) - "Process the raw message with shell command CMD." - (let ((buf (get-buffer-create mu4e-raw-view-buffer-name)) - (inhibit-read-only t) - (file (plist-get msg :path))) - (unless (and file (file-readable-p file)) - (error "Not a readable file: %S" file)) - (with-current-buffer buf - (erase-buffer) - (process-file-shell-command cmd file buf) - (mu4e-raw-view-mode) - (setq mu4e-raw-view-buffer view-buffer) - (switch-to-buffer buf) - (goto-char (point-min))))) - - -(defun mu4e-raw-view-quit-buffer () - "Quit the raw view and return to the message." - (interactive) - (kill-buffer)) - -(provide 'mu4e-raw-view) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/emacs/mu4e-utils.el b/emacs/mu4e-utils.el index 48a9a9e1..d4867d59 100644 --- a/emacs/mu4e-utils.el +++ b/emacs/mu4e-utils.el @@ -372,28 +372,31 @@ of mu4e and emacs." (format "mu4e %s; emacs %s" mu4e-mu-version emacs-version))) -(defun mu4e-message-at-point () +(defun mu4e-message-at-point (&optional raise-err) "Get the message s-expression for the message at point in either -the headers buffer or the view buffer." +the headers buffer or the view buffer, or nil if there is no such +message. If optional RAISE-ERR is non-nil, raise an error when +there is no message at point." (let ((msg (cond ((eq major-mode 'mu4e-hdrs-mode) (get-text-property (point) 'msg)) ((eq major-mode 'mu4e-view-mode) mu4e-current-msg)))) - (unless msg (error "No message at point")) - msg)) + (if (and (null msg) raise-err) + (error "No message at point") + msg))) (defun mu4e-field-at-point (field) "Get FIELD (a symbol, see `mu4e-header-names') for the message at point in eiter the headers buffer or the view buffer." - (plist-get (mu4e-message-at-point) field)) + (plist-get (mu4e-message-at-point t) field)) (defun mu4e-capture-message () "Capture the path of the message at point." (interactive) - (setq mu4e-captured-message (mu4e-message-at-point)) - (message "Message has been captured")) + (setq mu4e-captured-message (mu4e-message-at-point t)) + (message "Message has been captured")) (defun mu4e-kill-buffer-and-window (buf) "Kill buffer BUF and any of its windows. Like @@ -421,6 +424,18 @@ that has a live window), and vice versa." (message "No window to switch to")))) +(defconst mu4e-output-buffer-name "*mu4e-output" + "*internal* Name of the mu4e output buffer.") + +(defun mu4e-process-file-through-pipe (path pipecmd) + "Process file at PATH through a pipe with PIPECMD." + (let ((buf (get-buffer-create mu4e-output-buffer-name))) + (with-current-buffer buf + (let ((inhibit-read-only t)) + (erase-buffer) + (call-process-shell-command pipecmd path t t) + (view-mode))) + (switch-to-buffer buf))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/emacs/mu4e-view.el b/emacs/mu4e-view.el index 353e9976..f3c7b079 100644 --- a/emacs/mu4e-view.el +++ b/emacs/mu4e-view.el @@ -28,7 +28,6 @@ ;;; Code: (require 'mu4e-utils) ;; utility functions (require 'mu4e-vars) -(require 'mu4e-raw-view) ;; we prefer the improved fill-region (require 'filladapt nil 'noerror) @@ -38,6 +37,9 @@ (defvar mu4e-hdrs-buffer nil "*internal* Headers buffer connected to this view.") +(defconst mu4e-view-raw-buffer-name "*mu4e-raw-view*" + "*internal* Name for the raw message view buffer") + (defun mu4e-view-message-with-msgid (msgid) "View message with MSGID. This is meant for external programs wanting to show specific messages - for example, `mu4e-org'." @@ -245,7 +247,7 @@ is nil, and otherwise open it." (define-key map "C" 'mu4e-compose-new) (define-key map "E" 'mu4e-compose-edit) - (define-key map "." 'mu4e-raw-view) + (define-key map "." 'mu4e-view-raw-message) (define-key map "|" 'mu4e-view-pipe) ;; (define-key map "I" 'mu4e-inspect-message) @@ -682,6 +684,7 @@ ACTION." (?e (call-interactively 'mu4e-view-open-attachment-emacs)) (otherwise (message "Not yet implemented"))))) + ;; handler-function to handle the response we get from the server when we ;; want to do something with one of the attachments. (defun mu4e-view-temp-handler (path what param) @@ -694,17 +697,12 @@ attachments) in response to a (mu4e-proc-extract 'temp ... )." (concat param " " path))) ((string= what "pipe") ;; 'param' will be the pipe command, path the infile for this - (let ((inhibit-read-only t)) - (switch-to-buffer (get-buffer-create "*mu4e-output*")) - (erase-buffer) - (call-process-shell-command param path t t) - (view-mode))) + (mu4e-process-file-through-pipe path param)) ((string= what "emacs") (find-file path) ;; make the buffer read-only since it usually does not make ;; sense to edit the temp buffer; use C-x C-q if you insist... - (setq buffer-read-only t) - ) + (setq buffer-read-only t)) (t (error "Unsupported action %S" what)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -743,20 +741,28 @@ that execution can only take place in n the header list." (unless url (error "Invalid number for URL")) (browse-url url))) -(defun mu4e-raw-view () - "Show the the raw text of the current message." +(defun mu4e-view-raw-message () + "Display the raw contents of message at point in a new buffer." (interactive) - (unless mu4e-current-msg - (error "No current message")) - (mu4e-raw-view-message mu4e-current-msg (current-buffer))) + (let ((path (mu4e-field-at-point :path)) + (buf (get-buffer-create mu4e-view-raw-buffer-name))) + (unless (and path (file-readable-p path)) + (error "Not a readable file: %S" path)) + (with-current-buffer buf + (let ((inhibit-read-only t)) + (erase-buffer) + (insert-file-contents path) + (view-mode) + (goto-char (point-min)))) + (switch-to-buffer buf))) + (defun mu4e-view-pipe (cmd) "Pipe the message through shell command CMD, and display the results." (interactive "sShell command: ") - (unless mu4e-current-msg - (error "No current message")) - (mu4e-view-shell-command-on-raw-message mu4e-current-msg - (current-buffer) cmd)) + (let ((path (mu4e-field-at-point :path))) + (mu4e-process-file-through-pipe path cmd))) + (provide 'mu4e-view) diff --git a/emacs/mu4e.texi b/emacs/mu4e.texi index a6d04879..1db0cb22 100644 --- a/emacs/mu4e.texi +++ b/emacs/mu4e.texi @@ -535,6 +535,8 @@ u unmark message at point R,F,C reply/forward/compose E edit (only allowed for draft messages) +| pipe message through shell command + d mark for moving to the trash folder DEL,D mark for immediate deletion m mark for moving to another maildir folder @@ -544,6 +546,7 @@ u unmark message at point U unmark *all* messages x execute actions for the marked messages RET open the message at point in the message view + H get help q,z leave the headers buffer @end verbatim @@ -666,7 +669,7 @@ u unmark message at point R,F,C reply/forward/compose E edit (only allowed for draft messages) -. show the raw message view. ./q take you back +. show the raw message view. 'q' takes you back. g go to (visit) numbered URL (using `browse-url') (or: or RET with point on url) @@ -708,7 +711,8 @@ choose from a list with some more actions to perform on attachments: @itemize @item @t{open-with} (@key{w}): open the attachment with some arbitrary program. For example, suppose you have received a message with a picture -attachment; then, @t{a w 1 RET gimp RET} will open that attachment in The Gimp. +attachment; then, @t{a w 1 RET gimp RET} will open that attachment in The +Gimp. @item @t{pipe} (@key{|}: process the attachment with some Unix shell-pipe and see the results. Suppose you receive a patch file, and would like to get an overview of the changes, using the @t{diffstat} program. You can use something