Commit graph

6795 commits

Author SHA1 Message Date
David Bremner
baf1202fbc bindings/notmuch2: add missing crypto error status codes
These are needed so that the later codes line up numerically.
2021-02-06 19:37:50 -04:00
David Bremner
f118ef3c3d cli/compact: convert to new configuration framework
Switch to the newly created API function notmuch_database_compact_db,
which takes the database opened in main().
2021-02-06 19:36:06 -04:00
David Bremner
5232462dcf lib: split notmuch_database_compact
The "back end" function takes an open notmuch database, which should
know its own path (i.e. the path needs to be cached in the
configuration data).
2021-02-06 19:34:17 -04:00
David Bremner
87e3a82feb lib/config: add _notmuch_config_cache
This is a simple convenience routine to cache a configuration value
without writing it to the database.
2021-02-06 19:32:29 -04:00
David Bremner
c56dcea7e2 cli/tag: convert to new config framework.
In addition to changing configuration access, change talloc context
for allocation.
2021-02-06 19:30:20 -04:00
David Bremner
6c28039ebb CLI/show: mostly switch show to new config framework
This will need some cleanup when the transition completes, and we stop
passing notmuch_config_t structs to the subcommands.

Unlike the general case, we open the database in the subcommand, since
we don't know whether it should be opened read/write until we parse
the command line arguments.

Add a test to make sure passing config file on the command line is not
broken by these or future config related changes.
2021-02-06 19:27:54 -04:00
David Bremner
dd6b507099 cli/config: add accessor for config file name
This is intended for use in temporary code transitioning to the new
configuration system. The name is chosen to avoid cluttering the
notmuch_config_* namespace further with non-library functions.
2021-02-06 19:25:35 -04:00
David Bremner
d613d10ddd CLI/{search,address}: convert to new configuration framework
Since we are already passing a search context around as a kind of
parameter block, add a new talloc context to that to replace relying
on 'config'.

Convert notmuch-search and notmuch-address at the same time, because
they share some code.

Add a test to make sure we don't break passing configuration as a
command line argument.
2021-02-06 19:23:28 -04:00
David Bremner
8588719eb1 CLI/reply: convert to new config framework
This is messier than some of the other conversions because the
extensive use of 'config' as a talloc context.
2021-02-06 19:21:23 -04:00
David Bremner
0ab0b48be2 cli/reindex: convert new config framework
The only non-trivial part is switching the talloc context for
query_string_from args from 'config' to 'notmuch'.
2021-02-06 19:19:18 -04:00
David Bremner
f994f0e7df CLI/insert: convert to new config framework.
The new talloc context is needed to run the hook at the very end of
the function. That in turn is needed so that this process gives up the
write lock on the database.
2021-02-06 19:17:34 -04:00
David Bremner
66adcd4f53 CLI/restore: convert to new config framework
Switch one configuration check to new n_c_get_bool function, and
switch use of config as talloc context to notmuch.
2021-02-06 19:15:53 -04:00
David Bremner
a4af7a2a1b lib: add notmuch_config_get_bool
Booleans have no out of band values, so return a status for errors.
2021-02-06 19:14:11 -04:00
David Bremner
53f27aaf73 cli/dump: convert to new config framework
This conversion is trivial because the only configuration information
accessed by dump is that stored in the database (in order to dump
it). We do need to be careful to keep the write lock on the database
to ensure dump consistency.
2021-02-06 19:12:34 -04:00
David Bremner
acc6331baa CLI/count: switch to new configuration framework
The main effort is changing from the old argv style config list
iterators to the new more opaque ones provided by the library (and
backed by the database+file config cache).
2021-02-06 19:11:06 -04:00
David Bremner
d071828bd5 lib/config: make values iterators restartable
This is relatively cheap, and makes it easier to transform existing
code which uses arrays of pointers to store configuration lists.
2021-02-06 19:09:39 -04:00
David Bremner
fd6f8e6c30 lib/config: add config values iterator
This is intended to avoid duplicating the string splitting and
traversal code for all clients of the config API.
2021-02-06 19:08:12 -04:00
David Bremner
3fb123f215 util: add strsplit_len: simplified strtok with delimiter escaping
This will be used to make iterators for configuration values.
2021-02-06 19:06:49 -04:00
David Bremner
319efe21c9 CLI: add (unused) database argument to subcommands.
This will allow transitioning individual subcommands to the new
configuration framework. Eventually when they are all converted we can
remove the notmuch_config_t * argument.

For now, live with the parameter shadowing in some some subcommands;
it will go away when they are converted.
2021-02-06 19:05:19 -04:00
David Bremner
06a64cf0aa lib/open: load default values for known configuration keys.
This emulates the behaviour of notmuch_config_open defined in the CLI,
in that it fills in default values if they are not otherwise defined.
2021-02-06 19:03:36 -04:00
David Bremner
d6bd87a712 lib/config: add notmuch_config_key_{get,set}
By using an enum we can have better error detection than copy pasting
key strings around.

