X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.el;h=a5474158929857710129ed6b6b455c568a5fdc0e;hp=ed1b363b95a37edef4866d383058ae38e39a34c7;hb=6b823b6fba4b2802f9d72f62ff4f6e44809d5449;hpb=0656fb518df3190aebc04ed955c8b3c3cc21759c diff --git a/notmuch.el b/notmuch.el index ed1b363b..a5474158 100644 --- a/notmuch.el +++ b/notmuch.el @@ -19,6 +19,34 @@ ; ; Authors: Carl Worth +; This is an emacs-based interface to the notmuch mail system. +; +; You will first need to have the notmuch program installed and have a +; notmuch database built in order to use this. See +; http://notmuchmail.org for details. +; +; To install this software, copy it to a directory that is on the +; `load-path' variable within emacs (a good candidate is +; /usr/local/share/emacs/site-lisp). If you are viewing this from the +; notmuch source distribution then you can simply run: +; +; sudo make install-emacs +; +; to install it. +; +; Then, to actually run it, add: +; +; (require 'notmuch) +; +; to your ~/.emacs file, and then run "M-x notmuch" from within emacs, +; or run: +; +; emacs -f notmuch +; +; Have fun, and let us know if you have any comment, questions, or +; kudos: Notmuch list (subscription is not +; required, but is available from http://notmuchmail.org). + (require 'cl) (require 'mm-view) @@ -71,22 +99,31 @@ pattern can still test against the entire line).") (defvar notmuch-show-signature-lines-max 12 "Maximum length of signature that will be hidden by default.") -(set 'notmuch-show-message-begin-regexp " message{") -(set 'notmuch-show-message-end-regexp " message}") -(set 'notmuch-show-header-begin-regexp " header{") -(set 'notmuch-show-header-end-regexp " header}") -(set 'notmuch-show-body-begin-regexp " body{") -(set 'notmuch-show-body-end-regexp " body}") -(set 'notmuch-show-attachment-begin-regexp " attachment{") -(set 'notmuch-show-attachment-end-regexp " attachment}") -(set 'notmuch-show-part-begin-regexp " part{") -(set 'notmuch-show-part-end-regexp " part}") -(set 'notmuch-show-marker-regexp " \\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$") - -(set 'notmuch-show-id-regexp "\\(id:[^ ]*\\)") -(set 'notmuch-show-depth-regexp " depth:\\([0-9]*\\) ") -(set 'notmuch-show-filename-regexp "filename:\\(.*\\)$") -(set 'notmuch-show-tags-regexp "(\\([^)]*\\))$") +(defvar notmuch-command "notmuch" + "Command to run the notmuch binary.") + +(defvar notmuch-show-message-begin-regexp "\fmessage{") +(defvar notmuch-show-message-end-regexp "\fmessage}") +(defvar notmuch-show-header-begin-regexp "\fheader{") +(defvar notmuch-show-header-end-regexp "\fheader}") +(defvar notmuch-show-body-begin-regexp "\fbody{") +(defvar notmuch-show-body-end-regexp "\fbody}") +(defvar notmuch-show-attachment-begin-regexp "\fattachment{") +(defvar notmuch-show-attachment-end-regexp "\fattachment}") +(defvar notmuch-show-part-begin-regexp "\fpart{") +(defvar notmuch-show-part-end-regexp "\fpart}") +(defvar notmuch-show-marker-regexp "\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$") + +(defvar notmuch-show-id-regexp "\\(id:[^ ]*\\)") +(defvar notmuch-show-depth-regexp " depth:\\([0-9]*\\) ") +(defvar notmuch-show-filename-regexp "filename:\\(.*\\)$") +(defvar notmuch-show-tags-regexp "(\\([^)]*\\))$") + +(defvar notmuch-show-parent-buffer nil) +(defvar notmuch-show-body-read-visible nil) +(defvar notmuch-show-citations-visible nil) +(defvar notmuch-show-signatures-visible nil) +(defvar notmuch-show-headers-visible nil) ; XXX: This should be a generic function in emacs somewhere, not here (defun point-invisible-p () @@ -249,18 +286,21 @@ buffer." (mm-display-parts (mm-dissect-buffer)) (kill-this-buffer)))) +(defun notmuch-reply (query-string) + (switch-to-buffer (generate-new-buffer "notmuch-draft")) + (call-process notmuch-command nil t nil "reply" query-string) + (goto-char (point-min)) + (if (re-search-forward "^$" nil t) + (progn + (insert "--text follows this line--") + (forward-line))) + (message-mode)) + (defun notmuch-show-reply () "Begin composing a reply to the current message in a new buffer." (interactive) (let ((message-id (notmuch-show-get-message-id))) - (switch-to-buffer (generate-new-buffer "notmuch-draft")) - (call-process "notmuch" nil t nil "reply" message-id) - (goto-char (point-min)) - (if (re-search-forward "^$" nil t) - (progn - (insert "--text follows this line--") - (forward-line))) - (message-mode))) + (notmuch-reply message-id))) (defun notmuch-show-pipe-message (command) "Pipe the contents of the current message to the given command. @@ -513,7 +553,7 @@ which this thread was originally shown." (let ((beg (point-marker))) (end-of-line) ; Inverse video for subject - (overlay-put (make-overlay beg (point)) 'face '((cons :inverse-video t))) + (overlay-put (make-overlay beg (point)) 'face '(:inverse-video t)) (forward-line 2) (let ((beg-hidden (point-marker))) (re-search-forward notmuch-show-header-end-regexp) @@ -639,6 +679,35 @@ view, (remove the \"inbox\" tag from each), with mode-name "notmuch-show") (setq buffer-read-only t)) +;;;###autoload + +(defgroup notmuch nil + "Notmuch mail reader for Emacs." + :group 'mail) + +(defcustom notmuch-show-hook nil + "List of functions to call when notmuch displays a message." + :type 'hook + :options '(goto-address) + :group 'notmuch) + +(defcustom notmuch-search-hook nil + "List of functions to call when notmuch displays the search results." + :type 'hook + :options '(hl-line-mode) + :group 'notmuch) + +; Make show mode a bit prettier, highlighting URLs and using word wrap + +(defun notmuch-show-pretty-hook () + (goto-address-mode 1) + (visual-line-mode)) + +(add-hook 'notmuch-show-hook 'notmuch-show-pretty-hook) +(add-hook 'notmuch-search-hook + (lambda() + (hl-line-mode 1) )) + (defun notmuch-show (thread-id &optional parent-buffer) "Run \"notmuch show\" with the given thread ID and display results. @@ -653,14 +722,15 @@ thread from that buffer can be show when done with this one)." (let ((proc (get-buffer-process (current-buffer))) (inhibit-read-only t)) (if proc - (error "notmuch search process already running for query `%s'" query) + (error "notmuch search process already running for query `%s'" thread-id) ) (erase-buffer) (goto-char (point-min)) (save-excursion - (call-process "notmuch" nil t nil "show" thread-id) + (call-process notmuch-command nil t nil "show" thread-id) (notmuch-show-markup-messages) ) + (run-hooks 'notmuch-show-hook) ; Move straight to the first unread message (if (not (notmuch-show-message-unread-p)) (progn @@ -687,6 +757,7 @@ thread from that buffer can be show when done with this one)." (define-key map "o" 'notmuch-search-toggle-order) (define-key map "p" 'previous-line) (define-key map "q" 'kill-this-buffer) + (define-key map "r" 'notmuch-search-reply-to-thread) (define-key map "s" 'notmuch-search) (define-key map "t" 'notmuch-search-filter-by-tag) (define-key map "x" 'kill-this-buffer) @@ -704,6 +775,9 @@ thread from that buffer can be show when done with this one)." "Keymap for \"notmuch search\" buffers.") (fset 'notmuch-search-mode-map notmuch-search-mode-map) +(defvar notmuch-search-query-string) +(defvar notmuch-search-oldest-first) + (defun notmuch-search-scroll-up () "Scroll up, moving point to last message in thread if at end." (interactive) @@ -726,10 +800,10 @@ thread from that buffer can be show when done with this one)." (goto-char (window-start)) (scroll-down nil))) -(defun notmuch-search-goto-last-thread (&optional arg) +(defun notmuch-search-goto-last-thread () "Move point to the last thread in the buffer." - (interactive "^P") - (end-of-buffer arg) + (interactive) + (goto-char (point-max)) (forward-line -1)) ;;;###autoload @@ -759,6 +833,7 @@ global search. (set (make-local-variable 'scroll-preserve-screen-position) t) (add-to-invisibility-spec 'notmuch-search) (use-local-map notmuch-search-mode-map) + (setq truncate-lines t) (setq major-mode 'notmuch-search-mode mode-name "notmuch-search") (setq buffer-read-only t)) @@ -802,6 +877,12 @@ global search. (notmuch-show thread-id (current-buffer)) (error "End of search results")))) +(defun notmuch-search-reply-to-thread () + "Begin composing a reply to the entire current thread in a new buffer." + (interactive) + (let ((message-id (notmuch-search-find-thread-id))) + (notmuch-reply message-id))) + (defun notmuch-call-notmuch-process (&rest args) "Synchronously invoke \"notmuch\" with the given list of arguments. @@ -810,7 +891,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"." (let ((error-buffer (get-buffer-create "*Notmuch errors*"))) (with-current-buffer error-buffer (erase-buffer)) - (if (eq (apply 'call-process "notmuch" nil error-buffer nil args) 0) + (if (eq (apply 'call-process notmuch-command nil error-buffer nil args) 0) (point) (progn (with-current-buffer error-buffer @@ -876,10 +957,11 @@ This function advances point to the next line when finished." (goto-char (point-min)) (save-excursion (if oldest-first - (call-process "notmuch" nil t nil "search" "--sort=oldest-first" query) - (call-process "notmuch" nil t nil "search" "--sort=newest-first" query)) + (call-process notmuch-command nil t nil "search" "--sort=oldest-first" query) + (call-process notmuch-command nil t nil "search" "--sort=newest-first" query)) (notmuch-search-markup-thread-ids) - )))) + )) + (run-hooks 'notmuch-search-hook))) (defun notmuch-search-refresh-view () "Refresh the current view. @@ -940,4 +1022,6 @@ current search results AND that are tagged with the given tag." (interactive) (notmuch-search "tag:inbox" t)) +(setq mail-user-agent 'message-user-agent) + (provide 'notmuch)