("authors" . "%-20s ")
("subject" . "%s ")
("tags" . "(%s)"))
- "Search result formating. Supported fields are:
+ "Search result formatting. Supported fields are:
date, count, authors, subject, tags
For example:
(setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)
:type '(alist :key-type (string) :value-type (string))
:group 'notmuch)
+(defvar notmuch-query-history nil
+ "Variable to store minibuffer history for notmuch queries")
+
(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
(let ((tag-list
(with-output-to-string
(define-key map "p" 'notmuch-search-previous-thread)
(define-key map "n" 'notmuch-search-next-thread)
(define-key map "r" 'notmuch-search-reply-to-thread)
- (define-key map "m" 'notmuch-mua-mail)
+ (define-key map "m" 'notmuch-mua-new-mail)
(define-key map "s" 'notmuch-search)
(define-key map "o" 'notmuch-search-toggle-order)
(define-key map "c" 'notmuch-search-stash-map)
(make-local-variable 'notmuch-search-target-line)
(set (make-local-variable 'notmuch-search-continuation) nil)
(set (make-local-variable 'scroll-preserve-screen-position) t)
- (add-to-invisibility-spec 'notmuch-search)
+ (add-to-invisibility-spec (cons 'ellipsis t))
(use-local-map notmuch-search-mode-map)
(setq truncate-lines t)
(setq major-mode 'notmuch-search-mode
"Return a list of authors for the current region"
(notmuch-search-properties-in-region 'notmuch-search-subject beg end))
-(defun notmuch-search-show-thread ()
+(defun notmuch-search-show-thread (&optional crypto-switch)
"Display the currently selected thread."
- (interactive)
+ (interactive "P")
(let ((thread-id (notmuch-search-find-thread-id))
(subject (notmuch-search-find-subject)))
(if (> (length thread-id) 0)
(concat "*"
(truncate-string-to-width subject 32 nil nil t)
"*")
- 32 nil nil t)))
+ 32 nil nil t))
+ crypto-switch)
(error "End of search results"))))
-(defun notmuch-search-reply-to-thread ()
+(defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
"Begin composing a reply to the entire current thread in a new buffer."
- (interactive)
+ (interactive "P")
(let ((message-id (notmuch-search-find-thread-id)))
- (notmuch-mua-reply message-id)))
+ (notmuch-mua-new-reply message-id prompt-for-sender)))
(defun notmuch-call-notmuch-process (&rest args)
"Synchronously invoke \"notmuch\" with the given list of arguments.
(error (buffer-substring beg end))
))))))
+(defun notmuch-tag (query &rest tags)
+ "Add/remove tags in TAGS to messages matching QUERY.
+
+TAGS should be a list of strings of the form \"+TAG\" or \"-TAG\" and
+QUERY should be a string containing the search-query.
+
+Note: Other code should always use this function alter tags of
+messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
+directly, so that hooks specified in notmuch-before-tag-hook and
+notmuch-after-tag-hook will be run."
+ (run-hooks 'notmuch-before-tag-hook)
+ (apply 'notmuch-call-notmuch-process
+ (append (list "tag") tags (list "--" query)))
+ (run-hooks 'notmuch-after-tag-hook))
+
+(defcustom notmuch-before-tag-hook nil
+ "Hooks that are run before tags of a message are modified.
+
+'tags' will contain the tags that are about to be added or removed as
+a list of strings of the form \"+TAG\" or \"-TAG\".
+'query' will be a string containing the search query that determines
+the messages that are about to be tagged"
+
+ :type 'hook
+ :options '(hl-line-mode)
+ :group 'notmuch)
+
+(defcustom notmuch-after-tag-hook nil
+ "Hooks that are run after tags of a message are modified.
+
+'tags' will contain the tags that were added or removed as
+a list of strings of the form \"+TAG\" or \"-TAG\".
+'query' will be a string containing the search query that determines
+the messages that were tagged"
+ :type 'hook
+ :options '(hl-line-mode)
+ :group 'notmuch)
+
(defun notmuch-search-set-tags (tags)
(save-excursion
(end-of-line)
(defun notmuch-search-add-tag-region (tag beg end)
(let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
- (notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string)
+ (notmuch-tag search-id-string (concat "+" tag))
(save-excursion
(let ((last-line (line-number-at-pos end))
(max-line (- (line-number-at-pos (point-max)) 2)))
(defun notmuch-search-remove-tag-region (tag beg end)
(let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
- (notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string)
+ (notmuch-tag search-id-string (concat "-" tag))
(save-excursion
(let ((last-line (line-number-at-pos end))
(max-line (- (line-number-at-pos (point-max)) 2)))
(notmuch-search-remove-tag-thread "inbox")
(forward-line))
+(defvar notmuch-search-process-filter-data nil
+ "Data that has not yet been processed.")
+(make-variable-buffer-local 'notmuch-search-process-filter-data)
+
(defun notmuch-search-process-sentinel (proc msg)
"Add a message to let user know when \"notmuch search\" exits"
(let ((buffer (process-buffer proc))
(insert "Incomplete search results (search process was killed).\n"))
(if (eq status 'exit)
(progn
+ (if notmuch-search-process-filter-data
+ (insert (concat "Error: Unexpected output from notmuch search:\n" notmuch-search-process-filter-data)))
(insert "End of search results.")
(if (not (= exit-status 0))
(insert (format " (process returned %d)" exit-status)))
attributes overriding earlier. A message having both \"delete\"
and \"unread\" tags with the above settings would have a green
foreground and blue background."
- :type '(alist :key-type (string) :value-type (list))
+ :type '(alist :key-type (string) :value-type (custom-face-edit))
:group 'notmuch)
(defun notmuch-search-color-line (start end line-tag-list)
(append (overlay-get overlay 'face) attributes)))))
notmuch-search-line-faces)))
-(defun notmuch-search-isearch-authors-show (overlay)
- (remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))
-
(defun notmuch-search-author-propertize (authors)
"Split `authors' into matching and non-matching authors and
propertize appropriately. If no boundary between authors and
(insert visible-string)
(when (not (string= invisible-string ""))
(let ((start (point))
- (invis-spec (make-symbol "notmuch-search-authors"))
overlay)
(insert invisible-string)
- (add-to-invisibility-spec (cons invis-spec t))
(setq overlay (make-overlay start (point)))
- (overlay-put overlay 'invisible invis-spec)
- (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show)))
+ (overlay-put overlay 'invisible 'ellipsis)
+ (overlay-put overlay 'isearch-open-invisible #'delete-overlay)))
(insert padding))))
(defun notmuch-search-insert-field (field date count authors subject tags)
(save-excursion
(let ((line 0)
(more t)
- (inhibit-read-only t))
+ (inhibit-read-only t)
+ (string (concat notmuch-search-process-filter-data string)))
+ (setq notmuch-search-process-filter-data nil)
(while more
(while (and (< line (length string)) (= (elt string line) ?\n))
(setq line (1+ line)))
(goto-char (point-max))
(if (/= (match-beginning 1) line)
(insert (concat "Error: Unexpected output from notmuch search:\n" (substring string line (match-beginning 1)) "\n")))
- (let ((beg (point-marker)))
+ (let ((beg (point)))
(notmuch-search-show-result date count authors subject tags)
- (notmuch-search-color-line beg (point-marker) tag-list)
- (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id)
- (put-text-property beg (point-marker) 'notmuch-search-authors authors)
- (put-text-property beg (point-marker) 'notmuch-search-subject subject)
+ (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)
+ (put-text-property beg (point) 'notmuch-search-subject subject)
(if (string= thread-id notmuch-search-target-thread)
(progn
(set 'found-target beg)
(while (and (< line (length string)) (= (elt string line) ?\n))
(setq line (1+ line)))
(if (< line (length string))
- (insert (concat "Error: Unexpected output from notmuch search:\n" (substring string line) "\n")))
+ (setq notmuch-search-process-filter-data (substring string line)))
))))
(if found-target
(goto-char found-target)))
(defun notmuch-search-operate-all (action)
"Add/remove tags from all matching messages.
-Tis command adds or removes tags from all messages matching the
+This command adds or removes tags from all messages matching the
current search terms. When called interactively, this command
will prompt for tags to be added or removed. Tags prefixed with
'+' will be added and tags prefixed with '-' will be removed.
(unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
(error "Action must be of the form `+thistag -that_tag'"))
(setq words (cdr words))))
- (apply 'notmuch-call-notmuch-process "tag"
- (append action-split (list notmuch-search-query-string) nil))))
+ (apply 'notmuch-tag notmuch-search-query-string action-split)))
(defun notmuch-search-buffer-title (query)
"Returns the title for a buffer with notmuch search results."
(concat "*notmuch-search-" query "*"))
)))
+(defun notmuch-read-query (prompt)
+ "Read a notmuch-query from the minibuffer with completion.
+
+PROMPT is the string to prompt with."
+ (lexical-let
+ ((completions
+ (append (list "folder:" "thread:" "id:" "date:" "from:" "to:"
+ "subject:" "attachment:")
+ (mapcar (lambda (tag)
+ (concat "tag:" tag))
+ (process-lines notmuch-command "search" "--output=tags" "*")))))
+ (let ((keymap (copy-keymap minibuffer-local-map))
+ (minibuffer-completion-table
+ (completion-table-dynamic
+ (lambda (string)
+ ;; generate a list of possible completions for the current input
+ (cond
+ ;; this ugly regexp is used to get the last word of the input
+ ;; possibly preceded by a '('
+ ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
+ (mapcar (lambda (compl)
+ (concat (match-string-no-properties 1 string) compl))
+ (all-completions (match-string-no-properties 2 string)
+ completions)))
+ (t (list string)))))))
+ ;; this was simpler than convincing completing-read to accept spaces:
+ (define-key keymap (kbd "<tab>") 'minibuffer-complete)
+ (read-from-minibuffer prompt nil keymap nil
+ 'notmuch-query-history nil nil))))
+
;;;###autoload
(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)
"Run \"notmuch search\" with the given query string and display results.
current if it appears in the search results.
target-line: The line number to move to if the target thread does not
appear in the search results."
- (interactive "sNotmuch search: ")
+ (interactive (list (notmuch-read-query "Notmuch search: ")))
(let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))
(switch-to-buffer buffer)
(notmuch-search-mode)
+ ;; Don't track undo information for this buffer
+ (set 'buffer-undo-list t)
(set 'notmuch-search-query-string query)
(set 'notmuch-search-oldest-first oldest-first)
(set 'notmuch-search-target-thread target-thread)
"--sort=newest-first")
query)))
(set-process-sentinel proc 'notmuch-search-process-sentinel)
- (set-process-filter proc 'notmuch-search-process-filter))))
+ (set-process-filter proc 'notmuch-search-process-filter)
+ (set-process-query-on-exit-flag proc nil))))
(run-hooks 'notmuch-search-hook)))
(defun notmuch-search-refresh-view ()
Runs a new search matching only messages that match both the
current search results AND the additional query string provided."
- (interactive "sFilter search: ")
+ (interactive (list (notmuch-read-query "Filter search: ")))
(let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)
(concat "( " query " )")
query)))