;
; Authors: Carl Worth <cworth@cworth.org>
-(load "cl-seq")
+(require 'cl)
+(require 'mm-view)
(defvar notmuch-show-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "b" 'notmuch-show-toggle-body-read-visible)
(define-key map "c" 'notmuch-show-toggle-citations-visible)
(define-key map "h" 'notmuch-show-toggle-headers-visible)
+ (define-key map "m" 'message-mail)
(define-key map "n" 'notmuch-show-next-message)
(define-key map "N" 'notmuch-show-mark-read-then-next-open-message)
(define-key map "p" 'notmuch-show-previous-message)
(define-key map (kbd "C-n") 'notmuch-show-next-line)
(define-key map (kbd "C-p") 'notmuch-show-previous-line)
(define-key map "q" 'kill-this-buffer)
+ (define-key map "r" 'notmuch-show-reply)
(define-key map "s" 'notmuch-show-toggle-signatures-visible)
+ (define-key map "v" 'notmuch-show-view-all-mime-parts)
(define-key map "w" 'notmuch-show-view-raw-message)
(define-key map "x" 'kill-this-buffer)
(define-key map "+" 'notmuch-show-add-tag)
(set 'notmuch-show-part-end-regexp "\fpart}")
(set 'notmuch-show-marker-regexp "\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
-(set 'notmuch-show-id-regexp "id:\\([^ ]*\\)")
+(set 'notmuch-show-id-regexp "\\(id:[^ ]*\\)")
(set 'notmuch-show-filename-regexp "filename:\\(.*\\)$")
(set 'notmuch-show-tags-regexp "(\\([^)]*\\))$")
(apply 'notmuch-call-notmuch-process
(append (cons "tag"
(mapcar (lambda (s) (concat "+" s)) toadd))
- (cons (concat "id:" (notmuch-show-get-message-id)) nil)))
+ (cons (notmuch-show-get-message-id) nil)))
(notmuch-show-set-tags (sort (union toadd (notmuch-show-get-tags) :test 'string=) 'string<)))
(defun notmuch-show-remove-tag (&rest toremove)
(apply 'notmuch-call-notmuch-process
(append (cons "tag"
(mapcar (lambda (s) (concat "-" s)) toremove))
- (cons (concat "id:" (notmuch-show-get-message-id)) nil)))
+ (cons (notmuch-show-get-message-id) nil)))
(notmuch-show-set-tags (sort (set-difference tags toremove :test 'string=) 'string<))))))
(defun notmuch-show-archive-thread-maybe-mark-read (markread)
(if parent-buffer
(progn
(switch-to-buffer parent-buffer)
+ (forward-line)
(notmuch-search-show-thread)))))
(defun notmuch-show-mark-read-then-archive-thread ()
(interactive)
(view-file (notmuch-show-get-filename)))
+(defun notmuch-show-view-all-mime-parts ()
+ "Use external viewers (according to mailcap) to view all MIME-encoded parts."
+ (interactive)
+ (save-excursion
+ (let ((filename (notmuch-show-get-filename)))
+ (switch-to-buffer (generate-new-buffer (concat "*notmuch-mime-"
+ filename
+ "*")))
+ (insert-file-contents filename nil nil nil t)
+ (mm-display-parts (mm-dissect-buffer))
+ (kill-this-buffer))))
+
+(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)))
+
(defun notmuch-show-pipe-message (command)
"Pipe the contents of the current message to the given command.
(define-key map "a" 'notmuch-search-archive-thread)
(define-key map "b" 'notmuch-search-scroll-down)
(define-key map "f" 'notmuch-search-filter)
+ (define-key map "m" 'message-mail)
(define-key map "n" 'next-line)
+ (define-key map "o" 'notmuch-search-toggle-order)
(define-key map "p" 'previous-line)
(define-key map "q" 'kill-this-buffer)
(define-key map "s" 'notmuch-search)
(interactive)
(kill-all-local-variables)
(make-local-variable 'notmuch-search-query-string)
+ (make-local-variable 'notmuch-search-oldest-first)
(set (make-local-variable 'scroll-preserve-screen-position) t)
(add-to-invisibility-spec 'notmuch-search)
(use-local-map notmuch-search-mode-map)
(notmuch-search-markup-this-thread-id)
(next-line))))
-(defun notmuch-search-hide-thread-ids ()
- (interactive)
- (add-to-invisibility-spec 'notmuch-search)
- (force-window-update)
- (redisplay t))
-
-(defun notmuch-search-show-thread-ids ()
- (interactive)
- (remove-from-invisibility-spec 'notmuch-search)
- (force-window-update)
- (redisplay t))
-
(defun notmuch-search-show-thread ()
(interactive)
(let ((thread-id (notmuch-search-find-thread-id)))
- (forward-line)
(if (> (length thread-id) 0)
(notmuch-show thread-id (current-buffer))
(error "End of search results"))))
(notmuch-search-remove-tag "inbox")
(forward-line))
-(defun notmuch-search (query)
+(defun notmuch-search (query &optional oldest-first)
"Run \"notmuch search\" with the given query string and display results."
(interactive "sNotmuch search: ")
(let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*"))))
(switch-to-buffer buffer)
(notmuch-search-mode)
(set 'notmuch-search-query-string query)
+ (set 'notmuch-search-oldest-first oldest-first)
(let ((proc (get-buffer-process (current-buffer)))
(inhibit-read-only t))
(if proc
(erase-buffer)
(goto-char (point-min))
(save-excursion
- (call-process "notmuch" nil t nil "search" query)
+ (if oldest-first
+ (call-process "notmuch" nil t nil "search" query)
+ (call-process "notmuch" nil t nil "search" "--reverse" query))
(notmuch-search-markup-thread-ids)
))))
same relative position within the new buffer."
(interactive)
(let ((here (point))
+ (oldest-first notmuch-search-oldest-first)
(thread (notmuch-search-find-thread-id))
(query notmuch-search-query-string))
(kill-this-buffer)
- (notmuch-search query)
+ (notmuch-search query oldest-first)
(goto-char (point-min))
(if (re-search-forward (concat "^" thread) nil t)
(beginning-of-line)
(goto-char here))))
+(defun notmuch-search-toggle-order ()
+ "Toggle the current search order.
+
+By default, the \"inbox\" view created by `notmuch' is displayed
+in chronological order (oldest thread at the beginning of the
+buffer), while any global searches created by `notmuch-search'
+are displayed in reverse-chronological order (newest thread at
+the beginning of the buffer).
+
+This command toggles the sort order for the current search.
+
+Note that any fitlered searches created by
+`notmuch-search-filter' retain the search order of the parent
+search."
+ (interactive)
+ (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
+ (notmuch-search-refresh-view))
+
(defun notmuch-search-filter (query)
"Filter the current search results based on an additional query string.
Runs a new search matching only messages that match both the
current search results AND the additional query string provided."
(interactive "sFilter search: ")
- (notmuch-search (concat notmuch-search-query-string " and " query)))
+ (notmuch-search (concat notmuch-search-query-string " and " query) notmuch-search-oldest-first))
(defun notmuch-search-filter-by-tag (tag)
"Filter the current search results based on a single tag.
Runs a new search matching only messages that match both the
current search results AND that are tagged with the given tag."
(interactive "sFilter by tag: ")
- (notmuch-search (concat notmuch-search-query-string " and tag:" tag)))
+ (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))
(defun notmuch ()
"Run notmuch to display all mail with tag of 'inbox'"
(interactive)
- (notmuch-search "tag:inbox"))
+ (notmuch-search "tag:inbox" t))
(provide 'notmuch)