The question of what layer this belongs in is a bit
tricky. Historically most of the keys are defined by the CLI. On the
other hand features like excludes are supported in the
library/bindings, and it makes sense to configure them from the
library as well.

The somewhat long prefix for notmuch_config_t is to avoid collisions
with the existing usage in notmuch-client.h.
2021-02-06 19:02:00 -04:00
David Bremner
867d7352a7 CLI: generalize notmuch_config_mode_t
The renaming and extra values will make sense when we start to convert
subcommands to the new configuration framework. It will also avoid
collisions with a new enum for configuration keys to be introduced in
a future commit.
2021-02-06 19:00:30 -04:00
David Bremner
39580e2d7f lib/open: add support for config profiles and default locations
Fill in the remainder of the documented functionality for
n_d_open_with_config with respect to config file location. Similar
searching default locations of the database file still needs to be
added.
2021-02-06 18:59:00 -04:00
David Bremner
e5f3c3ed50 lib: add stub for notmuch_database_open_with_config
Initially document the intended API and copy the code from
notmuch_database_open_verbose. Most of the documented functionality is
not there yet.
2021-02-06 18:57:35 -04:00
David Bremner
4743e87c2c lib: cache configuration information from database
The main goal is to allow configuration information to be temporarily
overridden by a separate config file. That will require further
changes not in this commit.

The performance impact is unclear, and will depend on the balance
between number of queries and number of distinct metadata items read
on the first call to n_d_get_config.
2021-02-06 18:56:05 -04:00
David Bremner
763445beae lib: add _notmuch_string_map_set
This will be used (and tested) by the configuration caching code to be
added in the next commit.
2021-02-06 18:54:23 -04:00
David Edmondson
8b7c09c66b emacs: When completing tags, offer each tag once
When prompting for one or more tags to add or remove to/from one or
more threads, ensure that the set of tags offered for completion
contains no duplicates.

Some completion packages (e.g. selectrum) will include every member of
the offered list, resulting in the same tag being indicated as a
possibility several times.
2021-02-05 10:12:53 -04:00
Đoàn Trần Công Danh
5648bebe69 notmuch-show: use correct format specifier for ssize_t
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
2021-02-05 10:07:04 -04:00
David Bremner
6a7b61b1d5 test: add (back) upgrade tests
In ee897cab8b the upgrade tests from pre v3 databases were
removed. The reasons for that are still valid, but we should still
test the code paths that do the upgrade, and it is relatively
straightforward to do that for v3 to v3 upgrades.
2021-01-17 13:24:04 -04:00
David Bremner
15d8067c0a test/T391-python-cffi
Make bindings test verbose. This helps in debugging.
2021-01-15 07:43:23 -04:00
David Bremner
003fdba7a4 test/T750-gzip: don't compress the xapian database
This causes mysterious failures in trying to detect if a database
exists.
2021-01-15 07:43:07 -04:00
Jonas Bernoulli
1f14dbfbd7 emacs: avoid type errors due to nil as content-type
The output of "notmuch show --format=sexp --format-version=4"
may contain `:content-type' entries with `nil' as the value,
when it fails to detect the correct value.  Account for that
in a few places where we would otherwise risk a type error.

Note that `string=' does not choke on `nil' because it uses
the `symbol-name' when encountering a symbol.
2021-01-15 07:30:33 -04:00
Jonas Bernoulli
f1ae9addc6 emacs: notmuch-show--get-cid-content: cosmetics 2021-01-15 07:30:14 -04:00
Jonas Bernoulli
99bf983d8c emacs: notmuch-show--register-cids: fix names of bindings 2021-01-15 07:30:00 -04:00
Jonas Bernoulli
6cae6f32b1 emacs: notmuch-mua-add-more-hidden-headers: use local binding 2021-01-15 07:29:09 -04:00
Jonas Bernoulli
a2bf29ad35 emacs: notmuch-address-expand-name: use the actual initial-input
Users may type some text into the buffer on an address line, before
actually invoking address completion.  We now use that text as the
initial input when we begin address completion.

Previously we did knowingly replace the actual initial input with some
completion candidate that happens to match. Which candidate is used is
essentially random, at least when the actual initial input is short.
As a result users very often had to begin completion by deleting the
less than helpful "initial input".
2021-01-15 06:49:07 -04:00
Jonas Bernoulli
055294454f emacs: allow opting out of notmuch's address completion
IMO Notmuch should not override the default completion mechanism by
default, at least not globally. But since users are already used to
this behavior it is probably too late to change it. Do the next best
thing and at least allow users to opt out.
2021-01-15 06:48:24 -04:00
Jonas Bernoulli
9b5fd49ab2 emacs: notmuch-tree-get-match: No longer define as command
When called from code, then this function returns non-nil when the
message at point is a matched message.  However it does nothing at all
to present that information to the user when it called interactively.
It is therefore safe to conclude that nobody is using this as a
command.
2021-01-15 06:47:48 -04:00
Jonas Bernoulli
371f481d93 emacs: use string-empty-p 2021-01-15 06:47:28 -04:00
Jonas Bernoulli
f3d6fa2e40 emacs: make subr-x available in all libraries
Like `cl-lib' and `pcase', which are already available in all
libraries, `subr-x' also provided many useful functions that
we would like to use.

Making `subr-x' available in every library from the get-go means
that we can use the functions it defines without having to double
check every single time, whether the feature is already available
in the current library.
2021-01-15 06:47:10 -04:00
Jonas Bernoulli
9ca1f945d9 emacs: improve how cl-lib and pcase are required
We need to load `cl-lib' at run-time because we use more from it than
just macros.  Never-the-less many, but not all libraries required it
only at compile-time, which we got away with because at least some
libraries already required it at run-time as well.

We use `cl-lib' and (currently to a lesser extend) `pcase' throughout
the code-base, which means that we should require these features in
most libraries.

