2021-01-10 15:00:47 +01:00
|
|
|
;;; notmuch.el --- run notmuch within emacs -*- lexical-binding: t -*-
|
2012-01-21 15:44:28 +01:00
|
|
|
;;
|
|
|
|
;; Copyright © Carl Worth
|
|
|
|
;;
|
|
|
|
;; 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
|
2016-06-02 18:26:14 +02:00
|
|
|
;; along with Notmuch. If not, see <https://www.gnu.org/licenses/>.
|
2012-01-21 15:44:28 +01:00
|
|
|
;;
|
|
|
|
;; Authors: Carl Worth <cworth@cworth.org>
|
2020-08-08 13:49:54 +02:00
|
|
|
;; Homepage: https://notmuchmail.org
|
2009-10-30 23:17:27 +01:00
|
|
|
|
2016-04-13 09:58:47 +02:00
|
|
|
;;; Commentary:
|
|
|
|
|
2012-01-21 15:44:28 +01:00
|
|
|
;; 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
|
2016-06-02 18:26:14 +02:00
|
|
|
;; https://notmuchmail.org for details.
|
2012-01-21 15:44:28 +01:00
|
|
|
;;
|
|
|
|
;; 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:
|
|
|
|
;;
|
2014-03-29 09:07:58 +01:00
|
|
|
;; (autoload 'notmuch "notmuch" "Notmuch mail" t)
|
2012-01-21 15:44:28 +01:00
|
|
|
;;
|
|
|
|
;; 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 <notmuch@notmuchmail.org> (subscription is not
|
2016-06-02 18:26:14 +02:00
|
|
|
;; required, but is available from https://notmuchmail.org).
|
2017-07-11 13:19:37 +02:00
|
|
|
;;
|
|
|
|
;; Note for MELPA users (and others tracking the development version
|
|
|
|
;; of notmuch-emacs):
|
|
|
|
;;
|
|
|
|
;; This emacs package needs a fairly closely matched version of the
|
|
|
|
;; notmuch program. If you use the MELPA version of notmuch.el (as
|
|
|
|
;; opposed to MELPA stable), you should be prepared to track the
|
|
|
|
;; master development branch (i.e. build from git) for the notmuch
|
|
|
|
;; program as well. Upgrading notmuch-emacs too far beyond the notmuch
|
|
|
|
;; program can CAUSE YOUR EMAIL TO STOP WORKING.
|
|
|
|
;;
|
|
|
|
;; TL;DR: notmuch-emacs from MELPA and notmuch from distro packages is
|
|
|
|
;; NOT SUPPORTED.
|
2020-08-08 13:49:54 +02:00
|
|
|
|
2016-04-13 09:58:47 +02:00
|
|
|
;;; Code:
|
|
|
|
|
2009-11-14 17:57:38 +01:00
|
|
|
(require 'mm-view)
|
2009-11-25 23:14:20 +01:00
|
|
|
(require 'message)
|
2009-11-05 20:15:56 +01:00
|
|
|
|
2021-01-10 15:01:05 +01:00
|
|
|
(require 'hl-line)
|
|
|
|
|
2010-04-01 19:36:21 +02:00
|
|
|
(require 'notmuch-lib)
|
2012-04-14 20:52:50 +02:00
|
|
|
(require 'notmuch-tag)
|
2010-04-01 19:36:21 +02:00
|
|
|
(require 'notmuch-show)
|
2013-11-01 10:23:41 +01:00
|
|
|
(require 'notmuch-tree)
|
2010-04-22 11:03:32 +02:00
|
|
|
(require 'notmuch-mua)
|
2010-04-26 17:07:04 +02:00
|
|
|
(require 'notmuch-hello)
|
2010-04-26 10:23:16 +02:00
|
|
|
(require 'notmuch-maildir-fcc)
|
2010-04-27 18:03:10 +02:00
|
|
|
(require 'notmuch-message)
|
2013-06-01 02:40:07 +02:00
|
|
|
(require 'notmuch-parser)
|
2009-11-04 22:16:33 +01:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Options
|
|
|
|
|
2010-04-12 09:51:30 +02:00
|
|
|
(defcustom notmuch-search-result-format
|
2012-07-09 23:42:41 +02:00
|
|
|
`(("date" . "%12s ")
|
2010-04-12 09:51:30 +02:00
|
|
|
("count" . "%-7s ")
|
2010-04-23 12:24:09 +02:00
|
|
|
("authors" . "%-20s ")
|
2010-04-12 09:51:30 +02:00
|
|
|
("subject" . "%s ")
|
|
|
|
("tags" . "(%s)"))
|
2021-07-19 13:31:07 +02:00
|
|
|
"Search result formatting.
|
|
|
|
|
|
|
|
Supported fields are: date, count, authors, subject, tags.
|
2010-04-12 09:51:30 +02:00
|
|
|
For example:
|
2021-07-19 13:31:07 +02:00
|
|
|
(setq notmuch-search-result-format
|
|
|
|
'((\"authors\" . \"%-40s\")
|
|
|
|
(\"subject\" . \"%s\")))
|
|
|
|
|
2012-07-21 19:37:08 +02:00
|
|
|
Line breaks are permitted in format strings (though this is
|
|
|
|
currently experimental). Note that a line break at the end of an
|
|
|
|
\"authors\" field will get elided if the authors list is long;
|
|
|
|
place it instead at the beginning of the following field. To
|
|
|
|
enter a line break when setting this variable with setq, use \\n.
|
|
|
|
To enter a line break in customize, press \\[quoted-insert] C-j."
|
2021-07-19 13:31:07 +02:00
|
|
|
:type '(alist :key-type string :value-type string)
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search)
|
2010-04-12 09:51:30 +02:00
|
|
|
|
2014-03-29 09:07:59 +01:00
|
|
|
;; The name of this variable `notmuch-init-file' is consistent with the
|
|
|
|
;; convention used in e.g. emacs and gnus. The value, `notmuch-config[.el[c]]'
|
|
|
|
;; is consistent with notmuch cli configuration file `~/.notmuch-config'.
|
|
|
|
(defcustom notmuch-init-file (locate-user-emacs-file "notmuch-config")
|
|
|
|
"Your Notmuch Emacs-Lisp configuration file name.
|
|
|
|
If a file with one of the suffixes defined by `get-load-suffixes' exists,
|
|
|
|
it will be read instead.
|
|
|
|
This file is read once when notmuch is loaded; the notmuch hooks added
|
|
|
|
there will be called at other points of notmuch execution."
|
|
|
|
:type 'file
|
|
|
|
:group 'notmuch)
|
|
|
|
|
2021-01-10 15:01:05 +01:00
|
|
|
(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
|
|
|
|
"List of functions to call when notmuch displays the search results."
|
|
|
|
:type 'hook
|
|
|
|
:options '(notmuch-hl-line-mode)
|
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-hooks)
|
2011-08-09 19:32:49 +02:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Mime Utilities
|
|
|
|
|
2009-11-27 14:30:14 +01:00
|
|
|
(defun notmuch-foreach-mime-part (function mm-handle)
|
|
|
|
(cond ((stringp (car mm-handle))
|
2020-08-08 13:49:38 +02:00
|
|
|
(dolist (part (cdr mm-handle))
|
|
|
|
(notmuch-foreach-mime-part function part)))
|
|
|
|
((bufferp (car mm-handle))
|
|
|
|
(funcall function mm-handle))
|
|
|
|
(t (dolist (part mm-handle)
|
|
|
|
(notmuch-foreach-mime-part function part)))))
|
2009-11-27 14:30:14 +01:00
|
|
|
|
|
|
|
(defun notmuch-count-attachments (mm-handle)
|
|
|
|
(let ((count 0))
|
|
|
|
(notmuch-foreach-mime-part
|
|
|
|
(lambda (p)
|
|
|
|
(let ((disposition (mm-handle-disposition p)))
|
2020-08-08 13:49:38 +02:00
|
|
|
(and (listp disposition)
|
|
|
|
(or (equal (car disposition) "attachment")
|
|
|
|
(and (equal (car disposition) "inline")
|
|
|
|
(assq 'filename disposition)))
|
|
|
|
(cl-incf count))))
|
2009-11-27 14:30:14 +01:00
|
|
|
mm-handle)
|
|
|
|
count))
|
|
|
|
|
|
|
|
(defun notmuch-save-attachments (mm-handle &optional queryp)
|
|
|
|
(notmuch-foreach-mime-part
|
|
|
|
(lambda (p)
|
|
|
|
(let ((disposition (mm-handle-disposition p)))
|
|
|
|
(and (listp disposition)
|
2020-08-08 13:49:38 +02:00
|
|
|
(or (equal (car disposition) "attachment")
|
|
|
|
(and (equal (car disposition) "inline")
|
|
|
|
(assq 'filename disposition)))
|
|
|
|
(or (not queryp)
|
|
|
|
(y-or-n-p
|
|
|
|
(concat "Save '" (cdr (assq 'filename disposition)) "' ")))
|
|
|
|
(mm-save-part p))))
|
2009-11-27 14:30:14 +01:00
|
|
|
mm-handle))
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Keymap
|
|
|
|
|
2009-10-31 09:04:01 +01:00
|
|
|
(defvar notmuch-search-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2013-09-03 23:45:24 +02:00
|
|
|
(set-keymap-parent map notmuch-common-keymap)
|
2014-10-29 15:18:49 +01:00
|
|
|
(define-key map "x" 'notmuch-bury-or-kill-this-buffer)
|
2021-01-13 18:37:50 +01:00
|
|
|
(define-key map (kbd "DEL") 'notmuch-search-scroll-down)
|
2009-11-04 23:38:49 +01:00
|
|
|
(define-key map "b" 'notmuch-search-scroll-down)
|
2009-12-01 01:02:27 +01:00
|
|
|
(define-key map " " 'notmuch-search-scroll-up)
|
2009-12-01 01:52:31 +01:00
|
|
|
(define-key map "<" 'notmuch-search-first-thread)
|
|
|
|
(define-key map ">" 'notmuch-search-last-thread)
|
|
|
|
(define-key map "p" 'notmuch-search-previous-thread)
|
|
|
|
(define-key map "n" 'notmuch-search-next-thread)
|
2012-01-14 15:46:18 +01:00
|
|
|
(define-key map "r" 'notmuch-search-reply-to-thread-sender)
|
|
|
|
(define-key map "R" 'notmuch-search-reply-to-thread)
|
2009-12-01 01:02:27 +01:00
|
|
|
(define-key map "o" 'notmuch-search-toggle-order)
|
2010-09-18 21:48:22 +02:00
|
|
|
(define-key map "c" 'notmuch-search-stash-map)
|
2009-11-04 02:01:07 +01:00
|
|
|
(define-key map "t" 'notmuch-search-filter-by-tag)
|
2015-06-13 10:08:10 +02:00
|
|
|
(define-key map "l" 'notmuch-search-filter)
|
2009-12-01 01:44:05 +01:00
|
|
|
(define-key map [mouse-1] 'notmuch-search-show-thread)
|
2016-09-20 21:57:16 +02:00
|
|
|
(define-key map "k" 'notmuch-tag-jump)
|
2012-02-05 08:13:47 +01:00
|
|
|
(define-key map "*" 'notmuch-search-tag-all)
|
2009-12-01 01:02:27 +01:00
|
|
|
(define-key map "a" 'notmuch-search-archive-thread)
|
|
|
|
(define-key map "-" 'notmuch-search-remove-tag)
|
|
|
|
(define-key map "+" 'notmuch-search-add-tag)
|
|
|
|
(define-key map (kbd "RET") 'notmuch-search-show-thread)
|
2019-11-13 23:57:52 +01:00
|
|
|
(define-key map (kbd "M-RET") 'notmuch-tree-from-search-thread)
|
2013-11-01 10:23:41 +01:00
|
|
|
(define-key map "Z" 'notmuch-tree-from-search-current-query)
|
2020-02-27 18:16:51 +01:00
|
|
|
(define-key map "U" 'notmuch-unthreaded-from-search-current-query)
|
2009-10-31 09:04:01 +01:00
|
|
|
map)
|
|
|
|
"Keymap for \"notmuch search\" buffers.")
|
|
|
|
|
2021-01-10 15:01:03 +01:00
|
|
|
;;; Internal Variables
|
|
|
|
|
2021-01-10 15:01:05 +01:00
|
|
|
(defvar notmuch-query-history nil
|
|
|
|
"Variable to store minibuffer history for notmuch queries.")
|
|
|
|
|
2021-01-10 15:01:03 +01:00
|
|
|
(defvar-local notmuch-search-query-string nil)
|
|
|
|
(defvar-local notmuch-search-target-thread nil)
|
|
|
|
(defvar-local notmuch-search-target-line nil)
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Stashing
|
|
|
|
|
2010-09-18 21:48:22 +02:00
|
|
|
(defvar notmuch-search-stash-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map "i" 'notmuch-search-stash-thread-id)
|
2015-06-12 10:15:32 +02:00
|
|
|
(define-key map "q" 'notmuch-stash-query)
|
2013-11-14 10:49:46 +01:00
|
|
|
(define-key map "?" 'notmuch-subkeymap-help)
|
2010-09-18 21:48:22 +02:00
|
|
|
map)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Submap for stash commands.")
|
2010-09-18 21:48:22 +02:00
|
|
|
(fset 'notmuch-search-stash-map notmuch-search-stash-map)
|
|
|
|
|
|
|
|
(defun notmuch-search-stash-thread-id ()
|
|
|
|
"Copy thread ID of current thread to kill-ring."
|
|
|
|
(interactive)
|
|
|
|
(notmuch-common-do-stash (notmuch-search-find-thread-id)))
|
|
|
|
|
2015-06-12 10:15:32 +02:00
|
|
|
(defun notmuch-stash-query ()
|
|
|
|
"Copy current query to kill-ring."
|
|
|
|
(interactive)
|
2021-01-10 15:01:04 +01:00
|
|
|
(notmuch-common-do-stash notmuch-search-query-string))
|
2015-06-12 10:15:32 +02:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Movement
|
|
|
|
|
2009-11-04 23:38:49 +01:00
|
|
|
(defun notmuch-search-scroll-up ()
|
2009-12-01 01:52:31 +01:00
|
|
|
"Move forward through search results by one window's worth."
|
2009-11-04 23:38:49 +01:00
|
|
|
(interactive)
|
|
|
|
(condition-case nil
|
|
|
|
(scroll-up nil)
|
2009-12-01 01:52:31 +01:00
|
|
|
((end-of-buffer) (notmuch-search-last-thread))))
|
2009-11-04 23:38:49 +01:00
|
|
|
|
|
|
|
(defun notmuch-search-scroll-down ()
|
2009-12-01 01:52:31 +01:00
|
|
|
"Move backward through the search results by one window's worth."
|
2009-11-04 23:38:49 +01:00
|
|
|
(interactive)
|
2012-01-21 15:44:28 +01:00
|
|
|
;; I don't know why scroll-down doesn't signal beginning-of-buffer
|
|
|
|
;; the way that scroll-up signals end-of-buffer, but c'est la vie.
|
|
|
|
;;
|
|
|
|
;; So instead of trapping a signal we instead check whether the
|
|
|
|
;; window begins on the first line of the buffer and if so, move
|
|
|
|
;; directly to that position. (We have to count lines since the
|
|
|
|
;; window-start position is not the same as point-min due to the
|
|
|
|
;; invisible thread-ID characters on the first line.
|
2009-12-01 01:48:19 +01:00
|
|
|
(if (equal (count-lines (point-min) (window-start)) 0)
|
|
|
|
(goto-char (point-min))
|
2009-11-04 23:38:49 +01:00
|
|
|
(scroll-down nil)))
|
|
|
|
|
2009-12-01 01:52:31 +01:00
|
|
|
(defun notmuch-search-next-thread ()
|
|
|
|
"Select the next thread in the search results."
|
|
|
|
(interactive)
|
2012-08-02 09:19:37 +02:00
|
|
|
(when (notmuch-search-get-result)
|
2012-07-21 19:37:11 +02:00
|
|
|
(goto-char (notmuch-search-result-end))))
|
2009-12-01 01:52:31 +01:00
|
|
|
|
|
|
|
(defun notmuch-search-previous-thread ()
|
|
|
|
"Select the previous thread in the search results."
|
|
|
|
(interactive)
|
2012-07-21 19:37:11 +02:00
|
|
|
(if (notmuch-search-get-result)
|
|
|
|
(unless (bobp)
|
|
|
|
(goto-char (notmuch-search-result-beginning (- (point) 1))))
|
|
|
|
;; We must be past the end; jump to the last result
|
|
|
|
(notmuch-search-last-thread)))
|
2009-12-01 01:52:31 +01:00
|
|
|
|
|
|
|
(defun notmuch-search-last-thread ()
|
|
|
|
"Select the last thread in the search results."
|
2009-11-21 00:58:16 +01:00
|
|
|
(interactive)
|
|
|
|
(goto-char (point-max))
|
2012-07-21 19:37:11 +02:00
|
|
|
(forward-line -2)
|
|
|
|
(let ((beg (notmuch-search-result-beginning)))
|
2020-08-08 13:49:41 +02:00
|
|
|
(when beg
|
|
|
|
(goto-char beg))))
|
2009-11-03 03:23:06 +01:00
|
|
|
|
2009-12-01 01:52:31 +01:00
|
|
|
(defun notmuch-search-first-thread ()
|
|
|
|
"Select the first thread in the search results."
|
|
|
|
(interactive)
|
|
|
|
(goto-char (point-min)))
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Faces
|
|
|
|
|
2009-12-03 18:52:43 +01:00
|
|
|
(defface notmuch-message-summary-face
|
2020-08-08 13:49:45 +02:00
|
|
|
`((((class color) (background light))
|
|
|
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
2020-08-16 19:13:23 +02:00
|
|
|
:background "#f0f0f0")
|
2020-08-08 13:49:45 +02:00
|
|
|
(((class color) (background dark))
|
|
|
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
2020-08-16 19:13:23 +02:00
|
|
|
:background "#303030"))
|
2020-08-08 13:49:38 +02:00
|
|
|
"Face for the single-line message summary in notmuch-show-mode."
|
|
|
|
:group 'notmuch-show
|
|
|
|
:group 'notmuch-faces)
|
2009-12-03 18:52:43 +01:00
|
|
|
|
2010-04-29 09:32:31 +02:00
|
|
|
(defface notmuch-search-date
|
|
|
|
'((t :inherit default))
|
|
|
|
"Face used in search mode for dates."
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2010-04-29 09:32:31 +02:00
|
|
|
|
|
|
|
(defface notmuch-search-count
|
|
|
|
'((t :inherit default))
|
|
|
|
"Face used in search mode for the count matching the query."
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2010-04-29 09:32:31 +02:00
|
|
|
|
|
|
|
(defface notmuch-search-subject
|
|
|
|
'((t :inherit default))
|
|
|
|
"Face used in search mode for subjects."
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2010-04-29 09:32:31 +02:00
|
|
|
|
|
|
|
(defface notmuch-search-matching-authors
|
|
|
|
'((t :inherit default))
|
|
|
|
"Face used in search mode for authors matching the query."
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2010-04-29 09:32:31 +02:00
|
|
|
|
|
|
|
(defface notmuch-search-non-matching-authors
|
2009-11-28 07:07:05 +01:00
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
2010-04-29 09:32:31 +02:00
|
|
|
(:foreground "grey30"))
|
2009-11-28 07:07:05 +01:00
|
|
|
(((class color)
|
|
|
|
(background light))
|
2010-04-29 09:32:31 +02:00
|
|
|
(:foreground "grey60"))
|
2009-11-28 07:07:05 +01:00
|
|
|
(t
|
2010-04-29 09:32:31 +02:00
|
|
|
(:italic t)))
|
|
|
|
"Face used in search mode for authors not matching the query."
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2009-11-28 07:07:05 +01:00
|
|
|
|
2010-04-29 09:32:31 +02:00
|
|
|
(defface notmuch-tag-face
|
2010-04-29 08:52:22 +02:00
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
2010-04-29 09:32:31 +02:00
|
|
|
(:foreground "OliveDrab1"))
|
2010-04-29 08:52:22 +02:00
|
|
|
(((class color)
|
|
|
|
(background light))
|
2010-04-29 09:32:31 +02:00
|
|
|
(:foreground "navy blue" :bold t))
|
|
|
|
(t
|
|
|
|
(:bold t)))
|
|
|
|
"Face used in search mode face for tags."
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2010-04-29 08:52:22 +02:00
|
|
|
|
2016-07-21 23:30:33 +02:00
|
|
|
(defface notmuch-search-flagged-face
|
2016-10-29 00:31:42 +02:00
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "LightBlue1"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
2016-10-12 09:39:21 +02:00
|
|
|
(:foreground "blue")))
|
2016-07-21 23:30:33 +02:00
|
|
|
"Face used in search mode face for flagged threads.
|
|
|
|
|
|
|
|
This face is the default value for the \"flagged\" tag in
|
2020-11-16 22:28:30 +01:00
|
|
|
`notmuch-search-line-faces'."
|
2016-07-21 23:30:33 +02:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
|
|
|
(defface notmuch-search-unread-face
|
|
|
|
'((t
|
2016-10-12 09:39:21 +02:00
|
|
|
(:weight bold)))
|
2016-07-21 23:30:33 +02:00
|
|
|
"Face used in search mode for unread threads.
|
|
|
|
|
|
|
|
This face is the default value for the \"unread\" tag in
|
2020-11-16 22:28:30 +01:00
|
|
|
`notmuch-search-line-faces'."
|
2016-07-21 23:30:33 +02:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Mode
|
|
|
|
|
2016-08-28 20:41:22 +02:00
|
|
|
(define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
|
2009-12-01 01:02:27 +01:00
|
|
|
"Major mode displaying results of a notmuch search.
|
2009-11-04 03:24:13 +01:00
|
|
|
|
|
|
|
This buffer contains the results of a \"notmuch search\" of your
|
|
|
|
email archives. Each line in the buffer represents a single
|
2009-12-01 01:02:27 +01:00
|
|
|
thread giving a summary of the thread (a relative date, the
|
|
|
|
number of matched messages and total messages in the thread,
|
|
|
|
participants in the thread, a representative subject line, and
|
|
|
|
any tags).
|
|
|
|
|
2013-06-02 16:29:17 +02:00
|
|
|
Pressing \\[notmuch-search-show-thread] on any line displays that
|
|
|
|
thread. The '\\[notmuch-search-add-tag]' and
|
|
|
|
'\\[notmuch-search-remove-tag]' keys can be used to add or remove
|
|
|
|
tags from a thread. The '\\[notmuch-search-archive-thread]' key
|
|
|
|
is a convenience for archiving a thread (applying changes in
|
|
|
|
`notmuch-archive-tags'). The '\\[notmuch-search-tag-all]' key can
|
|
|
|
be used to add and/or remove tags from all messages (as opposed
|
|
|
|
to threads) that match the current query. Use with caution, as
|
|
|
|
this will also tag matching messages that arrived *after*
|
|
|
|
constructing the buffer.
|
|
|
|
|
|
|
|
Other useful commands are '\\[notmuch-search-filter]' for
|
|
|
|
filtering the current search based on an additional query string,
|
|
|
|
'\\[notmuch-search-filter-by-tag]' for filtering to include only
|
|
|
|
messages with a given tag, and '\\[notmuch-search]' to execute a
|
|
|
|
new, global search.
|
2009-12-01 01:02:27 +01:00
|
|
|
|
|
|
|
Complete list of currently available key bindings:
|
2009-11-04 03:24:13 +01:00
|
|
|
|
|
|
|
\\{notmuch-search-mode-map}"
|
2013-09-03 23:45:22 +02:00
|
|
|
(setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
|
2020-11-16 22:28:39 +01:00
|
|
|
(setq-local scroll-preserve-screen-position t)
|
emacs: Use a single buffer invisibility spec to fix quadratic search cost.
Buffer redisplay requires traversing the buffer's invisibility spec
for every part of the display that has an 'invisible text or overlay
property. Previously, the search buffer's invisibility spec list
contained roughly one entry for each search result. As a result,
redisplay took O(NM) time where N is the number of visible lines and M
is the total number of results. On a slow computer, this is enough to
make even buffer motion noticeably slow. Worse, during a search
operation, redisplay is triggered for each search result (even if
there are no visible buffer changes), so search was quadratic
(O(NM^2)) in the number of search results.
This change switches to using a single element buffer invisibility
spec. To un-hide authors, instead of removing an entry from the
invisibility spec, it simply removes the invisibility overlay from
those authors.
I tested using a query with 6633 results on a 9 year old machine.
Before this patch, Emacs took 70 seconds to fill the search buffer;
toward the end of the search, Emacs consumed 10-20x as much CPU as
notmuch; and moving point in the buffer took about a second. With
this patch, the same query takes 40 seconds, Emacs consumes ~3x the
CPU of notmuch by the end, and there's no noticeable lag to moving
point. (There's still some source of non-linearity, because Emacs and
notmuch consume roughly the same amount of CPU early in the search.)
2011-11-09 03:55:28 +01:00
|
|
|
(add-to-invisibility-spec (cons 'ellipsis t))
|
2009-11-18 09:12:31 +01:00
|
|
|
(setq truncate-lines t)
|
2017-06-12 15:30:10 +02:00
|
|
|
(setq buffer-read-only t)
|
|
|
|
(setq imenu-prev-index-position-function
|
2020-08-08 13:49:38 +02:00
|
|
|
#'notmuch-search-imenu-prev-index-position-function)
|
2017-06-12 15:30:10 +02:00
|
|
|
(setq imenu-extract-index-name-function
|
2020-08-08 13:49:38 +02:00
|
|
|
#'notmuch-search-imenu-extract-index-name-function))
|
2009-10-30 23:17:27 +01:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Search Results
|
|
|
|
|
2012-07-21 19:37:05 +02:00
|
|
|
(defun notmuch-search-get-result (&optional pos)
|
|
|
|
"Return the result object for the thread at POS (or point).
|
|
|
|
|
|
|
|
If there is no thread at POS (or point), returns nil."
|
|
|
|
(get-text-property (or pos (point)) 'notmuch-search-result))
|
|
|
|
|
|
|
|
(defun notmuch-search-result-beginning (&optional pos)
|
|
|
|
"Return the point at the beginning of the thread at POS (or point).
|
|
|
|
|
|
|
|
If there is no thread at POS (or point), returns nil."
|
2020-08-08 13:49:41 +02:00
|
|
|
(and (notmuch-search-get-result pos)
|
|
|
|
;; We pass 1+point because previous-single-property-change starts
|
|
|
|
;; searching one before the position we give it.
|
|
|
|
(previous-single-property-change (1+ (or pos (point)))
|
|
|
|
'notmuch-search-result nil
|
|
|
|
(point-min))))
|
2012-07-21 19:37:05 +02:00
|
|
|
|
|
|
|
(defun notmuch-search-result-end (&optional pos)
|
|
|
|
"Return the point at the end of the thread at POS (or point).
|
|
|
|
|
|
|
|
The returned point will be just after the newline character that
|
|
|
|
ends the result line. If there is no thread at POS (or point),
|
2020-05-24 21:17:56 +02:00
|
|
|
returns nil."
|
2020-08-08 13:49:41 +02:00
|
|
|
(and (notmuch-search-get-result pos)
|
|
|
|
(next-single-property-change (or pos (point))
|
|
|
|
'notmuch-search-result nil
|
|
|
|
(point-max))))
|
2012-07-21 19:37:05 +02:00
|
|
|
|
2017-04-08 19:03:29 +02:00
|
|
|
(defun notmuch-search-foreach-result (beg end fn)
|
|
|
|
"Invoke FN for each result between BEG and END.
|
2012-07-21 19:37:08 +02:00
|
|
|
|
2020-08-08 13:49:50 +02:00
|
|
|
FN should take one argument. It will be applied to the character
|
|
|
|
position of the beginning of each result that overlaps the region
|
|
|
|
between points BEG and END. As a special case, if (= BEG END),
|
|
|
|
FN will be applied to the result containing point BEG."
|
2020-04-25 22:18:07 +02:00
|
|
|
(let ((pos (notmuch-search-result-beginning beg))
|
|
|
|
;; End must be a marker in case fn changes the
|
|
|
|
;; text.
|
|
|
|
(end (copy-marker end))
|
|
|
|
;; Make sure we examine at least one result, even if
|
|
|
|
;; (= beg end).
|
|
|
|
(first t))
|
2012-07-21 19:37:08 +02:00
|
|
|
;; We have to be careful if the region extends beyond the results.
|
|
|
|
;; In this case, pos could be null or there could be no result at
|
|
|
|
;; pos.
|
|
|
|
(while (and pos (or (< pos end) first))
|
|
|
|
(when (notmuch-search-get-result pos)
|
2017-04-08 19:03:29 +02:00
|
|
|
(funcall fn pos))
|
2020-08-08 13:49:40 +02:00
|
|
|
(setq pos (notmuch-search-result-end pos))
|
|
|
|
(setq first nil))))
|
2012-07-21 19:37:08 +02:00
|
|
|
;; Unindent the function argument of notmuch-search-foreach-result so
|
|
|
|
;; the indentation of callers doesn't get out of hand.
|
|
|
|
(put 'notmuch-search-foreach-result 'lisp-indent-function 2)
|
|
|
|
|
2010-02-17 01:07:40 +01:00
|
|
|
(defun notmuch-search-properties-in-region (property beg end)
|
2012-07-21 19:37:08 +02:00
|
|
|
(let (output)
|
|
|
|
(notmuch-search-foreach-result beg end
|
|
|
|
(lambda (pos)
|
2012-07-21 19:37:09 +02:00
|
|
|
(push (plist-get (notmuch-search-get-result pos) property) output)))
|
2012-07-21 19:37:08 +02:00
|
|
|
output))
|
2010-02-17 01:07:40 +01:00
|
|
|
|
2012-08-07 18:32:18 +02:00
|
|
|
(defun notmuch-search-find-thread-id (&optional bare)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return the thread for the current thread.
|
2012-08-07 18:32:18 +02:00
|
|
|
|
2020-05-24 21:17:56 +02:00
|
|
|
If BARE is set then do not prefix with \"thread:\"."
|
2012-07-21 19:37:09 +02:00
|
|
|
(let ((thread (plist-get (notmuch-search-get-result) :thread)))
|
2020-08-08 13:49:41 +02:00
|
|
|
(when thread
|
|
|
|
(concat (and (not bare) "thread:") thread))))
|
2009-10-31 09:41:44 +01:00
|
|
|
|
2013-10-24 17:19:11 +02:00
|
|
|
(defun notmuch-search-find-stable-query ()
|
|
|
|
"Return the stable queries for the current thread.
|
|
|
|
|
2021-01-10 15:01:01 +01:00
|
|
|
Return a list (MATCHED-QUERY UNMATCHED-QUERY) for the
|
2013-10-24 17:19:11 +02:00
|
|
|
matched and unmatched messages in the current thread."
|
|
|
|
(plist-get (notmuch-search-get-result) :query))
|
|
|
|
|
|
|
|
(defun notmuch-search-find-stable-query-region (beg end &optional only-matched)
|
|
|
|
"Return the stable query for the current region.
|
|
|
|
|
|
|
|
If ONLY-MATCHED is non-nil, include only matched messages. If it
|
2014-05-21 11:58:50 +02:00
|
|
|
is nil, include both matched and unmatched messages. If there are
|
|
|
|
no messages in the region then return nil."
|
2013-10-24 17:19:11 +02:00
|
|
|
(let ((query-list nil) (all (not only-matched)))
|
|
|
|
(dolist (queries (notmuch-search-properties-in-region :query beg end))
|
2020-04-25 22:18:07 +02:00
|
|
|
(when (car queries)
|
|
|
|
(push (car queries) query-list))
|
|
|
|
(when (and all (cadr queries))
|
|
|
|
(push (cadr queries) query-list)))
|
2020-08-08 13:49:41 +02:00
|
|
|
(and query-list
|
|
|
|
(concat "(" (mapconcat 'identity query-list ") or (") ")"))))
|
2012-02-05 08:13:44 +01:00
|
|
|
|
2009-12-05 03:26:36 +01:00
|
|
|
(defun notmuch-search-find-authors ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return the authors for the current thread."
|
2012-07-21 19:37:09 +02:00
|
|
|
(plist-get (notmuch-search-get-result) :authors))
|
2009-12-05 03:26:36 +01:00
|
|
|
|
2010-02-17 01:07:40 +01:00
|
|
|
(defun notmuch-search-find-authors-region (beg end)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return a list of authors for the current region."
|
2012-07-21 19:37:09 +02:00
|
|
|
(notmuch-search-properties-in-region :authors beg end))
|
2010-02-17 01:07:40 +01:00
|
|
|
|
2009-12-05 03:26:36 +01:00
|
|
|
(defun notmuch-search-find-subject ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return the subject for the current thread."
|
2012-07-21 19:37:09 +02:00
|
|
|
(plist-get (notmuch-search-get-result) :subject))
|
2009-12-05 03:26:36 +01:00
|
|
|
|
2010-02-17 01:07:40 +01:00
|
|
|
(defun notmuch-search-find-subject-region (beg end)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return a list of authors for the current region."
|
2012-07-21 19:37:09 +02:00
|
|
|
(notmuch-search-properties-in-region :subject beg end))
|
2010-02-17 01:07:40 +01:00
|
|
|
|
2013-10-13 09:39:12 +02:00
|
|
|
(defun notmuch-search-show-thread (&optional elide-toggle)
|
2016-02-11 09:33:27 +01:00
|
|
|
"Display the currently selected thread.
|
|
|
|
|
|
|
|
With a prefix argument, invert the default value of
|
|
|
|
`notmuch-show-only-matching-messages' when displaying the
|
|
|
|
thread."
|
2013-10-13 09:39:12 +02:00
|
|
|
(interactive "P")
|
2021-01-10 15:01:06 +01:00
|
|
|
(let ((thread-id (notmuch-search-find-thread-id)))
|
|
|
|
(if thread-id
|
2012-01-30 11:16:01 +01:00
|
|
|
(notmuch-show thread-id
|
2013-10-13 09:39:12 +02:00
|
|
|
elide-toggle
|
2012-01-30 11:16:01 +01:00
|
|
|
(current-buffer)
|
|
|
|
notmuch-search-query-string
|
|
|
|
;; Name the buffer based on the subject.
|
2021-01-10 15:01:06 +01:00
|
|
|
(format "*%s*" (truncate-string-to-width
|
|
|
|
(notmuch-search-find-subject)
|
|
|
|
30 nil nil t)))
|
2011-12-20 09:45:14 +01:00
|
|
|
(message "End of search results."))))
|
2009-10-31 09:41:44 +01:00
|
|
|
|
2013-11-01 10:23:43 +01:00
|
|
|
(defun notmuch-tree-from-search-current-query ()
|
2021-10-23 15:12:58 +02:00
|
|
|
"Tree view of current query."
|
2013-11-01 10:23:43 +01:00
|
|
|
(interactive)
|
|
|
|
(notmuch-tree notmuch-search-query-string))
|
|
|
|
|
2020-02-27 18:16:51 +01:00
|
|
|
(defun notmuch-unthreaded-from-search-current-query ()
|
2021-10-23 15:12:58 +02:00
|
|
|
"Unthreaded view of current query."
|
2020-02-27 18:16:51 +01:00
|
|
|
(interactive)
|
|
|
|
(notmuch-unthreaded notmuch-search-query-string))
|
|
|
|
|
2013-11-01 10:23:43 +01:00
|
|
|
(defun notmuch-tree-from-search-thread ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Show the selected thread with notmuch-tree."
|
2013-11-01 10:23:43 +01:00
|
|
|
(interactive)
|
|
|
|
(notmuch-tree (notmuch-search-find-thread-id)
|
2020-05-24 21:17:56 +02:00
|
|
|
notmuch-search-query-string
|
2013-11-01 10:23:43 +01:00
|
|
|
nil
|
2020-05-24 21:17:56 +02:00
|
|
|
(notmuch-prettify-subject (notmuch-search-find-subject))
|
2020-08-11 19:36:51 +02:00
|
|
|
t nil (current-buffer)))
|
2013-11-01 10:23:43 +01:00
|
|
|
|
2011-05-26 10:41:33 +02:00
|
|
|
(defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
|
2012-01-14 15:46:17 +01:00
|
|
|
"Begin composing a reply-all to the entire current thread in a new buffer."
|
|
|
|
(interactive "P")
|
2021-01-10 15:01:06 +01:00
|
|
|
(notmuch-mua-new-reply (notmuch-search-find-thread-id)
|
|
|
|
prompt-for-sender t))
|
2012-01-14 15:46:17 +01:00
|
|
|
|
|
|
|
(defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
|
2009-11-19 00:21:24 +01:00
|
|
|
"Begin composing a reply to the entire current thread in a new buffer."
|
2011-05-26 10:41:33 +02:00
|
|
|
(interactive "P")
|
2021-01-10 15:01:06 +01:00
|
|
|
(notmuch-mua-new-reply (notmuch-search-find-thread-id)
|
|
|
|
prompt-for-sender nil))
|
2009-11-19 00:21:24 +01:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Tags
|
|
|
|
|
2012-07-21 19:37:07 +02:00
|
|
|
(defun notmuch-search-set-tags (tags &optional pos)
|
2021-01-10 15:01:06 +01:00
|
|
|
(notmuch-search-update-result
|
|
|
|
(plist-put (notmuch-search-get-result pos) :tags tags)
|
|
|
|
pos))
|
2012-07-21 19:37:07 +02:00
|
|
|
|
|
|
|
(defun notmuch-search-get-tags (&optional pos)
|
|
|
|
(plist-get (notmuch-search-get-result pos) :tags))
|
2009-11-03 00:48:21 +01:00
|
|
|
|
2010-02-17 01:07:40 +01:00
|
|
|
(defun notmuch-search-get-tags-region (beg end)
|
2012-07-21 19:37:08 +02:00
|
|
|
(let (output)
|
|
|
|
(notmuch-search-foreach-result beg end
|
|
|
|
(lambda (pos)
|
|
|
|
(setq output (append output (notmuch-search-get-tags pos)))))
|
2021-02-03 10:10:20 +01:00
|
|
|
(delete-dups output)))
|
2010-02-17 01:07:40 +01:00
|
|
|
|
2013-10-23 02:21:57 +02:00
|
|
|
(defun notmuch-search-interactive-tag-changes (&optional initial-input)
|
|
|
|
"Prompt for tag changes for the current thread or region.
|
|
|
|
|
2021-01-10 15:01:01 +01:00
|
|
|
Return (TAG-CHANGES REGION-BEGIN REGION-END)."
|
2020-04-25 22:18:07 +02:00
|
|
|
(pcase-let ((`(,beg ,end) (notmuch-interactive-region)))
|
|
|
|
(list (notmuch-read-tag-changes (notmuch-search-get-tags-region beg end)
|
|
|
|
(if (= beg end) "Tag thread" "Tag region")
|
|
|
|
initial-input)
|
|
|
|
beg end)))
|
2013-10-23 02:21:57 +02:00
|
|
|
|
2013-10-24 17:19:11 +02:00
|
|
|
(defun notmuch-search-tag (tag-changes &optional beg end only-matched)
|
2013-10-23 02:21:57 +02:00
|
|
|
"Change tags for the currently selected thread or region.
|
|
|
|
|
|
|
|
See `notmuch-tag' for information on the format of TAG-CHANGES.
|
|
|
|
When called interactively, this uses the region if the region is
|
|
|
|
active. When called directly, BEG and END provide the region.
|
2016-10-16 18:12:23 +02:00
|
|
|
If these are nil or not provided, then, if the region is active
|
|
|
|
this applied to all threads meeting the region, and if the region
|
|
|
|
is inactive this applies to the thread at point.
|
2013-10-24 17:19:11 +02:00
|
|
|
|
|
|
|
If ONLY-MATCHED is non-nil, only tag matched messages."
|
2013-10-23 02:21:57 +02:00
|
|
|
(interactive (notmuch-search-interactive-tag-changes))
|
2016-10-16 18:12:23 +02:00
|
|
|
(unless (and beg end)
|
2020-08-08 13:49:40 +02:00
|
|
|
(setq beg (car (notmuch-interactive-region)))
|
|
|
|
(setq end (cadr (notmuch-interactive-region))))
|
2013-10-24 17:19:11 +02:00
|
|
|
(let ((search-string (notmuch-search-find-stable-query-region
|
|
|
|
beg end only-matched)))
|
2013-10-23 02:21:57 +02:00
|
|
|
(notmuch-tag search-string tag-changes)
|
2012-07-21 19:37:08 +02:00
|
|
|
(notmuch-search-foreach-result beg end
|
|
|
|
(lambda (pos)
|
|
|
|
(notmuch-search-set-tags
|
|
|
|
(notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)
|
|
|
|
pos)))))
|
2010-02-17 01:07:40 +01:00
|
|
|
|
2013-10-23 02:21:57 +02:00
|
|
|
(defun notmuch-search-add-tag (tag-changes &optional beg end)
|
|
|
|
"Change tags for the current thread or region (defaulting to add).
|
2013-10-06 05:22:47 +02:00
|
|
|
|
|
|
|
Same as `notmuch-search-tag' but sets initial input to '+'."
|
2013-10-23 02:21:57 +02:00
|
|
|
(interactive (notmuch-search-interactive-tag-changes "+"))
|
|
|
|
(notmuch-search-tag tag-changes beg end))
|
2009-12-01 01:52:31 +01:00
|
|
|
|
2013-10-23 02:21:57 +02:00
|
|
|
(defun notmuch-search-remove-tag (tag-changes &optional beg end)
|
|
|
|
"Change tags for the current thread or region (defaulting to remove).
|
2013-10-06 05:22:47 +02:00
|
|
|
|
|
|
|
Same as `notmuch-search-tag' but sets initial input to '-'."
|
2013-10-23 02:21:57 +02:00
|
|
|
(interactive (notmuch-search-interactive-tag-changes "-"))
|
|
|
|
(notmuch-search-tag tag-changes beg end))
|
2009-10-31 20:09:06 +01:00
|
|
|
|
2013-10-06 05:22:47 +02:00
|
|
|
(put 'notmuch-search-archive-thread 'notmuch-prefix-doc
|
|
|
|
"Un-archive the currently selected thread.")
|
2013-10-23 02:21:57 +02:00
|
|
|
(defun notmuch-search-archive-thread (&optional unarchive beg end)
|
|
|
|
"Archive the currently selected thread or region.
|
2012-09-06 17:32:40 +02:00
|
|
|
|
|
|
|
Archive each message in the currently selected thread by applying
|
|
|
|
the tag changes in `notmuch-archive-tags' to each (remove the
|
|
|
|
\"inbox\" tag by default). If a prefix argument is given, the
|
|
|
|
messages will be \"unarchived\" (i.e. the tag changes in
|
|
|
|
`notmuch-archive-tags' will be reversed).
|
2009-11-04 02:18:04 +01:00
|
|
|
|
2009-12-01 01:52:31 +01:00
|
|
|
This function advances the next thread when finished."
|
2019-04-09 18:47:12 +02:00
|
|
|
(interactive (cons current-prefix-arg (notmuch-interactive-region)))
|
2012-09-06 17:32:40 +02:00
|
|
|
(when notmuch-archive-tags
|
|
|
|
(notmuch-search-tag
|
2013-10-23 02:21:57 +02:00
|
|
|
(notmuch-tag-change-list notmuch-archive-tags unarchive) beg end))
|
2014-06-06 14:48:33 +02:00
|
|
|
(when (eq beg end)
|
|
|
|
(notmuch-search-next-thread)))
|
2009-10-31 09:55:12 +01:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Search Results
|
|
|
|
|
2012-07-21 19:37:07 +02:00
|
|
|
(defun notmuch-search-update-result (result &optional pos)
|
|
|
|
"Replace the result object of the thread at POS (or point) by
|
|
|
|
RESULT and redraw it.
|
|
|
|
|
|
|
|
This will keep point in a reasonable location. However, if there
|
|
|
|
are enclosing save-excursions and the saved point is in the
|
|
|
|
result being updated, the point will be restored to the beginning
|
|
|
|
of the result."
|
|
|
|
(let ((start (notmuch-search-result-beginning pos))
|
|
|
|
(end (notmuch-search-result-end pos))
|
|
|
|
(init-point (point))
|
|
|
|
(inhibit-read-only t))
|
|
|
|
;; Delete the current thread
|
|
|
|
(delete-region start end)
|
|
|
|
;; Insert the updated thread
|
|
|
|
(notmuch-search-show-result result start)
|
|
|
|
;; If point was inside the old result, make an educated guess
|
|
|
|
;; about where to place it now. Unfortunately, this won't work
|
|
|
|
;; with save-excursion (or any other markers that would be nice to
|
|
|
|
;; preserve, such as the window start), but there's nothing we can
|
|
|
|
;; do about that without a way to retrieve markers in a region.
|
|
|
|
(when (and (>= init-point start) (<= init-point end))
|
|
|
|
(let* ((new-end (notmuch-search-result-end start))
|
|
|
|
(new-point (if (= init-point end)
|
|
|
|
new-end
|
|
|
|
(min init-point (- new-end 1)))))
|
|
|
|
(goto-char new-point)))))
|
|
|
|
|
2021-01-10 15:00:48 +01:00
|
|
|
(defun notmuch-search-process-sentinel (proc _msg)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Add a message to let user know when \"notmuch search\" exits."
|
2009-11-25 03:49:58 +01:00
|
|
|
(let ((buffer (process-buffer proc))
|
|
|
|
(status (process-status proc))
|
2010-03-09 20:36:08 +01:00
|
|
|
(exit-status (process-exit-status proc))
|
|
|
|
(never-found-target-thread nil))
|
2012-07-09 23:42:41 +02:00
|
|
|
(when (memq status '(exit signal))
|
2012-12-15 21:04:19 +01:00
|
|
|
(catch 'return
|
2012-07-09 23:42:41 +02:00
|
|
|
(kill-buffer (process-get proc 'parse-buf))
|
2020-08-08 13:49:43 +02:00
|
|
|
(when (buffer-live-p buffer)
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(save-excursion
|
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
(atbob (bobp)))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(when (eq status 'signal)
|
|
|
|
(insert "Incomplete search results (search process was killed).\n"))
|
|
|
|
(when (eq status 'exit)
|
|
|
|
(insert "End of search results.\n")
|
|
|
|
;; For version mismatch, there's no point in
|
|
|
|
;; showing the search buffer
|
|
|
|
(when (or (= exit-status 20) (= exit-status 21))
|
|
|
|
(kill-buffer)
|
|
|
|
(throw 'return nil))
|
|
|
|
(when (and atbob
|
2012-02-01 14:50:00 +01:00
|
|
|
(not (string= notmuch-search-target-thread "found")))
|
2021-01-10 15:00:37 +01:00
|
|
|
(setq never-found-target-thread t)))))
|
2020-08-08 13:49:43 +02:00
|
|
|
(when (and never-found-target-thread
|
|
|
|
notmuch-search-target-line)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (1- notmuch-search-target-line)))))))))
|
2009-11-25 03:49:58 +01:00
|
|
|
|
2016-10-15 11:40:48 +02:00
|
|
|
(define-widget 'notmuch--custom-face-edit 'lazy
|
|
|
|
"Custom face edit with a tag Edit Face"
|
|
|
|
;; I could not persuage custom-face-edit to respect the :tag
|
|
|
|
;; property so create a widget specially
|
|
|
|
:tag "Manually specify face"
|
|
|
|
:type 'custom-face-edit)
|
|
|
|
|
2016-07-21 23:30:33 +02:00
|
|
|
(defcustom notmuch-search-line-faces
|
2016-10-15 11:40:48 +02:00
|
|
|
'(("unread" . notmuch-search-unread-face)
|
|
|
|
("flagged" . notmuch-search-flagged-face))
|
2016-07-21 23:30:33 +02:00
|
|
|
"Alist of tags to faces for line highlighting in notmuch-search.
|
|
|
|
Each element looks like (TAG . FACE).
|
|
|
|
A thread with TAG will have FACE applied.
|
2010-02-04 13:07:26 +01:00
|
|
|
|
|
|
|
Here is an example of how to color search results based on tags.
|
2010-05-19 09:03:30 +02:00
|
|
|
(the following text would be placed in your ~/.emacs file):
|
2010-02-04 13:07:26 +01:00
|
|
|
|
2018-06-14 02:32:37 +02:00
|
|
|
(setq notmuch-search-line-faces \\='((\"unread\" . (:foreground \"green\"))
|
2020-08-08 13:49:38 +02:00
|
|
|
(\"deleted\" . (:foreground \"red\"
|
2014-05-06 12:03:30 +02:00
|
|
|
:background \"blue\"))))
|
2010-02-04 13:07:26 +01:00
|
|
|
|
2016-07-21 23:30:33 +02:00
|
|
|
The FACE must be a face name (a symbol or string), a property
|
|
|
|
list of face attributes, or a list of these. The faces for
|
|
|
|
matching tags are merged, with earlier attributes overriding
|
|
|
|
later. A message having both \"deleted\" and \"unread\" tags with
|
|
|
|
the above settings would have a green foreground and blue
|
|
|
|
background."
|
2016-10-15 11:40:48 +02:00
|
|
|
:type '(alist :key-type (string)
|
|
|
|
:value-type (radio (face :tag "Face name")
|
2020-08-08 13:49:38 +02:00
|
|
|
(notmuch--custom-face-edit)))
|
2012-01-16 11:38:33 +01:00
|
|
|
:group 'notmuch-search
|
|
|
|
:group 'notmuch-faces)
|
2010-02-04 13:07:26 +01:00
|
|
|
|
|
|
|
(defun notmuch-search-color-line (start end line-tag-list)
|
2010-06-07 16:35:10 +02:00
|
|
|
"Colorize lines in `notmuch-show' based on tags."
|
2016-08-15 00:13:00 +02:00
|
|
|
;; Reverse the list so earlier entries take precedence
|
|
|
|
(dolist (elem (reverse notmuch-search-line-faces))
|
|
|
|
(let ((tag (car elem))
|
|
|
|
(face (cdr elem)))
|
|
|
|
(when (member tag line-tag-list)
|
|
|
|
(notmuch-apply-face nil face nil start end)))))
|
2010-02-04 13:07:26 +01:00
|
|
|
|
2010-11-17 13:05:04 +01:00
|
|
|
(defun notmuch-search-author-propertize (authors)
|
|
|
|
"Split `authors' into matching and non-matching authors and
|
|
|
|
propertize appropriately. If no boundary between authors and
|
|
|
|
non-authors is found, assume that all of the authors match."
|
|
|
|
(if (string-match "\\(.*\\)|\\(.*\\)" authors)
|
|
|
|
(concat (propertize (concat (match-string 1 authors) ",")
|
|
|
|
'face 'notmuch-search-matching-authors)
|
|
|
|
(propertize (match-string 2 authors)
|
|
|
|
'face 'notmuch-search-non-matching-authors))
|
|
|
|
(propertize authors 'face 'notmuch-search-matching-authors)))
|
|
|
|
|
2010-04-29 08:52:22 +02:00
|
|
|
(defun notmuch-search-insert-authors (format-string authors)
|
2010-11-17 13:05:04 +01:00
|
|
|
;; Save the match data to avoid interfering with
|
|
|
|
;; `notmuch-search-process-filter'.
|
|
|
|
(save-match-data
|
|
|
|
(let* ((formatted-authors (format format-string authors))
|
|
|
|
(formatted-sample (format format-string ""))
|
|
|
|
(visible-string formatted-authors)
|
|
|
|
(invisible-string "")
|
|
|
|
(padding ""))
|
|
|
|
;; Truncate the author string to fit the specification.
|
2020-08-08 13:49:43 +02:00
|
|
|
(when (> (length formatted-authors)
|
|
|
|
(length formatted-sample))
|
|
|
|
(let ((visible-length (- (length formatted-sample)
|
|
|
|
(length "... "))))
|
|
|
|
;; Truncate the visible string according to the width of
|
|
|
|
;; the display string.
|
|
|
|
(setq visible-string (substring formatted-authors 0 visible-length))
|
|
|
|
(setq invisible-string (substring formatted-authors visible-length))
|
|
|
|
;; If possible, truncate the visible string at a natural
|
|
|
|
;; break (comma or pipe), as incremental search doesn't
|
|
|
|
;; match across the visible/invisible border.
|
|
|
|
(when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string)
|
|
|
|
;; Second clause is destructive on `visible-string', so
|
|
|
|
;; order is important.
|
|
|
|
(setq invisible-string (concat (match-string 3 visible-string)
|
|
|
|
invisible-string))
|
|
|
|
(setq visible-string (concat (match-string 1 visible-string)
|
|
|
|
(match-string 2 visible-string))))
|
|
|
|
;; `visible-string' may be shorter than the space allowed
|
|
|
|
;; by `format-string'. If so we must insert some padding
|
|
|
|
;; after `invisible-string'.
|
|
|
|
(setq padding (make-string (- (length formatted-sample)
|
|
|
|
(length visible-string)
|
|
|
|
(length "..."))
|
|
|
|
? ))))
|
2010-11-17 13:05:04 +01:00
|
|
|
;; Use different faces to show matching and non-matching authors.
|
|
|
|
(if (string-match "\\(.*\\)|\\(.*\\)" visible-string)
|
|
|
|
;; The visible string contains both matching and
|
|
|
|
;; non-matching authors.
|
2020-08-08 13:49:40 +02:00
|
|
|
(progn
|
|
|
|
(setq visible-string (notmuch-search-author-propertize visible-string))
|
|
|
|
;; The invisible string must contain only non-matching
|
|
|
|
;; authors, as the visible-string contains both.
|
|
|
|
(setq invisible-string (propertize invisible-string
|
|
|
|
'face 'notmuch-search-non-matching-authors)))
|
2010-11-17 13:05:04 +01:00
|
|
|
;; The visible string contains only matching authors.
|
|
|
|
(setq visible-string (propertize visible-string
|
2020-08-08 13:49:40 +02:00
|
|
|
'face 'notmuch-search-matching-authors))
|
|
|
|
;; The invisible string may contain both matching and
|
|
|
|
;; non-matching authors.
|
|
|
|
(setq invisible-string (notmuch-search-author-propertize invisible-string)))
|
2010-11-17 13:05:04 +01:00
|
|
|
;; If there is any invisible text, add it as a tooltip to the
|
|
|
|
;; visible text.
|
2021-01-10 15:01:09 +01:00
|
|
|
(unless (string-empty-p invisible-string)
|
2020-08-08 13:49:36 +02:00
|
|
|
(setq visible-string
|
|
|
|
(propertize visible-string
|
|
|
|
'help-echo (concat "..." invisible-string))))
|
2010-11-17 13:05:04 +01:00
|
|
|
;; Insert the visible and, if present, invisible author strings.
|
|
|
|
(insert visible-string)
|
2021-01-10 15:01:09 +01:00
|
|
|
(unless (string-empty-p invisible-string)
|
2010-11-17 13:05:04 +01:00
|
|
|
(let ((start (point))
|
|
|
|
overlay)
|
|
|
|
(insert invisible-string)
|
|
|
|
(setq overlay (make-overlay start (point)))
|
emacs: Use a single buffer invisibility spec to fix quadratic search cost.
Buffer redisplay requires traversing the buffer's invisibility spec
for every part of the display that has an 'invisible text or overlay
property. Previously, the search buffer's invisibility spec list
contained roughly one entry for each search result. As a result,
redisplay took O(NM) time where N is the number of visible lines and M
is the total number of results. On a slow computer, this is enough to
make even buffer motion noticeably slow. Worse, during a search
operation, redisplay is triggered for each search result (even if
there are no visible buffer changes), so search was quadratic
(O(NM^2)) in the number of search results.
This change switches to using a single element buffer invisibility
spec. To un-hide authors, instead of removing an entry from the
invisibility spec, it simply removes the invisibility overlay from
those authors.
I tested using a query with 6633 results on a 9 year old machine.
Before this patch, Emacs took 70 seconds to fill the search buffer;
toward the end of the search, Emacs consumed 10-20x as much CPU as
notmuch; and moving point in the buffer took about a second. With
this patch, the same query takes 40 seconds, Emacs consumes ~3x the
CPU of notmuch by the end, and there's no noticeable lag to moving
point. (There's still some source of non-linearity, because Emacs and
notmuch consume roughly the same amount of CPU early in the search.)
2011-11-09 03:55:28 +01:00
|
|
|
(overlay-put overlay 'invisible 'ellipsis)
|
|
|
|
(overlay-put overlay 'isearch-open-invisible #'delete-overlay)))
|
2010-11-17 13:05:04 +01:00
|
|
|
(insert padding))))
|
2010-04-29 08:52:22 +02:00
|
|
|
|
2012-07-09 23:42:38 +02:00
|
|
|
(defun notmuch-search-insert-field (field format-string result)
|
2021-02-21 16:19:00 +01:00
|
|
|
(pcase field
|
2021-02-21 16:19:01 +01:00
|
|
|
((pred functionp)
|
|
|
|
(insert (funcall field format-string result)))
|
2021-02-21 16:19:00 +01:00
|
|
|
("date"
|
|
|
|
(insert (propertize (format format-string (plist-get result :date_relative))
|
|
|
|
'face 'notmuch-search-date)))
|
|
|
|
("count"
|
|
|
|
(insert (propertize (format format-string
|
|
|
|
(format "[%s/%s]" (plist-get result :matched)
|
|
|
|
(plist-get result :total)))
|
|
|
|
'face 'notmuch-search-count)))
|
|
|
|
("subject"
|
|
|
|
(insert (propertize (format format-string
|
|
|
|
(notmuch-sanitize (plist-get result :subject)))
|
|
|
|
'face 'notmuch-search-subject)))
|
|
|
|
("authors"
|
|
|
|
(notmuch-search-insert-authors format-string
|
|
|
|
(notmuch-sanitize (plist-get result :authors))))
|
|
|
|
("tags"
|
|
|
|
(let ((tags (plist-get result :tags))
|
|
|
|
(orig-tags (plist-get result :orig-tags)))
|
|
|
|
(insert (format format-string (notmuch-tag-format-tags tags orig-tags)))))))
|
2010-04-12 09:51:30 +02:00
|
|
|
|
2014-03-22 12:51:11 +01:00
|
|
|
(defun notmuch-search-show-result (result pos)
|
|
|
|
"Insert RESULT at POS."
|
2012-07-09 23:42:35 +02:00
|
|
|
;; Ignore excluded matches
|
2012-07-09 23:42:38 +02:00
|
|
|
(unless (= (plist-get result :matched) 0)
|
2014-03-22 12:51:11 +01:00
|
|
|
(save-excursion
|
|
|
|
(goto-char pos)
|
|
|
|
(dolist (spec notmuch-search-result-format)
|
|
|
|
(notmuch-search-insert-field (car spec) (cdr spec) result))
|
|
|
|
(insert "\n")
|
|
|
|
(notmuch-search-color-line pos (point) (plist-get result :tags))
|
|
|
|
(put-text-property pos (point) 'notmuch-search-result result))))
|
|
|
|
|
|
|
|
(defun notmuch-search-append-result (result)
|
|
|
|
"Insert RESULT at the end of the buffer.
|
|
|
|
|
|
|
|
This is only called when a result is first inserted so it also
|
|
|
|
sets the :orig-tag property."
|
|
|
|
(let ((new-result (plist-put result :orig-tags (plist-get result :tags)))
|
|
|
|
(pos (point-max)))
|
|
|
|
(notmuch-search-show-result new-result pos)
|
|
|
|
(when (string= (plist-get result :thread) notmuch-search-target-thread)
|
|
|
|
(setq notmuch-search-target-thread "found")
|
|
|
|
(goto-char pos))))
|
2010-04-12 09:51:30 +02:00
|
|
|
|
2021-09-13 03:03:50 +02:00
|
|
|
(defvar-local notmuch--search-hook-run nil
|
|
|
|
"Flag used to ensure the notmuch-search-hook is only run once per buffer")
|
|
|
|
|
|
|
|
(defun notmuch--search-hook-wrapper ()
|
|
|
|
(unless notmuch--search-hook-run
|
|
|
|
(setq notmuch--search-hook-run t)
|
|
|
|
(run-hooks 'notmuch-search-hook)))
|
|
|
|
|
2009-11-25 03:49:58 +01:00
|
|
|
(defun notmuch-search-process-filter (proc string)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Process and filter the output of \"notmuch search\"."
|
2012-07-09 23:42:41 +02:00
|
|
|
(let ((results-buf (process-buffer proc))
|
|
|
|
(parse-buf (process-get proc 'parse-buf))
|
2021-01-10 15:00:48 +01:00
|
|
|
(inhibit-read-only t))
|
emacs: Fix "no such file or directory" error
Occasionally, when the user killed the search buffer when the CLI
process was still running, Emacs would run the
notmuch-start-notmuch-sentinel sentinel twice. The first call would
process and delete the error output file and the second would fail
with an "Opening input file: no such file or directory, ..." error
when attempting to access the error file.
Emacs isn't supposed to run the sentinel twice. The reason it does is
rather subtle (and probably a bug in Emacs):
1) When the user kills the search buffer, Emacs invokes
kill_buffer_processes, which sends a SIGHUP to notmuch, but doesn't do
anything else. Meanwhile, suppose the notmuch search process has
printed some more output, but Emacs hasn't consumed it yet (this is
critical and is why this error only happens sometimes).
2) Emacs gets a SIGCHLD from the dying notmuch process, which invokes
handle_child_signal, which sets the new process status, but can't do
anything else because it's a signal handler.
3) Emacs returns to its idle loop, which calls status_notify, which
sees that the notmuch process has a new status. This is where things
get interesting.
3.1) Emacs guarantees that it will run process filters on any
unconsumed output before running the process sentinel, so
status_notify calls read_process_output, which consumes the final
output and calls notmuch-search-process-filter.
3.1.1) notmuch-search-process-filter checks if the search buffer is
still alive and, since it's not, it calls delete-process.
3.1.1.1) delete-process correctly sees that the process is already
dead and doesn't try to send another signal, *but* it still modifies
the status to "killed". To deal with the new status, it calls
status_notify. Dun dun dun. We've seen this function before.
3.1.1.1.1) The *recursive* status_notify invocation sees that the
process has a new status and doesn't have any more output to consume,
so it invokes our sentinel and returns.
3.2) The outer status_notify call (which we're still in) is now done
flushing pending process output, so it *also* invokes our sentinel.
This patch addresses this problem at step 3.1.1, where the filter
calls delete-process, since this is a strange and redundant thing to
do anyway.
2013-06-09 06:45:38 +02:00
|
|
|
(when (buffer-live-p results-buf)
|
2012-07-09 23:42:41 +02:00
|
|
|
(with-current-buffer parse-buf
|
|
|
|
;; Insert new data
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-max))
|
2012-10-27 11:34:10 +02:00
|
|
|
(insert string))
|
2014-03-22 12:51:11 +01:00
|
|
|
(notmuch-sexp-parse-partial-list 'notmuch-search-append-result
|
2021-09-13 03:03:50 +02:00
|
|
|
results-buf))
|
|
|
|
(with-current-buffer results-buf
|
|
|
|
(notmuch--search-hook-wrapper)))))
|
2012-10-27 11:34:10 +02:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Commands (and some helper functions used by them)
|
|
|
|
|
2013-10-23 02:21:57 +02:00
|
|
|
(defun notmuch-search-tag-all (tag-changes)
|
2012-04-14 20:52:52 +02:00
|
|
|
"Add/remove tags from all messages in current search buffer.
|
2009-11-26 22:36:49 +01:00
|
|
|
|
2012-04-14 20:52:52 +02:00
|
|
|
See `notmuch-tag' for information on the format of TAG-CHANGES."
|
2013-10-23 02:21:57 +02:00
|
|
|
(interactive
|
|
|
|
(list (notmuch-read-tag-changes
|
|
|
|
(notmuch-search-get-tags-region (point-min) (point-max)) "Tag all")))
|
2013-10-24 17:19:11 +02:00
|
|
|
(notmuch-search-tag tag-changes (point-min) (point-max) t))
|
2009-11-26 22:36:49 +01:00
|
|
|
|
2022-01-23 20:54:17 +01:00
|
|
|
(defcustom notmuch-search-buffer-name-format "*notmuch-%t-%s*"
|
|
|
|
"Format for the name of search results buffers.
|
|
|
|
|
|
|
|
In this spec, %s will be replaced by a description of the search
|
|
|
|
query and %t by its type (search, tree or unthreaded). The
|
|
|
|
buffer name is formatted using `format-spec': see its docstring
|
|
|
|
for additional parameters for the s and t format specifiers.
|
|
|
|
|
|
|
|
See also `notmuch-saved-search-buffer-name-format'"
|
|
|
|
:type 'string
|
|
|
|
:group 'notmuch-search)
|
|
|
|
|
|
|
|
(defcustom notmuch-saved-search-buffer-name-format "*notmuch-saved-%t-%s*"
|
|
|
|
"Format for the name of search results buffers for saved searches.
|
|
|
|
|
|
|
|
In this spec, %s will be replaced by the saved search name and %t
|
|
|
|
by its type (search, tree or unthreaded). The buffer name is
|
|
|
|
formatted using `format-spec': see its docstring for additional
|
|
|
|
parameters for the s and t format specifiers.
|
|
|
|
|
|
|
|
See also `notmuch-search-buffer-name-format'"
|
|
|
|
:type 'string
|
|
|
|
:group 'notmuch-search)
|
|
|
|
|
|
|
|
(defun notmuch-search-format-buffer-name (query type saved)
|
|
|
|
"Compose a buffer name for the given QUERY, TYPE (search, tree,
|
|
|
|
unthreaded) and whether it's SAVED (t or nil)."
|
|
|
|
(let ((fmt (if saved
|
|
|
|
notmuch-saved-search-buffer-name-format
|
|
|
|
notmuch-search-buffer-name-format)))
|
|
|
|
(format-spec fmt `((?t . ,(or type "search")) (?s . ,query)))))
|
|
|
|
|
|
|
|
(defun notmuch-search-buffer-title (query &optional type)
|
2010-04-19 05:55:50 +02:00
|
|
|
"Returns the title for a buffer with notmuch search results."
|
2010-04-29 12:33:36 +02:00
|
|
|
(let* ((saved-search
|
|
|
|
(let (longest
|
|
|
|
(longest-length 0))
|
2020-04-25 22:18:07 +02:00
|
|
|
(cl-loop for tuple in notmuch-saved-searches
|
|
|
|
if (let ((quoted-query
|
2020-08-08 13:49:36 +02:00
|
|
|
(regexp-quote
|
|
|
|
(notmuch-saved-search-get tuple :query))))
|
2020-04-25 22:18:07 +02:00
|
|
|
(and (string-match (concat "^" quoted-query) query)
|
|
|
|
(> (length (match-string 0 query))
|
|
|
|
longest-length)))
|
|
|
|
do (setq longest tuple))
|
2010-04-29 12:33:36 +02:00
|
|
|
longest))
|
2014-04-06 07:44:46 +02:00
|
|
|
(saved-search-name (notmuch-saved-search-get saved-search :name))
|
2022-01-23 20:54:17 +01:00
|
|
|
(saved-search-type (notmuch-saved-search-get saved-search :search-type))
|
2014-04-06 07:44:46 +02:00
|
|
|
(saved-search-query (notmuch-saved-search-get saved-search :query)))
|
2010-04-27 07:58:46 +02:00
|
|
|
(cond ((and saved-search (equal saved-search-query query))
|
|
|
|
;; Query is the same as saved search (ignoring case)
|
2022-01-23 20:54:17 +01:00
|
|
|
(notmuch-search-format-buffer-name saved-search-name
|
|
|
|
saved-search-type
|
|
|
|
t))
|
2010-04-27 07:58:46 +02:00
|
|
|
(saved-search
|
2022-01-23 20:54:17 +01:00
|
|
|
(let ((query (replace-regexp-in-string
|
|
|
|
(concat "^" (regexp-quote saved-search-query))
|
|
|
|
(concat "[ " saved-search-name " ]")
|
|
|
|
query)))
|
|
|
|
(notmuch-search-format-buffer-name query saved-search-type t)))
|
|
|
|
(t (notmuch-search-format-buffer-name query type nil)))))
|
2010-04-19 05:55:50 +02:00
|
|
|
|
2011-08-09 19:32:49 +02:00
|
|
|
(defun notmuch-read-query (prompt)
|
|
|
|
"Read a notmuch-query from the minibuffer with completion.
|
|
|
|
|
|
|
|
PROMPT is the string to prompt with."
|
2021-01-13 18:37:50 +01:00
|
|
|
(let* ((all-tags
|
|
|
|
(mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
|
2021-08-29 21:23:29 +02:00
|
|
|
(notmuch--process-lines notmuch-command "search" "--output=tags" "*")))
|
2021-01-13 18:37:50 +01:00
|
|
|
(completions
|
|
|
|
(append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
|
|
|
|
"subject:" "attachment:")
|
|
|
|
(mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
|
|
|
|
(mapcar (lambda (tag) (concat "is:" tag)) all-tags)
|
|
|
|
(mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
|
|
|
|
(mailcap-mime-types))))
|
|
|
|
(keymap (copy-keymap minibuffer-local-map))
|
|
|
|
(current-query (cl-case major-mode
|
|
|
|
(notmuch-search-mode (notmuch-search-get-query))
|
|
|
|
(notmuch-show-mode (notmuch-show-get-query))
|
|
|
|
(notmuch-tree-mode (notmuch-tree-get-query))))
|
|
|
|
(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)
|
|
|
|
(let ((history-delete-duplicates t))
|
|
|
|
(read-from-minibuffer prompt nil keymap nil
|
|
|
|
'notmuch-search-history current-query nil))))
|
2014-06-23 23:06:46 +02:00
|
|
|
|
|
|
|
(defun notmuch-search-get-query ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return the current query in this search buffer."
|
2014-06-23 23:06:46 +02:00
|
|
|
notmuch-search-query-string)
|
2011-08-09 19:32:49 +02:00
|
|
|
|
2013-10-06 05:22:47 +02:00
|
|
|
(put 'notmuch-search 'notmuch-doc "Search for messages.")
|
2016-12-08 01:45:51 +01:00
|
|
|
;;;###autoload
|
2021-01-16 18:17:09 +01:00
|
|
|
(defun notmuch-search (&optional query oldest-first target-thread target-line
|
|
|
|
no-display)
|
2013-10-06 05:22:45 +02:00
|
|
|
"Display threads matching QUERY in a notmuch-search buffer.
|
2010-03-09 20:36:08 +01:00
|
|
|
|
2013-10-06 05:22:45 +02:00
|
|
|
If QUERY is nil, it is read interactively from the minibuffer.
|
2012-01-25 02:10:53 +01:00
|
|
|
Other optional parameters are used as follows:
|
2010-03-09 20:36:08 +01:00
|
|
|
|
2013-10-06 05:22:45 +02:00
|
|
|
OLDEST-FIRST: A Boolean controlling the sort order of returned threads
|
|
|
|
TARGET-THREAD: A thread ID (without the thread: prefix) that will be made
|
2010-03-09 20:36:08 +01:00
|
|
|
current if it appears in the search results.
|
2013-10-06 05:22:45 +02:00
|
|
|
TARGET-LINE: The line number to move to if the target thread does not
|
2013-09-03 23:45:17 +02:00
|
|
|
appear in the search results.
|
2016-10-15 09:32:42 +02:00
|
|
|
NO-DISPLAY: Do not try to foreground the search results buffer. If it is
|
|
|
|
already foregrounded i.e. displayed in a window, this has no
|
|
|
|
effect, meaning the buffer will remain visible.
|
2013-09-03 23:45:17 +02:00
|
|
|
|
|
|
|
When called interactively, this will prompt for a query and use
|
|
|
|
the configured default sort order."
|
|
|
|
(interactive
|
|
|
|
(list
|
|
|
|
;; Prompt for a query
|
|
|
|
nil
|
|
|
|
;; Use the default search order (if we're doing a search from a
|
|
|
|
;; search buffer, ignore any buffer-local overrides)
|
2013-09-14 22:17:07 +02:00
|
|
|
(default-value 'notmuch-search-oldest-first)))
|
2013-09-03 23:45:17 +02:00
|
|
|
|
2013-06-02 16:57:01 +02:00
|
|
|
(let* ((query (or query (notmuch-read-query "Notmuch search: ")))
|
|
|
|
(buffer (get-buffer-create (notmuch-search-buffer-title query))))
|
2016-10-15 09:32:42 +02:00
|
|
|
(if no-display
|
|
|
|
(set-buffer buffer)
|
2020-08-11 18:59:13 +02:00
|
|
|
(pop-to-buffer-same-window buffer))
|
2020-11-08 18:49:29 +01:00
|
|
|
(notmuch-search-mode)
|
2011-11-21 02:00:55 +01:00
|
|
|
;; Don't track undo information for this buffer
|
2021-01-10 15:00:37 +01:00
|
|
|
(setq buffer-undo-list t)
|
|
|
|
(setq notmuch-search-query-string query)
|
|
|
|
(setq notmuch-search-oldest-first oldest-first)
|
|
|
|
(setq notmuch-search-target-thread target-thread)
|
|
|
|
(setq notmuch-search-target-line target-line)
|
Make keys of notmuch-tag-formats regexps and use caching
This modifies `notmuch-tag-format-tag' to treat the keys of
`notmuch-tag-formats' as (anchored) regexps, rather than literal
strings. This is clearly more flexible, as it allows for prefix
matching, defining a fallback format, etc. This may cause compatibility
problems if people have customized `notmuch-tag-formats' to match tags
that contain regexp specials, but this seems unlikely.
Regular expression matching has quite a performance hit over string
lookup, so this also introduces a simple cache from exact tags to
formatted strings. The number of unique tags is likely to be quite
small, so this cache should have a high hit rate. In addition to
eliminating the regexp lookup in the common case, this cache stores
fully formatted tags, eliminating the repeated evaluation of potentially
expensive, user-specified formatting code. This makes regexp lookup at
least as fast as assoc for unformatted tags (e.g., inbox) and *faster*
than the current code for formatted tags (e.g., unread):
inbox (usec) unread (usec)
assoc: 0.4 2.8
regexp: 3.2 7.2
regexp+caching: 0.4 0.4
(Though even at 7.2 usec, tag formatting is not our top bottleneck.)
This cache must be explicitly cleared to keep it coherent, so this adds
the appropriate clearing calls.
2014-03-22 12:51:06 +01:00
|
|
|
(notmuch-tag-clear-cache)
|
2021-01-10 15:01:06 +01:00
|
|
|
(when (get-buffer-process buffer)
|
|
|
|
(error "notmuch search process already running for query `%s'" query))
|
|
|
|
(let ((inhibit-read-only t))
|
2009-10-31 08:44:39 +01:00
|
|
|
(erase-buffer)
|
2009-11-03 03:23:06 +01:00
|
|
|
(goto-char (point-min))
|
2009-10-31 08:44:39 +01:00
|
|
|
(save-excursion
|
2013-06-01 02:40:05 +02:00
|
|
|
(let ((proc (notmuch-start-notmuch
|
|
|
|
"notmuch-search" buffer #'notmuch-search-process-sentinel
|
2021-08-22 02:00:11 +02:00
|
|
|
"search" "--format=sexp" "--format-version=5"
|
2010-06-04 02:29:32 +02:00
|
|
|
(if oldest-first
|
|
|
|
"--sort=oldest-first"
|
|
|
|
"--sort=newest-first")
|
2021-01-13 18:37:50 +01:00
|
|
|
query)))
|
|
|
|
;; Use a scratch buffer to accumulate partial output.
|
|
|
|
;; This buffer will be killed by the sentinel, which
|
|
|
|
;; should be called no matter how the process dies.
|
|
|
|
(process-put proc 'parse-buf
|
|
|
|
(generate-new-buffer " *notmuch search parse*"))
|
2011-08-27 14:38:26 +02:00
|
|
|
(set-process-filter proc 'notmuch-search-process-filter)
|
2021-09-13 03:03:50 +02:00
|
|
|
(set-process-query-on-exit-flag proc nil))))))
|
2009-10-31 01:18:19 +01:00
|
|
|
|
2009-11-03 20:47:48 +01:00
|
|
|
(defun notmuch-search-refresh-view ()
|
|
|
|
"Refresh the current view.
|
|
|
|
|
2016-10-15 09:32:43 +02:00
|
|
|
Erases the current buffer and runs a new search with the same
|
2009-11-03 20:54:34 +01:00
|
|
|
query string as the current search. If the current thread is in
|
|
|
|
the new search results, then point will be placed on the same
|
|
|
|
thread. Otherwise, point will be moved to attempt to be in the
|
|
|
|
same relative position within the new buffer."
|
2016-10-15 09:32:40 +02:00
|
|
|
(interactive)
|
2021-01-10 15:01:06 +01:00
|
|
|
(notmuch-search notmuch-search-query-string
|
|
|
|
notmuch-search-oldest-first
|
|
|
|
(notmuch-search-find-thread-id 'bare)
|
|
|
|
(line-number-at-pos)
|
|
|
|
t)
|
|
|
|
(goto-char (point-min)))
|
2009-11-03 20:47:48 +01:00
|
|
|
|
2009-11-13 08:16:19 +01:00
|
|
|
(defun notmuch-search-toggle-order ()
|
|
|
|
"Toggle the current search order.
|
|
|
|
|
2013-06-03 19:56:31 +02:00
|
|
|
This command toggles the sort order for the current search. The
|
|
|
|
default sort order is defined by `notmuch-search-oldest-first'."
|
2009-11-13 08:16:19 +01:00
|
|
|
(interactive)
|
2021-01-10 15:00:37 +01:00
|
|
|
(setq notmuch-search-oldest-first (not notmuch-search-oldest-first))
|
2009-11-13 08:16:19 +01:00
|
|
|
(notmuch-search-refresh-view))
|
|
|
|
|
2015-09-06 23:29:05 +02:00
|
|
|
(defun notmuch-group-disjunctive-query-string (query-string)
|
|
|
|
"Group query if it contains a complex expression.
|
2021-01-10 15:01:02 +01:00
|
|
|
Enclose QUERY-STRING in parentheses if contains \"OR\" operators."
|
|
|
|
(if (string-match-p "\\<[oO][rR]\\>" query-string)
|
2015-09-06 23:29:05 +02:00
|
|
|
(concat "( " query-string " )")
|
|
|
|
query-string))
|
|
|
|
|
2009-11-03 02:56:18 +01:00
|
|
|
(defun notmuch-search-filter (query)
|
2015-06-13 10:08:10 +02:00
|
|
|
"Filter or LIMIT the current search results based on an additional query string.
|
2009-11-03 02:56:18 +01:00
|
|
|
|
2009-11-04 02:01:07 +01:00
|
|
|
Runs a new search matching only messages that match both the
|
|
|
|
current search results AND the additional query string provided."
|
2011-08-09 19:32:49 +02:00
|
|
|
(interactive (list (notmuch-read-query "Filter search: ")))
|
2015-09-06 23:29:05 +02:00
|
|
|
(let ((grouped-query (notmuch-group-disjunctive-query-string query))
|
|
|
|
(grouped-original-query (notmuch-group-disjunctive-query-string
|
|
|
|
notmuch-search-query-string)))
|
|
|
|
(notmuch-search (if (string= grouped-original-query "*")
|
2010-04-16 06:22:57 +02:00
|
|
|
grouped-query
|
2015-09-06 23:29:05 +02:00
|
|
|
(concat grouped-original-query " and " grouped-query))
|
|
|
|
notmuch-search-oldest-first)))
|
2009-11-03 02:56:18 +01:00
|
|
|
|
2009-11-04 02:01:07 +01:00
|
|
|
(defun notmuch-search-filter-by-tag (tag)
|
2021-01-10 15:01:01 +01:00
|
|
|
"Filter the current search results based on a single TAG.
|
2009-11-04 02:01:07 +01:00
|
|
|
|
2021-01-10 15:01:01 +01:00
|
|
|
Run a new search matching only messages that match the current
|
|
|
|
search results and that are also tagged with the given TAG."
|
2009-11-23 01:10:56 +01:00
|
|
|
(interactive
|
2020-08-08 13:49:36 +02:00
|
|
|
(list (notmuch-select-tag-with-completion "Filter by tag: "
|
|
|
|
notmuch-search-query-string)))
|
|
|
|
(notmuch-search (concat notmuch-search-query-string " and tag:" tag)
|
|
|
|
notmuch-search-oldest-first))
|
2009-11-04 02:01:07 +01:00
|
|
|
|
2020-04-13 22:10:50 +02:00
|
|
|
(defun notmuch-search-by-tag (tag)
|
|
|
|
"Display threads matching TAG in a notmuch-search buffer."
|
|
|
|
(interactive
|
|
|
|
(list (notmuch-select-tag-with-completion "Notmuch search tag: ")))
|
|
|
|
(notmuch-search (concat "tag:" tag)))
|
|
|
|
|
2009-11-27 14:30:08 +01:00
|
|
|
;;;###autoload
|
2009-10-30 23:17:27 +01:00
|
|
|
(defun notmuch ()
|
2010-04-26 17:07:04 +02:00
|
|
|
"Run notmuch and display saved searches, known tags, etc."
|
2009-10-30 23:17:27 +01:00
|
|
|
(interactive)
|
2010-04-26 17:07:04 +02:00
|
|
|
(notmuch-hello))
|
2009-10-31 09:04:01 +01:00
|
|
|
|
2011-12-28 09:29:58 +01:00
|
|
|
(defun notmuch-interesting-buffer (b)
|
2021-01-10 15:01:01 +01:00
|
|
|
"Whether the current buffer's major-mode is a notmuch mode."
|
2011-12-28 09:29:58 +01:00
|
|
|
(with-current-buffer b
|
|
|
|
(memq major-mode '(notmuch-show-mode
|
|
|
|
notmuch-search-mode
|
2016-10-22 14:10:04 +02:00
|
|
|
notmuch-tree-mode
|
2011-12-28 09:29:58 +01:00
|
|
|
notmuch-hello-mode
|
2016-10-22 14:10:04 +02:00
|
|
|
notmuch-message-mode))))
|
2011-12-28 09:29:58 +01:00
|
|
|
|
2011-12-20 09:01:46 +01:00
|
|
|
;;;###autoload
|
2011-12-28 09:29:58 +01:00
|
|
|
(defun notmuch-cycle-notmuch-buffers ()
|
|
|
|
"Cycle through any existing notmuch buffers (search, show or hello).
|
2011-12-20 09:01:46 +01:00
|
|
|
|
2021-01-10 15:01:01 +01:00
|
|
|
If the current buffer is the only notmuch buffer, bury it.
|
|
|
|
If no notmuch buffers exist, run `notmuch'."
|
2011-12-20 09:01:46 +01:00
|
|
|
(interactive)
|
2011-12-28 09:29:58 +01:00
|
|
|
(let (start first)
|
|
|
|
;; If the current buffer is a notmuch buffer, remember it and then
|
|
|
|
;; bury it.
|
|
|
|
(when (notmuch-interesting-buffer (current-buffer))
|
|
|
|
(setq start (current-buffer))
|
|
|
|
(bury-buffer))
|
|
|
|
|
|
|
|
;; Find the first notmuch buffer.
|
2020-04-25 22:18:07 +02:00
|
|
|
(setq first (cl-loop for buffer in (buffer-list)
|
|
|
|
if (notmuch-interesting-buffer buffer)
|
|
|
|
return buffer))
|
2011-12-28 09:29:58 +01:00
|
|
|
|
|
|
|
(if first
|
|
|
|
;; If the first one we found is any other than the starting
|
|
|
|
;; buffer, switch to it.
|
|
|
|
(unless (eq first start)
|
2020-08-11 18:59:13 +02:00
|
|
|
(pop-to-buffer-same-window first))
|
2011-12-20 09:01:46 +01:00
|
|
|
(notmuch))))
|
|
|
|
|
2021-01-10 15:01:05 +01:00
|
|
|
;;; Integrations
|
|
|
|
;;;; Hl-line Support
|
|
|
|
|
|
|
|
(defun notmuch-hl-line-mode ()
|
|
|
|
(prog1 (hl-line-mode)
|
|
|
|
(when hl-line-overlay
|
|
|
|
(overlay-put hl-line-overlay 'priority 1))))
|
|
|
|
|
|
|
|
;;;; Imenu Support
|
2017-06-12 15:30:10 +02:00
|
|
|
|
|
|
|
(defun notmuch-search-imenu-prev-index-position-function ()
|
|
|
|
"Move point to previous message in notmuch-search buffer.
|
2021-01-10 15:01:01 +01:00
|
|
|
Used as`imenu-prev-index-position-function' in notmuch buffers."
|
2017-06-12 15:30:10 +02:00
|
|
|
(notmuch-search-previous-thread))
|
|
|
|
|
|
|
|
(defun notmuch-search-imenu-extract-index-name-function ()
|
|
|
|
"Return imenu name for line at point.
|
2021-01-10 15:01:01 +01:00
|
|
|
Used as `imenu-extract-index-name-function' in notmuch buffers.
|
|
|
|
Point should be at the beginning of the line."
|
2021-01-10 15:01:06 +01:00
|
|
|
(format "%s (%s)"
|
|
|
|
(notmuch-search-find-subject)
|
|
|
|
(notmuch-search-find-authors)))
|
2017-06-12 15:30:10 +02:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; _
|
|
|
|
|
2009-10-31 09:04:01 +01:00
|
|
|
(provide 'notmuch)
|
2014-03-29 09:07:59 +01:00
|
|
|
|
|
|
|
;; After provide to avoid loops if notmuch was require'd via notmuch-init-file.
|
2020-08-08 13:49:43 +02:00
|
|
|
(when init-file-user ; don't load init file if the -q option was used.
|
|
|
|
(load notmuch-init-file t t nil t))
|
2016-04-13 09:58:47 +02:00
|
|
|
|
|
|
|
;;; notmuch.el ends here
|