2021-01-10 15:00:47 +01:00
|
|
|
;;; notmuch-tree.el --- displaying notmuch forests -*- lexical-binding: t -*-
|
2012-10-27 13:26:38 +02:00
|
|
|
;;
|
|
|
|
;; Copyright © Carl Worth
|
|
|
|
;; Copyright © David Edmondson
|
|
|
|
;; Copyright © Mark Walters
|
|
|
|
;;
|
|
|
|
;; 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-10-27 13:26:38 +02:00
|
|
|
;;
|
|
|
|
;; Authors: David Edmondson <dme@dme.org>
|
|
|
|
;; Mark Walters <markwalters1009@gmail.com>
|
|
|
|
|
2016-04-13 09:58:47 +02:00
|
|
|
;;; Code:
|
|
|
|
|
2012-10-27 13:26:38 +02:00
|
|
|
(require 'mail-parse)
|
|
|
|
|
|
|
|
(require 'notmuch-lib)
|
|
|
|
(require 'notmuch-show)
|
2013-10-29 23:55:29 +01:00
|
|
|
(require 'notmuch-tag)
|
|
|
|
(require 'notmuch-parser)
|
2020-08-08 13:49:51 +02:00
|
|
|
(require 'notmuch-jump)
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-08-08 13:49:36 +02:00
|
|
|
(declare-function notmuch-search "notmuch"
|
2021-01-16 18:17:09 +01:00
|
|
|
(&optional query oldest-first target-thread target-line
|
|
|
|
no-display))
|
|
|
|
(declare-function notmuch-call-notmuch-process "notmuch-lib" (&rest args))
|
2012-10-27 13:26:38 +02:00
|
|
|
(declare-function notmuch-read-query "notmuch" (prompt))
|
2013-10-29 23:55:29 +01:00
|
|
|
(declare-function notmuch-search-find-thread-id "notmuch" (&optional bare))
|
2012-10-27 13:26:38 +02:00
|
|
|
(declare-function notmuch-search-find-subject "notmuch" ())
|
|
|
|
|
2020-11-08 20:02:45 +01:00
|
|
|
;; For `notmuch-tree-next-thread-from-search'.
|
|
|
|
(declare-function notmuch-search-next-thread "notmuch" ())
|
|
|
|
(declare-function notmuch-search-previous-thread "notmuch" ())
|
|
|
|
(declare-function notmuch-tree-from-search-thread "notmuch" ())
|
|
|
|
|
2012-10-27 13:26:38 +02:00
|
|
|
;; the following variable is defined in notmuch.el
|
|
|
|
(defvar notmuch-search-query-string)
|
|
|
|
|
2020-02-27 18:16:48 +01:00
|
|
|
;; this variable distinguishes the unthreaded display from the normal tree display
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-unthreaded nil
|
2020-05-24 21:17:56 +02:00
|
|
|
"A buffer local copy of argument unthreaded to the function notmuch-tree.")
|
2020-02-27 18:16:48 +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
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defgroup notmuch-tree nil
|
2012-10-27 13:26:38 +02:00
|
|
|
"Showing message and thread structure."
|
|
|
|
:group 'notmuch)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defcustom notmuch-tree-show-out nil
|
2012-10-27 13:26:38 +02:00
|
|
|
"View selected messages in new window rather than split-pane."
|
|
|
|
:type 'boolean
|
2013-10-27 00:02:05 +02:00
|
|
|
:group 'notmuch-tree)
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-02-27 18:16:50 +01:00
|
|
|
(defcustom notmuch-unthreaded-show-out t
|
|
|
|
"View selected messages in new window rather than split-pane."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'notmuch-tree)
|
|
|
|
|
|
|
|
(defun notmuch-tree-show-out ()
|
|
|
|
(if notmuch-tree-unthreaded
|
|
|
|
notmuch-unthreaded-show-out
|
|
|
|
notmuch-tree-show-out))
|
|
|
|
|
2021-08-31 03:21:06 +02:00
|
|
|
(defcustom notmuch-tree-thread-symbols
|
|
|
|
'((prefix . " ")
|
|
|
|
(top . "─")
|
|
|
|
(top-tee . "┬")
|
|
|
|
(vertical . "│")
|
|
|
|
(vertical-tee . "├")
|
|
|
|
(bottom . "╰")
|
|
|
|
(arrow . "►"))
|
|
|
|
"Strings used to draw trees in notmuch tree results.
|
|
|
|
Symbol keys denote where the corresponding string value is used:
|
|
|
|
`prefix' is used at the top of the tree, followed by `top' if it
|
|
|
|
has no children or `top-tee' if it does; `vertical' is a bar
|
|
|
|
connecting with a response down the list skipping the current
|
|
|
|
one, while `vertical-tee' marks the current message as a reply to
|
|
|
|
the previous one; `bottom' is used at the bottom of threads.
|
|
|
|
Finally, the `arrrow' string in the list is used as a pointer to
|
|
|
|
every message.
|
|
|
|
|
|
|
|
Common customizations include setting `prefix' to \"-\", to see
|
|
|
|
equal-length prefixes, and `arrow' to an empty string or to a
|
|
|
|
different kind of arrow point."
|
|
|
|
:type '(alist :key-type symbol :value-type string)
|
|
|
|
:group 'notmuch-tree)
|
|
|
|
|
2022-07-16 23:22:25 +02:00
|
|
|
(defconst notmuch-tree--field-names
|
|
|
|
'(choice :tag "Field"
|
|
|
|
(const :tag "Date" "date")
|
|
|
|
(const :tag "Authors" "authors")
|
|
|
|
(const :tag "Subject" "subject")
|
|
|
|
(const :tag "Tree" "tree")
|
|
|
|
(const :tag "Tags" "tags")
|
|
|
|
(function)))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defcustom notmuch-tree-result-format
|
2012-10-27 13:26:38 +02:00
|
|
|
`(("date" . "%12s ")
|
|
|
|
("authors" . "%-20s")
|
2021-07-19 13:31:07 +02:00
|
|
|
((("tree" . "%s")
|
|
|
|
("subject" . "%s"))
|
|
|
|
. " %-54s ")
|
2012-10-27 13:26:38 +02:00
|
|
|
("tags" . "(%s)"))
|
2021-07-19 13:31:07 +02:00
|
|
|
"Result formatting for tree view.
|
|
|
|
|
2022-07-16 23:22:25 +02:00
|
|
|
List of pairs of (field . format-string). Supported field
|
|
|
|
strings are: \"date\", \"authors\", \"subject\", \"tree\",
|
|
|
|
\"tags\". It is also supported to pass a function in place of a
|
|
|
|
field-name. In this case the function is passed the thread
|
|
|
|
object (plist) and format string.
|
2021-07-19 13:31:07 +02:00
|
|
|
|
|
|
|
Tree means the thread tree box graphics. The field may
|
|
|
|
also be a list in which case the formatting rules are
|
|
|
|
applied recursively and then the output of all the fields
|
|
|
|
in the list is inserted according to format-string.
|
|
|
|
|
|
|
|
Note that the author string should not contain whitespace
|
2022-07-16 23:22:25 +02:00
|
|
|
\(put it in the neighbouring fields instead)."
|
|
|
|
|
|
|
|
:type `(alist :key-type (choice ,notmuch-tree--field-names
|
|
|
|
(alist :key-type ,notmuch-tree--field-names
|
|
|
|
:value-type (string :tag "Format")))
|
|
|
|
:value-type (string :tag "Format"))
|
2013-10-27 00:02:05 +02:00
|
|
|
:group 'notmuch-tree)
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-02-27 18:16:49 +01:00
|
|
|
(defcustom notmuch-unthreaded-result-format
|
|
|
|
`(("date" . "%12s ")
|
|
|
|
("authors" . "%-20s")
|
|
|
|
((("subject" . "%s")) ." %-54s ")
|
|
|
|
("tags" . "(%s)"))
|
2021-07-19 13:31:07 +02:00
|
|
|
"Result formatting for unthreaded tree view.
|
|
|
|
|
|
|
|
Supported fields are: date, authors, subject, tree, tags.
|
|
|
|
|
|
|
|
Tree means the thread tree box graphics. The field may
|
|
|
|
also be a list in which case the formatting rules are
|
|
|
|
applied recursively and then the output of all the fields
|
|
|
|
in the list is inserted according to format-string.
|
|
|
|
|
|
|
|
Note that the author string should not contain whitespace
|
|
|
|
\(put it in the neighbouring fields instead). For example:
|
|
|
|
(setq notmuch-unthreaded-result-format
|
|
|
|
'((\"authors\" . \"%-40s\")
|
|
|
|
(\"subject\" . \"%s\")))"
|
|
|
|
:type '(alist :key-type (choice string
|
|
|
|
(alist :key-type string
|
|
|
|
:value-type string))
|
|
|
|
:value-type string)
|
2020-02-27 18:16:49 +01:00
|
|
|
:group 'notmuch-tree)
|
|
|
|
|
|
|
|
(defun notmuch-tree-result-format ()
|
|
|
|
(if notmuch-tree-unthreaded
|
|
|
|
notmuch-unthreaded-result-format
|
|
|
|
notmuch-tree-result-format))
|
|
|
|
|
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
|
|
|
|
;;;; Faces for messages that match the query
|
|
|
|
|
2014-01-11 22:41:42 +01:00
|
|
|
(defface notmuch-tree-match-face
|
2012-10-27 13:26:38 +02:00
|
|
|
'((t :inherit default))
|
2014-01-11 22:41:42 +01:00
|
|
|
"Default face used in tree mode face for matching messages"
|
|
|
|
:group 'notmuch-tree
|
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
|
|
|
(defface notmuch-tree-match-date-face
|
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for the date in messages matching the query."
|
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-match-author-face
|
2012-10-27 13:26:38 +02:00
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "OliveDrab1"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
|
|
|
(:foreground "dark blue"))
|
|
|
|
(t
|
|
|
|
(:bold t)))
|
2021-12-05 21:48:36 +01:00
|
|
|
"Face used in tree mode for the author in messages matching the query."
|
2013-10-27 00:02:05 +02:00
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-match-subject-face
|
2014-01-11 22:41:42 +01:00
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for the subject in messages matching the query."
|
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-match-tree-face
|
2014-01-11 22:41:42 +01:00
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for the thread tree block graphics in messages matching the query."
|
|
|
|
:group 'notmuch-tree
|
2013-09-02 05:28:08 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-match-tag-face
|
2012-10-27 13:26:38 +02:00
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "OliveDrab1"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
|
|
|
(:foreground "navy blue" :bold t))
|
|
|
|
(t
|
|
|
|
(:bold t)))
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for tags in messages matching the query."
|
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
: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
|
|
|
;;;; Faces for messages that do not match the query
|
|
|
|
|
2014-01-11 22:41:42 +01:00
|
|
|
(defface notmuch-tree-no-match-face
|
2012-10-27 13:26:38 +02:00
|
|
|
'((t (:foreground "gray")))
|
2020-05-24 21:17:56 +02:00
|
|
|
"Default face used in tree mode face for non-matching messages."
|
2014-01-11 22:41:42 +01:00
|
|
|
:group 'notmuch-tree
|
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
|
|
|
(defface notmuch-tree-no-match-date-face
|
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for non-matching dates."
|
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-no-match-subject-face
|
2014-01-11 22:41:42 +01:00
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for non-matching subjects."
|
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-no-match-tree-face
|
2014-01-11 22:41:42 +01:00
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode for the thread tree block graphics in messages matching the query."
|
|
|
|
:group 'notmuch-tree
|
2013-09-02 05:28:08 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-no-match-author-face
|
2014-01-11 22:41:42 +01:00
|
|
|
nil
|
2021-12-05 21:48:36 +01:00
|
|
|
"Face used in tree mode for non-matching authors."
|
2013-10-27 00:02:05 +02:00
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
:group 'notmuch-faces)
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defface notmuch-tree-no-match-tag-face
|
2014-01-11 22:41:42 +01:00
|
|
|
nil
|
2013-10-27 00:02:05 +02:00
|
|
|
"Face used in tree mode face for non-matching tags."
|
|
|
|
:group 'notmuch-tree
|
2012-10-27 13:26:38 +02:00
|
|
|
: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
|
|
|
;;; Variables
|
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-previous-subject
|
2020-05-24 21:17:56 +02:00
|
|
|
"The subject of the most recent result shown during the async display.")
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-basic-query nil
|
2020-05-24 21:17:56 +02:00
|
|
|
"A buffer local copy of argument query to the function notmuch-tree.")
|
2013-07-01 09:54:00 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-query-context nil
|
2020-05-24 21:17:56 +02:00
|
|
|
"A buffer local copy of argument query-context to the function notmuch-tree.")
|
2013-07-01 09:54:00 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-target-msg nil
|
2020-05-24 21:17:56 +02:00
|
|
|
"A buffer local copy of argument target to the function notmuch-tree.")
|
2013-07-01 09:54:00 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-open-target nil
|
2020-05-24 21:17:56 +02:00
|
|
|
"A buffer local copy of argument open-target to the function notmuch-tree.")
|
2013-07-01 09:54:00 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-parent-buffer nil)
|
2020-08-11 19:36:51 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-message-window nil
|
2013-07-01 09:54:00 +02:00
|
|
|
"The window of the message pane.
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
It is set in both the tree buffer and the child show buffer. It
|
|
|
|
is used to try and close the message pane when quitting tree view
|
|
|
|
or the child show buffer.")
|
|
|
|
(put 'notmuch-tree-message-window 'permanent-local t)
|
2013-07-01 09:54:00 +02:00
|
|
|
|
2020-11-16 22:28:38 +01:00
|
|
|
(defvar-local notmuch-tree-message-buffer nil
|
2013-07-01 09:54:00 +02:00
|
|
|
"The buffer name of the show buffer in the message pane.
|
|
|
|
|
|
|
|
This is used to try and make sure we don't close the message pane
|
|
|
|
if the user has loaded a different buffer in that window.")
|
2013-10-27 00:02:05 +02:00
|
|
|
(put 'notmuch-tree-message-buffer 'permanent-local t)
|
2013-07-01 09:54:00 +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
|
|
|
;;; Tree wrapper commands
|
|
|
|
|
2020-11-16 22:28:42 +01:00
|
|
|
(defmacro notmuch-tree--define-do-in-message-window (name cmd)
|
|
|
|
"Define NAME as a command that calls CMD interactively in the message window.
|
|
|
|
If the message pane is closed then this command does nothing.
|
|
|
|
Avoid using this macro in new code; it will be removed."
|
|
|
|
`(defun ,name ()
|
|
|
|
,(concat "(In message window) " (documentation cmd t))
|
2013-08-22 19:10:20 +02:00
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(with-selected-window notmuch-tree-message-window
|
2020-11-16 22:28:42 +01:00
|
|
|
(call-interactively #',cmd)))))
|
|
|
|
|
|
|
|
(notmuch-tree--define-do-in-message-window
|
|
|
|
notmuch-tree-previous-message-button
|
|
|
|
notmuch-show-previous-button)
|
|
|
|
(notmuch-tree--define-do-in-message-window
|
|
|
|
notmuch-tree-next-message-button
|
|
|
|
notmuch-show-next-button)
|
|
|
|
(notmuch-tree--define-do-in-message-window
|
|
|
|
notmuch-tree-toggle-message-process-crypto
|
|
|
|
notmuch-show-toggle-process-crypto)
|
|
|
|
|
|
|
|
(defun notmuch-tree--message-process-crypto ()
|
|
|
|
"Return value of `notmuch-show-process-crypto' in the message window.
|
|
|
|
If that window isn't alive, then return the current value.
|
|
|
|
Avoid using this function in new code; it will be removed."
|
2016-09-21 17:49:19 +02:00
|
|
|
(if (window-live-p notmuch-tree-message-window)
|
|
|
|
(with-selected-window notmuch-tree-message-window
|
2020-11-16 22:28:42 +01:00
|
|
|
notmuch-show-process-crypto)
|
|
|
|
notmuch-show-process-crypto))
|
|
|
|
|
|
|
|
(defmacro notmuch-tree--define-close-message-window-and (name cmd)
|
|
|
|
"Define NAME as a variant of CMD.
|
|
|
|
|
|
|
|
NAME determines the value of `notmuch-show-process-crypto' in the
|
|
|
|
message window, closes the window, and then call CMD interactively
|
|
|
|
with that value let-bound. If the message window does not exist,
|
|
|
|
then NAME behaves like CMD."
|
|
|
|
`(defun ,name ()
|
|
|
|
,(concat "(Close message pane and) " (documentation cmd t))
|
2013-08-22 19:10:23 +02:00
|
|
|
(interactive)
|
2016-09-21 17:49:19 +02:00
|
|
|
(let ((notmuch-show-process-crypto
|
2020-11-16 22:28:42 +01:00
|
|
|
(notmuch-tree--message-process-crypto)))
|
2016-09-21 17:49:19 +02:00
|
|
|
(notmuch-tree-close-message-window)
|
2020-11-16 22:28:42 +01:00
|
|
|
(call-interactively #',cmd))))
|
|
|
|
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-help
|
|
|
|
notmuch-help)
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-new-mail
|
|
|
|
notmuch-mua-new-mail)
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-jump-search
|
|
|
|
notmuch-jump-search)
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-forward-message
|
|
|
|
notmuch-show-forward-message)
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-reply-sender
|
|
|
|
notmuch-show-reply-sender)
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-reply
|
|
|
|
notmuch-show-reply)
|
|
|
|
(notmuch-tree--define-close-message-window-and
|
|
|
|
notmuch-tree-view-raw-message
|
|
|
|
notmuch-show-view-raw-message)
|
2013-08-22 19:10:23 +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
|
|
|
;;; Keymap
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defvar notmuch-tree-mode-map
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((map (make-sparse-keymap)))
|
2013-09-15 10:17:48 +02:00
|
|
|
(set-keymap-parent map notmuch-common-keymap)
|
2020-11-16 22:28:42 +01:00
|
|
|
;; These bindings shadow common bindings with variants
|
|
|
|
;; that additionally close the message window.
|
2014-10-29 15:18:49 +01:00
|
|
|
(define-key map [remap notmuch-bury-or-kill-this-buffer] 'notmuch-tree-quit)
|
2021-08-22 02:50:49 +02:00
|
|
|
(define-key map [remap notmuch-search] 'notmuch-tree-to-search)
|
|
|
|
(define-key map [remap notmuch-help] 'notmuch-tree-help)
|
|
|
|
(define-key map [remap notmuch-mua-new-mail] 'notmuch-tree-new-mail)
|
|
|
|
(define-key map [remap notmuch-jump-search] 'notmuch-tree-jump-search)
|
2013-09-15 10:17:48 +02:00
|
|
|
|
2021-07-02 22:44:23 +02:00
|
|
|
(define-key map "o" 'notmuch-tree-toggle-order)
|
2015-10-14 10:38:23 +02:00
|
|
|
(define-key map "S" 'notmuch-search-from-tree-current-query)
|
2020-02-27 18:16:51 +01:00
|
|
|
(define-key map "U" 'notmuch-unthreaded-from-tree-current-query)
|
|
|
|
(define-key map "Z" 'notmuch-tree-from-unthreaded-current-query)
|
2015-10-14 10:38:23 +02:00
|
|
|
|
2013-08-22 19:10:17 +02:00
|
|
|
;; these use notmuch-show functions directly
|
|
|
|
(define-key map "|" 'notmuch-show-pipe-message)
|
2013-08-22 19:10:18 +02:00
|
|
|
(define-key map "w" 'notmuch-show-save-attachments)
|
|
|
|
(define-key map "v" 'notmuch-show-view-all-mime-parts)
|
2013-08-22 19:10:19 +02:00
|
|
|
(define-key map "c" 'notmuch-show-stash-map)
|
2016-09-25 09:18:10 +02:00
|
|
|
(define-key map "b" 'notmuch-show-resend-message)
|
2013-08-22 19:10:22 +02:00
|
|
|
|
|
|
|
;; these apply to the message pane
|
2020-11-16 22:28:42 +01:00
|
|
|
(define-key map (kbd "M-TAB") 'notmuch-tree-previous-message-button)
|
|
|
|
(define-key map (kbd "<backtab>") 'notmuch-tree-previous-message-button)
|
|
|
|
(define-key map (kbd "TAB") 'notmuch-tree-next-message-button)
|
|
|
|
(define-key map "$" 'notmuch-tree-toggle-message-process-crypto)
|
2013-08-22 19:10:22 +02:00
|
|
|
|
2013-08-22 19:10:24 +02:00
|
|
|
;; bindings from show (or elsewhere) but we close the message pane first.
|
2020-11-16 22:28:42 +01:00
|
|
|
(define-key map "f" 'notmuch-tree-forward-message)
|
|
|
|
(define-key map "r" 'notmuch-tree-reply-sender)
|
|
|
|
(define-key map "R" 'notmuch-tree-reply)
|
|
|
|
(define-key map "V" 'notmuch-tree-view-raw-message)
|
2021-08-22 02:50:48 +02:00
|
|
|
(define-key map "l" 'notmuch-tree-filter)
|
2021-08-22 02:50:49 +02:00
|
|
|
(define-key map "t" 'notmuch-tree-filter-by-tag)
|
2013-10-27 00:02:05 +02:00
|
|
|
|
|
|
|
;; The main tree view bindings
|
|
|
|
(define-key map (kbd "RET") 'notmuch-tree-show-message)
|
|
|
|
(define-key map [mouse-1] 'notmuch-tree-show-message)
|
2020-04-04 22:41:42 +02:00
|
|
|
(define-key map "x" 'notmuch-tree-archive-message-then-next-or-exit)
|
|
|
|
(define-key map "X" 'notmuch-tree-archive-thread-then-exit)
|
2020-08-11 19:36:53 +02:00
|
|
|
(define-key map "A" 'notmuch-tree-archive-thread-then-next)
|
2013-10-27 00:02:05 +02:00
|
|
|
(define-key map "a" 'notmuch-tree-archive-message-then-next)
|
|
|
|
(define-key map "z" 'notmuch-tree-to-tree)
|
|
|
|
(define-key map "n" 'notmuch-tree-next-matching-message)
|
|
|
|
(define-key map "p" 'notmuch-tree-prev-matching-message)
|
|
|
|
(define-key map "N" 'notmuch-tree-next-message)
|
|
|
|
(define-key map "P" 'notmuch-tree-prev-message)
|
|
|
|
(define-key map (kbd "M-p") 'notmuch-tree-prev-thread)
|
|
|
|
(define-key map (kbd "M-n") 'notmuch-tree-next-thread)
|
2016-09-20 21:57:16 +02:00
|
|
|
(define-key map "k" 'notmuch-tag-jump)
|
2013-10-27 00:02:05 +02:00
|
|
|
(define-key map "-" 'notmuch-tree-remove-tag)
|
|
|
|
(define-key map "+" 'notmuch-tree-add-tag)
|
|
|
|
(define-key map "*" 'notmuch-tree-tag-thread)
|
|
|
|
(define-key map " " 'notmuch-tree-scroll-or-next)
|
2016-09-25 09:18:10 +02:00
|
|
|
(define-key map (kbd "DEL") 'notmuch-tree-scroll-message-window-back)
|
2016-11-13 15:08:50 +01:00
|
|
|
(define-key map "e" 'notmuch-tree-resume-message)
|
2020-11-08 20:02:47 +01:00
|
|
|
map)
|
|
|
|
"Keymap for \"notmuch tree\" buffers.")
|
2012-10-27 13:26:38 +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
|
|
|
;;; Message properties
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-get-message-properties ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Return the properties of the current message as a plist.
|
|
|
|
|
|
|
|
Some useful entries are:
|
|
|
|
:headers - Property list containing the headers :Date, :Subject, :From, etc.
|
2020-05-24 21:17:56 +02:00
|
|
|
:tags - Tags for this message."
|
2012-10-27 13:26:38 +02:00
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line)
|
|
|
|
(get-text-property (point) :notmuch-message-properties)))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-set-message-properties (props)
|
2012-10-27 13:26:38 +02:00
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line)
|
2020-08-08 13:49:36 +02:00
|
|
|
(put-text-property (point)
|
|
|
|
(+ (point) 1)
|
|
|
|
:notmuch-message-properties props)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-set-prop (prop val &optional props)
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
(props (or props
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-get-message-properties))))
|
2012-10-27 13:26:38 +02:00
|
|
|
(plist-put props prop val)
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-set-message-properties props)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-get-prop (prop &optional props)
|
2021-01-10 15:01:06 +01:00
|
|
|
(plist-get (or props (notmuch-tree-get-message-properties))
|
|
|
|
prop))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-set-tags (tags)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Set the tags of the current message."
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-set-prop :tags tags))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-get-tags ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Return the tags of the current message."
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-get-prop :tags))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-12-19 20:16:51 +01:00
|
|
|
(defun notmuch-tree-get-message-id (&optional bare)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Return the message id of the current message."
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((id (notmuch-tree-get-prop :id)))
|
2012-11-10 18:02:18 +01:00
|
|
|
(if id
|
2013-12-19 20:16:51 +01:00
|
|
|
(if bare
|
|
|
|
id
|
|
|
|
(notmuch-id-to-query id))
|
2012-11-10 18:02:18 +01:00
|
|
|
nil)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-get-match ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Return whether the current message is a match."
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-get-prop :match))
|
2012-10-27 13:26:38 +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
|
|
|
;;; Update display
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-refresh-result ()
|
2013-07-01 22:05:41 +02:00
|
|
|
"Redisplay the current message line.
|
|
|
|
|
|
|
|
This redisplays the current line based on the messages
|
|
|
|
properties (as they are now). This is used when tags are
|
|
|
|
updated."
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((init-point (point))
|
|
|
|
(end (line-end-position))
|
2013-10-27 00:02:05 +02:00
|
|
|
(msg (notmuch-tree-get-message-properties))
|
2012-10-27 13:26:38 +02:00
|
|
|
(inhibit-read-only t))
|
|
|
|
(beginning-of-line)
|
2013-06-30 10:55:12 +02:00
|
|
|
;; This is a little tricky: we override
|
2013-10-27 00:02:05 +02:00
|
|
|
;; notmuch-tree-previous-subject to get the decision between
|
|
|
|
;; ... and a subject right and it stops notmuch-tree-insert-msg
|
2013-06-30 10:55:12 +02:00
|
|
|
;; from overwriting the buffer local copy of
|
2013-10-27 00:02:05 +02:00
|
|
|
;; notmuch-tree-previous-subject if this is called while the
|
2013-06-30 10:55:12 +02:00
|
|
|
;; buffer is displaying.
|
2020-08-08 13:49:36 +02:00
|
|
|
(let ((notmuch-tree-previous-subject
|
|
|
|
(notmuch-tree-get-prop :previous-subject)))
|
2013-06-30 10:55:12 +02:00
|
|
|
(delete-region (point) (1+ (line-end-position)))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-insert-msg msg))
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((new-end (line-end-position)))
|
|
|
|
(goto-char (if (= init-point end)
|
|
|
|
new-end
|
|
|
|
(min init-point (- new-end 1)))))))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-tag-update-display (&optional tag-changes)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Update display for TAG-CHANGES to current message.
|
|
|
|
|
2016-10-15 20:25:19 +02:00
|
|
|
Updates the message in the message pane if appropriate, but does
|
|
|
|
NOT change the database."
|
2013-10-27 00:02:05 +02:00
|
|
|
(let* ((current-tags (notmuch-tree-get-tags))
|
2016-10-15 20:25:19 +02:00
|
|
|
(new-tags (notmuch-update-tags current-tags tag-changes))
|
|
|
|
(tree-msg-id (notmuch-tree-get-message-id)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(unless (equal current-tags new-tags)
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-set-tags new-tags)
|
2016-10-15 20:25:19 +02:00
|
|
|
(notmuch-tree-refresh-result)
|
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(with-selected-window notmuch-tree-message-window
|
|
|
|
(when (string= tree-msg-id (notmuch-show-get-message-id))
|
|
|
|
(notmuch-show-update-tags new-tags)))))))
|
2012-10-27 13:26:38 +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-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-tag (tag-changes)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Change tags for the current message."
|
2013-10-23 02:22:00 +02:00
|
|
|
(interactive
|
2013-10-27 00:02:05 +02:00
|
|
|
(list (notmuch-read-tag-changes (notmuch-tree-get-tags) "Tag message")))
|
|
|
|
(notmuch-tag (notmuch-tree-get-message-id) tag-changes)
|
|
|
|
(notmuch-tree-tag-update-display tag-changes))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-add-tag (tag-changes)
|
|
|
|
"Same as `notmuch-tree-tag' but sets initial input to '+'."
|
2013-10-23 02:22:00 +02:00
|
|
|
(interactive
|
2013-10-27 00:02:05 +02:00
|
|
|
(list (notmuch-read-tag-changes (notmuch-tree-get-tags) "Tag message" "+")))
|
|
|
|
(notmuch-tree-tag tag-changes))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-remove-tag (tag-changes)
|
|
|
|
"Same as `notmuch-tree-tag' but sets initial input to '-'."
|
2013-10-23 02:22:00 +02:00
|
|
|
(interactive
|
2013-10-27 00:02:05 +02:00
|
|
|
(list (notmuch-read-tag-changes (notmuch-tree-get-tags) "Tag message" "-")))
|
|
|
|
(notmuch-tree-tag tag-changes))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2016-11-13 15:08:50 +01:00
|
|
|
(defun notmuch-tree-resume-message ()
|
|
|
|
"Resume EDITING the current draft message."
|
|
|
|
(interactive)
|
|
|
|
(notmuch-tree-close-message-window)
|
|
|
|
(let ((id (notmuch-tree-get-message-id)))
|
|
|
|
(if id
|
|
|
|
(notmuch-draft-resume id)
|
|
|
|
(message "No message to resume!"))))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
;; The next two functions close the message window before calling
|
|
|
|
;; notmuch-search or notmuch-tree but they do so after the user has
|
|
|
|
;; entered the query (in case the user was basing the query on
|
|
|
|
;; something in the message window).
|
2012-12-08 13:44:34 +01:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-to-search ()
|
2012-12-08 13:44:34 +01:00
|
|
|
"Run \"notmuch search\" with the given `query' and display results."
|
|
|
|
(interactive)
|
|
|
|
(let ((query (notmuch-read-query "Notmuch search: ")))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-close-message-window)
|
2012-12-08 13:44:34 +01:00
|
|
|
(notmuch-search query)))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-to-tree ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Run a query and display results in tree view."
|
2012-12-08 13:44:34 +01:00
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((query (notmuch-read-query "Notmuch tree view search: ")))
|
|
|
|
(notmuch-tree-close-message-window)
|
|
|
|
(notmuch-tree query)))
|
2012-12-08 13:44:34 +01:00
|
|
|
|
2020-08-11 19:36:53 +02:00
|
|
|
(defun notmuch-tree-archive-thread-then-next ()
|
|
|
|
"Archive all messages in the current buffer, then show next thread from search."
|
|
|
|
(interactive)
|
|
|
|
(notmuch-tree-archive-thread)
|
|
|
|
(notmuch-tree-next-thread))
|
|
|
|
|
2020-02-27 18:16:51 +01:00
|
|
|
(defun notmuch-unthreaded-from-tree-current-query ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Switch from tree view to unthreaded view."
|
2020-02-27 18:16:51 +01:00
|
|
|
(interactive)
|
|
|
|
(unless notmuch-tree-unthreaded
|
|
|
|
(notmuch-tree-refresh-view 'unthreaded)))
|
|
|
|
|
|
|
|
(defun notmuch-tree-from-unthreaded-current-query ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Switch from unthreaded view to tree view."
|
2020-02-27 18:16:51 +01:00
|
|
|
(interactive)
|
|
|
|
(when notmuch-tree-unthreaded
|
|
|
|
(notmuch-tree-refresh-view 'tree)))
|
|
|
|
|
2015-10-14 10:38:23 +02:00
|
|
|
(defun notmuch-search-from-tree-current-query ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Call notmuch search with the current query."
|
2015-10-14 10:38:23 +02:00
|
|
|
(interactive)
|
|
|
|
(notmuch-tree-close-message-window)
|
|
|
|
(notmuch-search (notmuch-tree-get-query)))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-message-window-kill-hook ()
|
2013-07-01 22:05:42 +02:00
|
|
|
"Close the message pane when exiting the show buffer."
|
2012-12-25 12:47:17 +01:00
|
|
|
(let ((buffer (current-buffer)))
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (and (window-live-p notmuch-tree-message-window)
|
|
|
|
(eq (window-buffer notmuch-tree-message-window) buffer))
|
2020-11-16 22:28:24 +01:00
|
|
|
;; We could check whether this is the only window in its frame,
|
|
|
|
;; but simply ignoring the error that is thrown otherwise is
|
|
|
|
;; what we had to do for Emacs 24 and we stick to that because
|
|
|
|
;; it is still the simplest approach.
|
2012-12-25 12:47:17 +01:00
|
|
|
(ignore-errors
|
2013-10-27 00:02:05 +02:00
|
|
|
(delete-window notmuch-tree-message-window)))))
|
2012-12-25 12:47:17 +01:00
|
|
|
|
2015-06-09 11:51:07 +02:00
|
|
|
(defun notmuch-tree-command-hook ()
|
|
|
|
(when (eq major-mode 'notmuch-tree-mode)
|
|
|
|
;; We just run the notmuch-show-command-hook on the message pane.
|
|
|
|
(when (buffer-live-p notmuch-tree-message-buffer)
|
|
|
|
(with-current-buffer notmuch-tree-message-buffer
|
|
|
|
(notmuch-show-command-hook)))))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-show-message-in ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Show the current message (in split-pane)."
|
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((id (notmuch-tree-get-message-id))
|
2012-10-27 13:26:38 +02:00
|
|
|
(inhibit-read-only t)
|
|
|
|
buffer)
|
|
|
|
(when id
|
|
|
|
;; We close and reopen the window to kill off un-needed buffers
|
|
|
|
;; this might cause flickering but seems ok.
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-close-message-window)
|
|
|
|
(setq notmuch-tree-message-window
|
2012-10-27 13:26:38 +02:00
|
|
|
(split-window-vertically (/ (window-height) 4)))
|
2013-10-27 00:02:05 +02:00
|
|
|
(with-selected-window notmuch-tree-message-window
|
2020-08-11 18:59:13 +02:00
|
|
|
(let (;; Since we are only displaying one message do not indent.
|
|
|
|
(notmuch-show-indent-messages-width 0)
|
2021-06-26 14:04:28 +02:00
|
|
|
(notmuch-show-single-message t)
|
2020-08-11 18:59:13 +02:00
|
|
|
;; Ensure that `pop-to-buffer-same-window' uses the
|
|
|
|
;; window we want it to use.
|
|
|
|
(display-buffer-overriding-action
|
|
|
|
'((display-buffer-same-window)
|
|
|
|
(inhibit-same-window . nil))))
|
2013-10-13 09:49:00 +02:00
|
|
|
(setq buffer (notmuch-show id))))
|
2013-10-27 00:02:05 +02:00
|
|
|
;; We need the `let' as notmuch-tree-message-window is buffer local.
|
|
|
|
(let ((window notmuch-tree-message-window))
|
2012-12-25 12:47:17 +01:00
|
|
|
(with-current-buffer buffer
|
2013-10-27 00:02:05 +02:00
|
|
|
(setq notmuch-tree-message-window window)
|
|
|
|
(add-hook 'kill-buffer-hook 'notmuch-tree-message-window-kill-hook)))
|
2013-06-01 23:49:12 +02:00
|
|
|
(when notmuch-show-mark-read-tags
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-tag-update-display notmuch-show-mark-read-tags))
|
|
|
|
(setq notmuch-tree-message-buffer buffer))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-show-message-out ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Show the current message (in whole window)."
|
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((id (notmuch-tree-get-message-id))
|
2021-01-10 15:00:48 +01:00
|
|
|
(inhibit-read-only t))
|
2012-10-27 13:26:38 +02:00
|
|
|
(when id
|
|
|
|
;; We close the window to kill off un-needed buffers.
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-close-message-window)
|
2021-06-26 14:04:28 +02:00
|
|
|
;; n-s-s-m is buffer local, so use inner let.
|
|
|
|
(let ((notmuch-show-single-message t))
|
|
|
|
(notmuch-show id)))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-show-message (arg)
|
2013-09-23 21:52:58 +02:00
|
|
|
"Show the current message.
|
|
|
|
|
|
|
|
Shows in split pane or whole window according to value of
|
2013-10-27 00:02:05 +02:00
|
|
|
`notmuch-tree-show-out'. A prefix argument reverses the choice."
|
2013-09-23 21:52:58 +02:00
|
|
|
(interactive "P")
|
2020-02-27 18:16:50 +01:00
|
|
|
(if (or (and (notmuch-tree-show-out) (not arg))
|
|
|
|
(and (not (notmuch-tree-show-out)) arg))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-show-message-out)
|
|
|
|
(notmuch-tree-show-message-in)))
|
2013-09-23 21:52:58 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-scroll-message-window ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Scroll the message window (if it exists)."
|
2012-10-27 13:26:38 +02:00
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(with-selected-window notmuch-tree-message-window
|
2012-10-27 13:26:38 +02:00
|
|
|
(if (pos-visible-in-window-p (point-max))
|
|
|
|
t
|
|
|
|
(scroll-up)))))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-scroll-message-window-back ()
|
2020-08-08 13:49:50 +02:00
|
|
|
"Scroll the message window back (if it exists)."
|
2012-10-27 13:26:38 +02:00
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(with-selected-window notmuch-tree-message-window
|
2012-10-27 13:26:38 +02:00
|
|
|
(if (pos-visible-in-window-p (point-min))
|
|
|
|
t
|
|
|
|
(scroll-down)))))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-scroll-or-next ()
|
2020-08-08 13:49:50 +02:00
|
|
|
"Scroll the message window.
|
|
|
|
If it at end go to next message."
|
2012-10-27 13:26:38 +02:00
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (notmuch-tree-scroll-message-window)
|
|
|
|
(notmuch-tree-next-matching-message)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-04-04 22:41:34 +02:00
|
|
|
(defun notmuch-tree-quit (&optional kill-both)
|
2013-10-27 00:02:05 +02:00
|
|
|
"Close the split view or exit tree."
|
2020-04-04 22:41:34 +02:00
|
|
|
(interactive "P")
|
|
|
|
(when (or (not (notmuch-tree-close-message-window)) kill-both)
|
2012-10-27 13:26:38 +02:00
|
|
|
(kill-buffer (current-buffer))))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-close-message-window ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Close the message-window. Return t if close succeeds."
|
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (and (window-live-p notmuch-tree-message-window)
|
2020-08-08 13:49:36 +02:00
|
|
|
(eq (window-buffer notmuch-tree-message-window)
|
|
|
|
notmuch-tree-message-buffer))
|
2013-10-27 00:02:05 +02:00
|
|
|
(delete-window notmuch-tree-message-window)
|
|
|
|
(unless (get-buffer-window-list notmuch-tree-message-buffer)
|
|
|
|
(kill-buffer notmuch-tree-message-buffer))
|
2012-10-27 13:26:38 +02:00
|
|
|
t))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-archive-message (&optional unarchive)
|
2012-12-08 13:41:34 +01:00
|
|
|
"Archive the current message.
|
|
|
|
|
|
|
|
Archive the current message by applying the tag changes in
|
2013-06-04 00:06:09 +02:00
|
|
|
`notmuch-archive-tags' to it. If a prefix argument is given, the
|
|
|
|
message will be \"unarchived\", i.e. the tag changes in
|
|
|
|
`notmuch-archive-tags' will be reversed."
|
2012-12-08 13:41:34 +01:00
|
|
|
(interactive "P")
|
|
|
|
(when notmuch-archive-tags
|
2020-08-08 13:49:36 +02:00
|
|
|
(notmuch-tree-tag
|
|
|
|
(notmuch-tag-change-list notmuch-archive-tags unarchive))))
|
2012-12-08 13:41:34 +01:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-archive-message-then-next (&optional unarchive)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Archive the current message and move to next matching message."
|
2012-12-08 13:41:34 +01:00
|
|
|
(interactive "P")
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-archive-message unarchive)
|
|
|
|
(notmuch-tree-next-matching-message))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-04-04 22:41:41 +02:00
|
|
|
(defun notmuch-tree-archive-thread-then-exit ()
|
|
|
|
"Archive all messages in the current buffer, then exit notmuch-tree."
|
|
|
|
(interactive)
|
|
|
|
(notmuch-tree-archive-thread)
|
|
|
|
(notmuch-tree-quit t))
|
|
|
|
|
2020-04-04 22:41:35 +02:00
|
|
|
(defun notmuch-tree-archive-message-then-next-or-exit ()
|
|
|
|
"Archive current message, then show next open message in current thread.
|
|
|
|
|
|
|
|
If at the last open message in the current thread, then exit back
|
|
|
|
to search results."
|
|
|
|
(interactive)
|
|
|
|
(notmuch-tree-archive-message)
|
|
|
|
(notmuch-tree-next-matching-message t))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-next-message ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Move to next message."
|
|
|
|
(interactive)
|
|
|
|
(forward-line)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(notmuch-tree-show-message-in)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-prev-message ()
|
2012-10-27 13:26:38 +02:00
|
|
|
"Move to previous message."
|
|
|
|
(interactive)
|
|
|
|
(forward-line -1)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(notmuch-tree-show-message-in)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-04-04 22:41:32 +02:00
|
|
|
(defun notmuch-tree-goto-matching-message (&optional prev)
|
|
|
|
"Move to the next or previous matching message.
|
|
|
|
|
|
|
|
Returns t if there was a next matching message in the thread to show,
|
|
|
|
nil otherwise."
|
|
|
|
(let ((dir (if prev -1 nil))
|
|
|
|
(eobfn (if prev #'bobp #'eobp)))
|
|
|
|
(while (and (not (funcall eobfn))
|
|
|
|
(not (notmuch-tree-get-match)))
|
|
|
|
(forward-line dir))
|
|
|
|
(not (funcall eobfn))))
|
|
|
|
|
2020-04-04 22:41:35 +02:00
|
|
|
(defun notmuch-tree-matching-message (&optional prev pop-at-end)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Move to the next or previous matching message."
|
2020-04-04 22:41:33 +02:00
|
|
|
(interactive "P")
|
|
|
|
(forward-line (if prev -1 nil))
|
2020-04-04 22:41:35 +02:00
|
|
|
(if (and (not (notmuch-tree-goto-matching-message prev)) pop-at-end)
|
|
|
|
(notmuch-tree-quit pop-at-end)
|
|
|
|
(when (window-live-p notmuch-tree-message-window)
|
|
|
|
(notmuch-tree-show-message-in))))
|
2020-04-04 22:41:33 +02:00
|
|
|
|
2020-04-04 22:41:35 +02:00
|
|
|
(defun notmuch-tree-prev-matching-message (&optional pop-at-end)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Move to previous matching message."
|
2020-04-04 22:41:35 +02:00
|
|
|
(interactive "P")
|
|
|
|
(notmuch-tree-matching-message t pop-at-end))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-04-04 22:41:35 +02:00
|
|
|
(defun notmuch-tree-next-matching-message (&optional pop-at-end)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Move to next matching message."
|
2020-04-04 22:41:35 +02:00
|
|
|
(interactive "P")
|
|
|
|
(notmuch-tree-matching-message nil pop-at-end))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2020-02-27 18:16:51 +01:00
|
|
|
(defun notmuch-tree-refresh-view (&optional view)
|
2012-10-27 13:26:38 +02:00
|
|
|
"Refresh view."
|
|
|
|
(interactive)
|
2017-08-14 09:08:36 +02:00
|
|
|
(when (get-buffer-process (current-buffer))
|
|
|
|
(error "notmuch tree process already running for current buffer"))
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((inhibit-read-only t)
|
2013-10-27 00:02:05 +02:00
|
|
|
(basic-query notmuch-tree-basic-query)
|
2020-02-27 18:16:51 +01:00
|
|
|
(unthreaded (cond ((eq view 'unthreaded) t)
|
|
|
|
((eq view 'tree) nil)
|
|
|
|
(t notmuch-tree-unthreaded)))
|
2013-10-27 00:02:05 +02:00
|
|
|
(query-context notmuch-tree-query-context)
|
|
|
|
(target (notmuch-tree-get-message-id)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(erase-buffer)
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-worker basic-query
|
2013-01-10 12:14:58 +01:00
|
|
|
query-context
|
2020-02-27 18:16:51 +01:00
|
|
|
target
|
|
|
|
nil
|
2021-07-02 22:44:23 +02:00
|
|
|
unthreaded
|
|
|
|
notmuch-search-oldest-first)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-thread-top ()
|
|
|
|
(when (notmuch-tree-get-message-properties)
|
|
|
|
(while (not (or (notmuch-tree-get-prop :first) (eobp)))
|
2013-08-25 21:55:32 +02:00
|
|
|
(forward-line -1))))
|
|
|
|
|
2020-08-11 19:36:52 +02:00
|
|
|
(defun notmuch-tree-prev-thread-in-tree ()
|
|
|
|
"Move to the previous thread in the current tree"
|
2013-08-25 21:55:34 +02:00
|
|
|
(interactive)
|
|
|
|
(forward-line -1)
|
2020-08-11 19:36:52 +02:00
|
|
|
(notmuch-tree-thread-top)
|
|
|
|
(not (bobp)))
|
2013-08-25 21:55:34 +02:00
|
|
|
|
2020-08-11 19:36:52 +02:00
|
|
|
(defun notmuch-tree-next-thread-in-tree ()
|
2020-04-04 22:41:31 +02:00
|
|
|
"Get the next thread in the current tree. Returns t if a thread was
|
|
|
|
found or nil if not."
|
2013-08-25 21:55:34 +02:00
|
|
|
(interactive)
|
|
|
|
(forward-line 1)
|
2013-10-27 00:02:05 +02:00
|
|
|
(while (not (or (notmuch-tree-get-prop :first) (eobp)))
|
2020-04-04 22:41:31 +02:00
|
|
|
(forward-line 1))
|
|
|
|
(not (eobp)))
|
2013-08-25 21:55:34 +02:00
|
|
|
|
2020-08-11 19:36:52 +02:00
|
|
|
(defun notmuch-tree-next-thread-from-search (&optional previous)
|
|
|
|
"Move to the next thread in the parent search results, if any.
|
|
|
|
|
|
|
|
If PREVIOUS is non-nil, move to the previous item in the
|
|
|
|
search results instead."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((parent-buffer notmuch-tree-parent-buffer))
|
|
|
|
(notmuch-tree-quit t)
|
|
|
|
(when (buffer-live-p parent-buffer)
|
|
|
|
(switch-to-buffer parent-buffer)
|
|
|
|
(if previous
|
|
|
|
(notmuch-search-previous-thread)
|
|
|
|
(notmuch-search-next-thread))
|
|
|
|
(notmuch-tree-from-search-thread))))
|
|
|
|
|
|
|
|
(defun notmuch-tree-next-thread (&optional previous)
|
2021-01-10 15:01:01 +01:00
|
|
|
"Move to the next thread in the current tree or parent search results.
|
2020-08-11 19:36:52 +02:00
|
|
|
|
|
|
|
If PREVIOUS is non-nil, move to the previous thread in the tree or
|
|
|
|
search results instead."
|
|
|
|
(interactive)
|
|
|
|
(unless (if previous (notmuch-tree-prev-thread-in-tree)
|
|
|
|
(notmuch-tree-next-thread-in-tree))
|
|
|
|
(notmuch-tree-next-thread-from-search previous)))
|
|
|
|
|
|
|
|
(defun notmuch-tree-prev-thread ()
|
2021-01-10 15:01:01 +01:00
|
|
|
"Move to the previous thread in the current tree or parent search results."
|
2020-08-11 19:36:52 +02:00
|
|
|
(interactive)
|
|
|
|
(notmuch-tree-next-thread t))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-thread-mapcar (function)
|
2021-01-10 15:01:01 +01:00
|
|
|
"Call FUNCTION for each message in the current thread.
|
|
|
|
FUNCTION is called for side effects only."
|
2013-08-25 21:55:32 +02:00
|
|
|
(save-excursion
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-thread-top)
|
2020-04-25 22:18:07 +02:00
|
|
|
(cl-loop collect (funcall function)
|
|
|
|
do (forward-line)
|
|
|
|
while (and (notmuch-tree-get-message-properties)
|
|
|
|
(not (notmuch-tree-get-prop :first))))))
|
2013-08-25 21:55:32 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-get-messages-ids-thread-search ()
|
2013-08-25 21:55:32 +02:00
|
|
|
"Return a search string for all message ids of messages in the current thread."
|
|
|
|
(mapconcat 'identity
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-thread-mapcar 'notmuch-tree-get-message-id)
|
2013-08-25 21:55:32 +02:00
|
|
|
" or "))
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-tag-thread (tag-changes)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Tag all messages in the current thread."
|
2013-10-23 02:22:00 +02:00
|
|
|
(interactive
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((tags (apply #'append (notmuch-tree-thread-mapcar
|
|
|
|
(lambda () (notmuch-tree-get-tags))))))
|
2013-10-23 02:22:00 +02:00
|
|
|
(list (notmuch-read-tag-changes tags "Tag thread"))))
|
2013-10-27 00:02:05 +02:00
|
|
|
(when (notmuch-tree-get-message-properties)
|
|
|
|
(notmuch-tag (notmuch-tree-get-messages-ids-thread-search) tag-changes)
|
|
|
|
(notmuch-tree-thread-mapcar
|
|
|
|
(lambda () (notmuch-tree-tag-update-display tag-changes)))))
|
2013-08-25 21:55:33 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-archive-thread (&optional unarchive)
|
2013-08-25 21:55:33 +02:00
|
|
|
"Archive each message in thread.
|
|
|
|
|
|
|
|
Archive each message currently shown by applying the tag changes
|
|
|
|
in `notmuch-archive-tags' to each. If a prefix argument is given,
|
|
|
|
the messages will be \"unarchived\", i.e. the tag changes in
|
|
|
|
`notmuch-archive-tags' will be reversed.
|
|
|
|
|
|
|
|
Note: This command is safe from any race condition of new messages
|
|
|
|
being delivered to the same thread. It does not archive the
|
|
|
|
entire thread, but only the messages shown in the current
|
|
|
|
buffer."
|
|
|
|
(interactive "P")
|
|
|
|
(when notmuch-archive-tags
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-tag-thread
|
2013-08-25 21:55:33 +02:00
|
|
|
(notmuch-tag-change-list notmuch-archive-tags unarchive))))
|
|
|
|
|
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
|
|
|
;;; Functions for displaying the tree buffer itself
|
2013-08-25 21:55:32 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-clean-address (address)
|
2012-12-01 19:02:02 +01:00
|
|
|
"Try to clean a single email ADDRESS for display. Return
|
|
|
|
AUTHOR_NAME if present, otherwise return AUTHOR_EMAIL. Return
|
2012-10-27 13:26:38 +02:00
|
|
|
unchanged ADDRESS if parsing fails."
|
2012-12-01 19:02:02 +01:00
|
|
|
(let* ((clean-address (notmuch-clean-address address))
|
|
|
|
(p-address (car clean-address))
|
|
|
|
(p-name (cdr clean-address)))
|
|
|
|
|
|
|
|
;; If we have a name return that otherwise return the address.
|
|
|
|
(or p-name p-address)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-format-field (field format-string msg)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Format a FIELD of MSG according to FORMAT-STRING and return string."
|
2012-10-27 13:26:38 +02:00
|
|
|
(let* ((headers (plist-get msg :headers))
|
2013-09-15 10:41:17 +02:00
|
|
|
(match (plist-get msg :match)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(cond
|
2013-09-02 05:28:07 +02:00
|
|
|
((listp field)
|
2013-10-27 00:02:05 +02:00
|
|
|
(format format-string (notmuch-tree-format-field-list field msg)))
|
2013-09-02 05:28:07 +02:00
|
|
|
|
2021-02-21 16:19:02 +01:00
|
|
|
((functionp field)
|
|
|
|
(funcall field format-string msg))
|
|
|
|
|
2012-10-27 13:26:38 +02:00
|
|
|
((string-equal field "date")
|
|
|
|
(let ((face (if match
|
2013-10-27 00:02:05 +02:00
|
|
|
'notmuch-tree-match-date-face
|
|
|
|
'notmuch-tree-no-match-date-face)))
|
2020-08-08 13:49:36 +02:00
|
|
|
(propertize (format format-string (plist-get msg :date_relative))
|
|
|
|
'face face)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-09-02 05:28:08 +02:00
|
|
|
((string-equal field "tree")
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((tree-status (plist-get msg :tree-status))
|
2013-09-02 05:28:08 +02:00
|
|
|
(face (if match
|
2013-10-27 00:02:05 +02:00
|
|
|
'notmuch-tree-match-tree-face
|
|
|
|
'notmuch-tree-no-match-tree-face)))
|
2013-09-02 05:28:08 +02:00
|
|
|
|
2013-09-15 10:41:17 +02:00
|
|
|
(propertize (format format-string
|
|
|
|
(mapconcat #'identity (reverse tree-status) ""))
|
|
|
|
'face face)))
|
2013-09-02 05:28:08 +02:00
|
|
|
|
|
|
|
((string-equal field "subject")
|
|
|
|
(let ((bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))
|
2013-10-27 00:02:05 +02:00
|
|
|
(previous-subject notmuch-tree-previous-subject)
|
2012-10-27 13:26:38 +02:00
|
|
|
(face (if match
|
2013-10-27 00:02:05 +02:00
|
|
|
'notmuch-tree-match-subject-face
|
|
|
|
'notmuch-tree-no-match-subject-face)))
|
2013-09-15 10:41:17 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(setq notmuch-tree-previous-subject bare-subject)
|
2013-09-15 10:41:17 +02:00
|
|
|
(propertize (format format-string
|
|
|
|
(if (string= previous-subject bare-subject)
|
|
|
|
" ..."
|
|
|
|
bare-subject))
|
|
|
|
'face face)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
|
|
|
((string-equal field "authors")
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((author (notmuch-tree-clean-address (plist-get headers :From)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(len (length (format format-string "")))
|
|
|
|
(face (if match
|
2013-10-27 00:02:05 +02:00
|
|
|
'notmuch-tree-match-author-face
|
|
|
|
'notmuch-tree-no-match-author-face)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(when (> (length author) len)
|
|
|
|
(setq author (substring author 0 len)))
|
2013-09-15 10:41:17 +02:00
|
|
|
(propertize (format format-string author) 'face face)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
|
|
|
((string-equal field "tags")
|
|
|
|
(let ((tags (plist-get msg :tags))
|
2014-03-22 12:51:12 +01:00
|
|
|
(orig-tags (plist-get msg :orig-tags))
|
2012-10-27 13:26:38 +02:00
|
|
|
(face (if match
|
2013-10-27 00:02:05 +02:00
|
|
|
'notmuch-tree-match-tag-face
|
|
|
|
'notmuch-tree-no-match-tag-face)))
|
2014-03-22 12:51:12 +01:00
|
|
|
(format format-string (notmuch-tag-format-tags tags orig-tags face)))))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-format-field-list (field-list msg)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Format fields of MSG according to FIELD-LIST and return string."
|
2014-01-11 22:41:42 +01:00
|
|
|
(let ((face (if (plist-get msg :match)
|
|
|
|
'notmuch-tree-match-face
|
|
|
|
'notmuch-tree-no-match-face))
|
|
|
|
(result-string))
|
2013-09-02 05:28:07 +02:00
|
|
|
(dolist (spec field-list result-string)
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((field-string (notmuch-tree-format-field (car spec) (cdr spec) msg)))
|
2014-01-11 22:41:42 +01:00
|
|
|
(setq result-string (concat result-string field-string))))
|
2014-03-22 12:51:05 +01:00
|
|
|
(notmuch-apply-face result-string face t)))
|
2013-09-02 05:28:07 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-insert-msg (msg)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Insert the message MSG according to notmuch-tree-result-format."
|
2013-06-30 10:55:12 +02:00
|
|
|
;; We need to save the previous subject as it will get overwritten
|
|
|
|
;; by the insert-field calls.
|
2013-10-27 00:02:05 +02:00
|
|
|
(let ((previous-subject notmuch-tree-previous-subject))
|
2020-02-27 18:16:49 +01:00
|
|
|
(insert (notmuch-tree-format-field-list (notmuch-tree-result-format) msg))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-set-message-properties msg)
|
|
|
|
(notmuch-tree-set-prop :previous-subject previous-subject)
|
2013-06-30 10:55:12 +02:00
|
|
|
(insert "\n")))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-goto-and-insert-msg (msg)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Insert msg at the end of the buffer. Move point to msg if it is the target."
|
2013-01-10 11:41:16 +01:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-max))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-insert-msg msg))
|
2013-06-30 10:55:10 +02:00
|
|
|
(let ((msg-id (notmuch-id-to-query (plist-get msg :id)))
|
2013-10-27 00:02:05 +02:00
|
|
|
(target notmuch-tree-target-msg))
|
2013-06-30 10:55:10 +02:00
|
|
|
(when (or (and (not target) (plist-get msg :match))
|
|
|
|
(string= msg-id target))
|
2013-10-27 00:02:05 +02:00
|
|
|
(setq notmuch-tree-target-msg "found")
|
2013-01-10 12:14:58 +01:00
|
|
|
(goto-char (point-max))
|
2013-06-30 10:55:11 +02:00
|
|
|
(forward-line -1)
|
2013-10-27 00:02:05 +02:00
|
|
|
(when notmuch-tree-open-target
|
2021-02-16 01:01:38 +01:00
|
|
|
(notmuch-tree-show-message-in)
|
|
|
|
(notmuch-tree-command-hook)))))
|
2013-01-10 12:14:58 +01:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-insert-tree (tree depth tree-status first last)
|
2013-07-01 22:05:43 +02:00
|
|
|
"Insert the message tree TREE at depth DEPTH in the current thread.
|
|
|
|
|
|
|
|
A message tree is another name for a single sub-thread: i.e., a
|
|
|
|
message together with all its descendents."
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((msg (car tree))
|
|
|
|
(replies (cadr tree)))
|
2020-08-08 13:49:38 +02:00
|
|
|
(cond
|
|
|
|
((and (< 0 depth) (not last))
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'vertical-tee notmuch-tree-thread-symbols) tree-status))
|
2020-08-08 13:49:38 +02:00
|
|
|
((and (< 0 depth) last)
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'bottom notmuch-tree-thread-symbols) tree-status))
|
2020-08-08 13:49:38 +02:00
|
|
|
((and (eq 0 depth) first last)
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'prefix notmuch-tree-thread-symbols) tree-status))
|
2020-08-08 13:49:38 +02:00
|
|
|
((and (eq 0 depth) first (not last))
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'top-tee notmuch-tree-thread-symbols) tree-status))
|
2020-08-08 13:49:38 +02:00
|
|
|
((and (eq 0 depth) (not first) last)
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'bottom notmuch-tree-thread-symbols) tree-status))
|
2020-08-08 13:49:38 +02:00
|
|
|
((and (eq 0 depth) (not first) (not last))
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'vertical-tee notmuch-tree-thread-symbols) tree-status)))
|
|
|
|
(push (concat (alist-get (if replies 'top-tee 'top) notmuch-tree-thread-symbols)
|
|
|
|
(alist-get 'arrow notmuch-tree-thread-symbols))
|
|
|
|
tree-status)
|
2020-08-08 13:49:38 +02:00
|
|
|
(setq msg (plist-put msg :first (and first (eq 0 depth))))
|
|
|
|
(setq msg (plist-put msg :tree-status tree-status))
|
|
|
|
(setq msg (plist-put msg :orig-tags (plist-get msg :tags)))
|
|
|
|
(notmuch-tree-goto-and-insert-msg msg)
|
|
|
|
(pop tree-status)
|
|
|
|
(pop tree-status)
|
|
|
|
(if last
|
|
|
|
(push " " tree-status)
|
2021-08-31 03:21:06 +02:00
|
|
|
(push (alist-get 'vertical notmuch-tree-thread-symbols) tree-status))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-insert-thread replies (1+ depth) tree-status)))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-insert-thread (thread depth tree-status)
|
2013-07-01 22:05:43 +02:00
|
|
|
"Insert the collection of sibling sub-threads THREAD at depth DEPTH in the current forest."
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((n (length thread)))
|
2020-04-25 22:18:07 +02:00
|
|
|
(cl-loop for tree in thread
|
|
|
|
for count from 1 to n
|
|
|
|
do (notmuch-tree-insert-tree tree depth tree-status
|
|
|
|
(eq count 1)
|
|
|
|
(eq count n)))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-insert-forest-thread (forest-thread)
|
2013-07-01 22:05:43 +02:00
|
|
|
"Insert a single complete thread."
|
2021-07-07 03:51:08 +02:00
|
|
|
;; Reset at the start of each main thread.
|
|
|
|
(setq notmuch-tree-previous-subject nil)
|
|
|
|
(notmuch-tree-insert-thread forest-thread 0 nil))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-insert-forest (forest)
|
2013-07-01 22:05:43 +02:00
|
|
|
"Insert a forest of threads.
|
|
|
|
|
|
|
|
This function inserts a collection of several complete threads as
|
2013-10-27 00:02:05 +02:00
|
|
|
passed to it by notmuch-tree-process-filter."
|
|
|
|
(mapc 'notmuch-tree-insert-forest-thread forest))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2016-08-28 20:41:22 +02:00
|
|
|
(define-derived-mode notmuch-tree-mode fundamental-mode "notmuch-tree"
|
2017-07-08 03:01:59 +02:00
|
|
|
"Major mode displaying messages (as opposed to threads) of a notmuch search.
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
This buffer contains the results of a \"notmuch tree\" of your
|
2012-10-27 13:26:38 +02:00
|
|
|
email archives. Each line in the buffer represents a single
|
|
|
|
message giving the relative date, the author, subject, and any
|
|
|
|
tags.
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
Pressing \\[notmuch-tree-show-message] on any line displays that message.
|
2012-10-27 13:26:38 +02:00
|
|
|
|
|
|
|
Complete list of currently available key bindings:
|
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
\\{notmuch-tree-mode-map}"
|
|
|
|
(setq notmuch-buffer-refresh-function #'notmuch-tree-refresh-view)
|
2012-10-27 13:26:38 +02:00
|
|
|
(hl-line-mode 1)
|
2020-08-08 13:49:40 +02:00
|
|
|
(setq buffer-read-only t)
|
|
|
|
(setq truncate-lines t))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2021-01-10 15:00:48 +01:00
|
|
|
(defun notmuch-tree-process-sentinel (proc _msg)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Add a message to let user know when \"notmuch tree\" exits."
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((buffer (process-buffer proc))
|
|
|
|
(status (process-status proc))
|
2021-01-10 15:00:48 +01:00
|
|
|
(exit-status (process-exit-status proc)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(when (memq status '(exit signal))
|
2020-08-08 13:49:38 +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
|
2021-01-10 15:00:48 +01:00
|
|
|
(let ((inhibit-read-only t))
|
2020-08-08 13:49:43 +02:00
|
|
|
(goto-char (point-max))
|
|
|
|
(when (eq status 'signal)
|
|
|
|
(insert "Incomplete search results (tree view process was killed).\n"))
|
|
|
|
(when (eq status 'exit)
|
|
|
|
(insert "End of search results.")
|
|
|
|
(unless (= exit-status 0)
|
|
|
|
(insert (format " (process returned %d)" exit-status)))
|
|
|
|
(insert "\n")))))))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(defun notmuch-tree-process-filter (proc string)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Process and filter the output of \"notmuch show\" for tree view."
|
2012-10-27 13:26:38 +02:00
|
|
|
(let ((results-buf (process-buffer proc))
|
2020-08-08 13:49:38 +02:00
|
|
|
(parse-buf (process-get proc 'parse-buf))
|
2021-01-10 15:00:48 +01:00
|
|
|
(inhibit-read-only t))
|
2012-10-27 13:26:38 +02:00
|
|
|
(if (not (buffer-live-p results-buf))
|
2020-08-08 13:49:38 +02:00
|
|
|
(delete-process proc)
|
2012-10-27 13:26:38 +02:00
|
|
|
(with-current-buffer parse-buf
|
2020-08-08 13:49:38 +02:00
|
|
|
;; Insert new data
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert string))
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-sexp-parse-partial-list 'notmuch-tree-insert-forest-thread
|
2012-10-28 14:37:10 +01:00
|
|
|
results-buf)))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2021-07-02 22:44:22 +02:00
|
|
|
(defun notmuch-tree-worker (basic-query &optional query-context target
|
|
|
|
open-target unthreaded oldest-first)
|
2013-10-27 00:02:05 +02:00
|
|
|
"Insert the tree view of the search in the current buffer.
|
2013-09-02 22:15:13 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
This is is a helper function for notmuch-tree. The arguments are
|
|
|
|
the same as for the function notmuch-tree."
|
2012-10-27 13:26:38 +02:00
|
|
|
(interactive)
|
2013-10-27 00:02:05 +02:00
|
|
|
(notmuch-tree-mode)
|
2015-06-09 11:51:07 +02:00
|
|
|
(add-hook 'post-command-hook #'notmuch-tree-command-hook t t)
|
2021-07-02 22:44:23 +02:00
|
|
|
(setq notmuch-search-oldest-first oldest-first)
|
2020-02-27 18:16:48 +01:00
|
|
|
(setq notmuch-tree-unthreaded unthreaded)
|
2013-10-27 00:02:05 +02:00
|
|
|
(setq notmuch-tree-basic-query basic-query)
|
2017-08-13 11:07:24 +02:00
|
|
|
(setq notmuch-tree-query-context (if (or (string= query-context "")
|
|
|
|
(string= query-context "*"))
|
2020-08-08 13:49:44 +02:00
|
|
|
nil
|
|
|
|
query-context))
|
2013-10-27 00:02:05 +02:00
|
|
|
(setq notmuch-tree-target-msg target)
|
|
|
|
(setq notmuch-tree-open-target open-target)
|
2015-10-15 20:46:34 +02:00
|
|
|
;; Set the default value for `notmuch-show-process-crypto' in this
|
|
|
|
;; buffer. Although we don't use this some of the functions we call
|
|
|
|
;; (such as reply) do. It is a buffer local variable so setting it
|
|
|
|
;; will not affect genuine show buffers.
|
|
|
|
(setq notmuch-show-process-crypto notmuch-crypto-process-mime)
|
2012-10-27 13:26:38 +02:00
|
|
|
(erase-buffer)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(let* ((search-args (concat basic-query
|
2020-08-08 13:49:41 +02:00
|
|
|
(and query-context
|
|
|
|
(concat " and (" query-context ")"))))
|
2021-07-02 22:44:22 +02:00
|
|
|
(sort-arg (if oldest-first "--sort=oldest-first" "--sort=newest-first"))
|
2020-02-27 18:16:48 +01:00
|
|
|
(message-arg (if unthreaded "--unthreaded" "--entire-thread")))
|
2021-08-29 21:23:29 +02:00
|
|
|
(when (equal (car (notmuch--process-lines notmuch-command "count" search-args)) "0")
|
2020-08-08 13:49:43 +02:00
|
|
|
(setq search-args basic-query))
|
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)
|
2013-08-26 21:57:22 +02:00
|
|
|
(let ((proc (notmuch-start-notmuch
|
2013-10-27 00:02:05 +02:00
|
|
|
"notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel
|
2021-08-22 02:00:11 +02:00
|
|
|
"show" "--body=false" "--format=sexp" "--format-version=5"
|
2021-07-02 22:44:22 +02:00
|
|
|
sort-arg message-arg search-args))
|
2013-08-26 21:57:22 +02:00
|
|
|
;; 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.
|
2013-10-27 00:02:05 +02:00
|
|
|
(parse-buf (generate-new-buffer " *notmuch tree parse*")))
|
2013-08-26 21:57:22 +02:00
|
|
|
(process-put proc 'parse-buf parse-buf)
|
2013-10-27 00:02:05 +02:00
|
|
|
(set-process-filter proc 'notmuch-tree-process-filter)
|
2013-08-26 21:57:22 +02:00
|
|
|
(set-process-query-on-exit-flag proc nil))))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2014-06-23 23:06:46 +02:00
|
|
|
(defun notmuch-tree-get-query ()
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return the current query in this tree buffer."
|
2014-06-23 23:06:46 +02:00
|
|
|
(if notmuch-tree-query-context
|
|
|
|
(concat notmuch-tree-basic-query
|
|
|
|
" and ("
|
|
|
|
notmuch-tree-query-context
|
|
|
|
")")
|
|
|
|
notmuch-tree-basic-query))
|
|
|
|
|
2021-07-02 22:44:23 +02:00
|
|
|
(defun notmuch-tree-toggle-order ()
|
|
|
|
"Toggle the current search order.
|
|
|
|
|
|
|
|
This command toggles the sort order for the current search. The
|
|
|
|
default sort order is defined by `notmuch-search-oldest-first'."
|
|
|
|
(interactive)
|
|
|
|
(setq notmuch-search-oldest-first (not notmuch-search-oldest-first))
|
|
|
|
(notmuch-tree-refresh-view))
|
|
|
|
|
2021-01-16 18:17:09 +01:00
|
|
|
(defun notmuch-tree (&optional query query-context target buffer-name
|
2021-07-02 22:44:22 +02:00
|
|
|
open-target unthreaded parent-buffer oldest-first)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Display threads matching QUERY in tree view.
|
2013-07-01 09:53:59 +02:00
|
|
|
|
|
|
|
The arguments are:
|
|
|
|
QUERY: the main query. This can be any query but in many cases will be
|
|
|
|
a single thread. If nil this is read interactively from the minibuffer.
|
|
|
|
QUERY-CONTEXT: is an additional term for the query. The query used
|
|
|
|
is QUERY and QUERY-CONTEXT unless that does not match any messages
|
|
|
|
in which case we fall back to just QUERY.
|
|
|
|
TARGET: A message ID (with the id: prefix) that will be made
|
2013-10-27 00:02:05 +02:00
|
|
|
current if it appears in the tree view results.
|
|
|
|
BUFFER-NAME: the name of the buffer to display the tree view. If
|
|
|
|
it is nil \"*notmuch-tree\" followed by QUERY is used.
|
2020-02-27 18:16:48 +01:00
|
|
|
OPEN-TARGET: If TRUE open the target message in the message pane.
|
|
|
|
UNTHREADED: If TRUE only show matching messages in an unthreaded view."
|
2013-09-15 10:19:33 +02:00
|
|
|
(interactive)
|
2020-08-08 13:49:42 +02:00
|
|
|
(unless query
|
|
|
|
(setq query (notmuch-read-query (concat "Notmuch "
|
|
|
|
(if unthreaded "unthreaded " "tree ")
|
|
|
|
"view search: "))))
|
2022-01-23 20:54:17 +01:00
|
|
|
(let* ((name
|
|
|
|
(or buffer-name
|
|
|
|
(notmuch-search-buffer-title query
|
|
|
|
(if unthreaded "unthreaded" "tree"))))
|
|
|
|
(buffer (get-buffer-create (generate-new-buffer-name name)))
|
2012-10-27 13:26:38 +02:00
|
|
|
(inhibit-read-only t))
|
2020-08-11 18:59:13 +02:00
|
|
|
(pop-to-buffer-same-window buffer))
|
2013-09-02 22:15:12 +02:00
|
|
|
;; Don't track undo information for this buffer
|
2021-01-10 15:00:37 +01:00
|
|
|
(setq buffer-undo-list t)
|
2021-07-02 22:44:22 +02:00
|
|
|
(notmuch-tree-worker query query-context target open-target unthreaded oldest-first)
|
2020-08-11 19:36:51 +02:00
|
|
|
(setq notmuch-tree-parent-buffer parent-buffer)
|
2013-09-02 22:15:12 +02:00
|
|
|
(setq truncate-lines t))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2021-01-16 18:17:09 +01:00
|
|
|
(defun notmuch-unthreaded (&optional query query-context target buffer-name
|
|
|
|
open-target)
|
2021-10-11 13:19:21 +02:00
|
|
|
"Display threads matching QUERY in unthreaded view.
|
|
|
|
|
|
|
|
See function NOTMUCH-TREE for documentation of the arguments"
|
2020-02-27 18:16:48 +01:00
|
|
|
(interactive)
|
|
|
|
(notmuch-tree query query-context target buffer-name open-target t))
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2021-08-22 02:50:48 +02:00
|
|
|
(defun notmuch-tree-filter (query)
|
|
|
|
"Filter or LIMIT the current search results based on an additional query string.
|
|
|
|
|
|
|
|
Runs a new tree search matching only messages that match both the
|
|
|
|
current search results AND the additional query string provided."
|
|
|
|
(interactive (list (notmuch-read-query "Filter search: ")))
|
|
|
|
(let ((notmuch-show-process-crypto (notmuch-tree--message-process-crypto))
|
|
|
|
(grouped-query (notmuch-group-disjunctive-query-string query))
|
|
|
|
(grouped-original-query (notmuch-group-disjunctive-query-string
|
|
|
|
(notmuch-tree-get-query))))
|
|
|
|
(notmuch-tree-close-message-window)
|
|
|
|
(notmuch-tree (if (string= grouped-original-query "*")
|
|
|
|
grouped-query
|
|
|
|
(concat grouped-original-query " and " grouped-query)))))
|
|
|
|
|
2021-08-22 02:50:49 +02:00
|
|
|
(defun notmuch-tree-filter-by-tag (tag)
|
|
|
|
"Filter the current search results based on a single TAG.
|
|
|
|
|
|
|
|
Run a new search matching only messages that match the current
|
|
|
|
search results and that are also tagged with the given TAG."
|
|
|
|
(interactive
|
|
|
|
(list (notmuch-select-tag-with-completion "Filter by tag: "
|
|
|
|
notmuch-tree-basic-query)))
|
|
|
|
(let ((notmuch-show-process-crypto (notmuch-tree--message-process-crypto)))
|
|
|
|
(notmuch-tree-close-message-window)
|
|
|
|
(notmuch-tree (concat notmuch-tree-basic-query " and tag:" tag)
|
|
|
|
notmuch-tree-query-context
|
|
|
|
nil
|
|
|
|
nil
|
|
|
|
nil
|
|
|
|
notmuch-tree-unthreaded
|
|
|
|
nil
|
|
|
|
notmuch-search-oldest-first)))
|
|
|
|
|
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
|
|
|
;;; _
|
2012-10-27 13:26:38 +02:00
|
|
|
|
2013-10-27 00:02:05 +02:00
|
|
|
(provide 'notmuch-tree)
|
2016-04-13 09:58:47 +02:00
|
|
|
|
|
|
|
;;; notmuch-tree.el ends here
|