In the past we tried to only require these features in just the
libraries that actually need them, without fully succeeding.  We did
not succeed in doing so because that means we would have to check
every time that we use a function from these features whether they
are already being required in the current library.

An alternative would be to add the `require' forms at the top of every
library but that is a bit annoying too.

In order to make sure that these features are loaded when needed but
also to keep the noise down we only require them in "notmuch-lib.el",
which most other libraries require, and in most of the few libraries
that do not do so, namely "notmuch-draft.el", "notmuch-message.el" and
"notmuch-parser.el".  ("coolj.el", "make-deps.el", various generated
libraries, and "notmuch-compat.el" are left touched.)
2021-01-15 06:46:38 -04:00
Jonas Bernoulli
f47e3333b5 emacs: avoid unnecessary let-bindings
To some extend this is a personal preference, but the preference is
strongly dependent on whether one is used to a language that makes it
necessary to use variables like this.

This makes it perfectly clear that we are first getting and then using
a "foo":

  (use-foo (get-foo))

Sure this has to be read "inside out", but that's something one better
gets used to quickly when dealing with lisp.  I don't understand why
one would want to write this instead:

  (let ((the-foo (get-foo)))
    (use-foo the-foo))

Both `get-foo' and `use-foo' are named in a way that make it very
clear that we are dealing with a "foo".  Storing the value in an
additional variable `the-foo' does not make this any more clear.

On the contrary I makes the reader wonder why the author choose to
use a variable.  Is the value used more than once?  Is the value
being retrieved in one context and then used in another (e.g. when
the current buffer changes)?
2021-01-15 06:45:30 -04:00
Jonas Bernoulli
25a8873c68 emacs: reorder notmuch.el a bit 2021-01-15 06:45:20 -04:00
Jonas Bernoulli
c6ac1121d4 emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string
No longer use the function `notmuch-search-get-query', which does
nothing but return the value of that variable.  That function was
added in [1: f47eeac0] for use in `notmuch-read-query' along-side
related `notmuch-show-get-query' and `notmuch-tree-get-query' but
using it here makes little sense.

1: f47eeac0b0
   emacs: set default in notmuch-read-query
2021-01-15 06:45:09 -04:00
Jonas Bernoulli
42d32713be emacs: define a few variables as automatically buffer-local
Define these variables as automatically buffer-local, meaning that
they always become buffer-local when set unless explicitly told
otherwise using `setq-default' or when using the Custom interface.

Previously they were declared, which keeps the byte-compiler quiet but
is not actually the same as being defined.  `notmuch-search-mode' then
made them buffer-local in the current buffer and then set the local
values.  This works but is not kosher.

The definitions of the three non-option variables have to be moved up
a bit to enable the change in the next commit, which see.
2021-01-15 06:44:01 -04:00
Jonas Bernoulli
b614ea7563 emacs: remove variable notmuch-search-disjunctive-regexp
The value is the only possible value, it is only used in one
place, and using a global variable serves no purpose but to
make things more complicated.
2021-01-15 06:43:13 -04:00
Jonas Bernoulli
692acdf9da emacs: various doc-string improvements 2021-01-15 06:40:58 -04:00
Jonas Bernoulli
65fc5ea758 emacs: various comment improvements 2021-01-15 06:38:43 -04:00
Jonas Bernoulli
16b2db0986 emacs: various cosmetic improvements 2021-01-15 06:38:00 -04:00
Jonas Bernoulli
1bbbde4a0c emacs: notmuch-crypto-status-button-type: fix potential bug
The "help-echo" can potentially contain an unintended %-spec
so we have to make sure it would not be treated as such.
2021-01-13 07:23:11 -04:00