Commit graph

57 commits

Author SHA1 Message Date
David Bremner
fc1c81c378 emacs: update quoting in docstrings
The complicated looking escapes are needed to avoid compile time
warnings.  (info "(elisp) Text Quoting Style") for details.
2023-10-06 20:36:56 -03:00
David Bremner
cc2c3a383d emacs: add notmuch-tag-undo
Keybindings are deferred to a future commit.
2022-02-26 07:58:14 -04:00
David Bremner
9b2a548189 emacs/tag: keep tag history
This buffer local list will be used to provide an undo facility for
tagging operations. Keeping history can be disabled with the new
OMIT-HIST option.
2022-02-26 07:57:58 -04:00
David Bremner
d298af9e9d emacs: remove non-batch code path from function notmuch-tag
It is no slower (according to T06-emacs) to use batch for everything,
and it simplifies the code.
2022-02-25 08:39:05 -04:00
LdBeth
c7c422ded2 emacs/notmuch-tag.el: add xmlns attribute to svg icons
emacs-mac that compiled with OS X system API for image display
support cannot correctly render svg without xmlns parameter [1].

[1]: id:tencent_127AA231767438AC66FEE4DDB4BBF51DF909@qq.com
2022-01-14 17:12:41 -04:00
David Bremner
20b2150406 emacs: don't add space to tag completion candidates.
Apparently this messes up various third party completion
frameworks. This change does mean that users will have to hit space
after completing a tag change in order to enter another change.

As a bonus, remove the call to #'delete, since
completing-read-multiple already promises to remove empty strings.
2021-12-04 12:56:43 -04:00
David Bremner
e722b4f48c emacs: wrap call-process
Provide safe working directory
2021-09-11 11:11:29 -03:00
Jonas Bernoulli
27c8e377e4 emacs: use closures instead of backquoted lambdas 2021-08-29 17:42:32 -07:00
Kyle Meyer
319dcfb50e emacs: restore tag-changes and query bindings for tag hooks
notmuch-before-tag-hook and notmuch-after-tag-hook are supposed to
have access to two dynamic variables, tag-changes and query, but these
were lost with the switch to lexical binding in fc4cda07 (emacs: use
lexical-bindings in all libraries, 2021-01-13).

Add a variant of Emacs's dlet (not available until Emacs 28) and use
it in notmuch-tag to expose tag-changes and query to the hooks.
2021-05-15 08:34:28 -03:00
Jonas Bernoulli
371f481d93 emacs: use string-empty-p 2021-01-15 06:47:28 -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
692acdf9da emacs: various doc-string improvements 2021-01-15 06:40:58 -04:00
Jonas Bernoulli
16b2db0986 emacs: various cosmetic improvements 2021-01-15 06:38:00 -04:00
Jonas Bernoulli
9be8c6802f emacs: notmuch-tag--get-formats: silence byte-compiler
`format-alist' is a global variable and the byte-compiler is unhappy
when a lexical function argument shadows a global (dynamic) binding.
2021-01-13 07:16:38 -04:00
Jonas Bernoulli
fc4cda07a9 emacs: use lexical-bindings in all libraries
Doing so causes many new compile warnings.  Some of these warnings
concern genuine changes in behavior that have to be addressed right
away.

Many other warnings are due to unused variables.  Nothing has changed
here, except that the byte-compiler can now detect these pre-existing
and harmless issues.  We delay addressing these issues so that we can
focus on the important ones here.

A third group of warnings concern arguments that are not actually used
inside the function but which cannot be removed because the functions
signature is dictated by some outside convention.  Silencing these
warning is also delayed until subsequent commits.
2021-01-13 07:16:04 -04:00
Jonas Bernoulli
2ca941163d 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-13 07:10:27 -04:00
Jonas Bernoulli
54492ddf23 emacs: do not quote self-quoting t 2020-12-06 16:23:11 -04:00
Jonas Bernoulli
d6cacef832 emacs: always use elisp quoting style in doc-strings
Emacs doc-strings use neither markdown nor lisp symbol quoting.
2020-12-06 16:20:16 -04:00
Jonas Bernoulli
a1b757c1ca emacs: Add end-of-file line to libraries that lack it 2020-08-09 21:14:36 -03:00
Jonas Bernoulli
df3fab18fe emacs: Increase consistency of library headers 2020-08-09 21:14:36 -03:00
Jonas Bernoulli
73cc4105aa emacs: Autoload notmuch-jump using an autoload cookie
Doing that is better than using an `autoload' form because the latter
may result in dependencies getting hidden and indeed it turns out we
have to declare `notmuch-jump' in "notmuch-tag.el".
2020-08-09 21:14:36 -03:00
Jonas Bernoulli
82390b2807 emacs: Fix some function declarations 2020-08-09 20:57:51 -03:00
Jonas Bernoulli
99b6e780c8 emacs: Use one or three lines for 'if' forms
Putting the COND and THEN parts on the same line but ELSE on a
separate line makes it harder to determine if there actually is
an ELSE part.
2020-08-09 20:53:30 -03:00
Jonas Bernoulli
09f6533c37 emacs: Use 'unless' instead of 'when' and 'not'
Also use 'unless' in a few cases where previously 'if' was used with
'not' but without an ELSE part.
2020-08-09 20:51:26 -03:00
Jonas Bernoulli
caaa108760 emacs: Fix indentation 2020-08-09 20:48:09 -03:00
Jonas Bernoulli
6fb7d35069 emacs: Remove excess empty lines
Most people who write lots of lisp tend to only sparsely use empty
"separator" lines within forms.  In lisp they feel unnecessary and
since most files stick to this convention we get a bit confused
when there are extra empty lines.  It feels like the s-expressions
are falling into pieces.

All of this is especially true between a function's doc-string and
body because the doc-string is colored differently, which visually
already separates it quite sufficiently from the code that follows.
2020-08-09 20:47:52 -03:00
Jonas Bernoulli
a4617f29ce emacs: Shorten long lines 2020-08-09 19:48:36 -03:00
Tomi Ollila
ed40579ad3 emacs docstrings: consistent indentation, newlines, periods
Fixed emacs docstrings to be consistent. No functional change.

- removed some (accidental) indentation
- removed some trailing newlines
- added trailing periods where missing (some exclusions)
2020-06-06 07:55:58 -03:00
Jonas Bernoulli
11ac932a45 emacs: Use cl-lib' instead of deprecated cl'
Starting with Emacs 27 the old `cl' implementation is finally
considered obsolete.  Previously its use was strongly discouraged
at run-time but one was still allowed to use it at compile-time.

For the most part the transition is very simple and boils down to
adding the "cl-" prefix to some symbols.  A few replacements do not
follow that simple pattern; e.g. `first' is replaced with `car',
even though the alias `cl-first' exists, because the latter is not
idiomatic emacs-lisp.

In a few cases we start using `pcase-let' or `pcase-lambda' instead
of renaming e.g. `first' to `car'.  That way we can remind the reader
of the meaning of the various parts of the data that is being
deconstructed.

An obsolete `lexical-let' and a `lexical-let*' are replaced with their
regular variants `let' and `let*' even though we do not at the same
time enable `lexical-binding' for that file.  That is the right thing
to do because it does not actually make a difference in those cases
whether lexical bindings are used or not, and because this should be
enabled in a separate commit.

We need to explicitly depend on the `cl-lib' package because Emacs
24.1 and 24.2 lack that library.  When using these releases we end
up using the backport from GNU Elpa.

We need to explicitly require the `pcase' library because
`pcase-dolist' was not autoloaded until Emacs 25.1.
2020-04-27 07:36:10 -03:00
Vladimir Panteleev
d7a49e8199 notmuch-tag.el: Fix minor grammar error 2017-08-23 08:08:01 -03:00
Matt Armstrong
d62f9dbfc0 emacs: make faces readable on dark backgrounds.
The notmuch-tag-flagged, notmuch-search-flagged-face and
notmuch-crypto-part-header faces defaulted to "blue", which is nearly
unreadable when a dark background is in use.  This is addressed by using
"LightBlue1" for dark backgrounds.

As a side effect, these faces are now no-op definitions for grayscale or
mono displays.
2016-11-02 07:40:20 -03:00
Mark Walters
190a30b263 emacs: tag-jump: docstring fix
In commit 297d091e1c the key for
switching to the reverse keymap was changed from r to k but the
docstring for the defcustom was not updated. This changeset updates
the documentation to match.
2016-10-15 21:49:48 -03:00
Mark Walters
297d091e1c emacs: tag-jump: make k binding for the reverse tag change map
Currently, by default k invokes the tag-jump menu, and following it by
r invokes the reverse tag change jump menu. This is awkward to type
(e.g. k r u for undoing a -unread change). This changes it so that k
followed by k invokes the reverse menu. We make the key for the
reverse map a variable as that makes it possible for a user to
change it by editing their .emacs file.
2016-10-07 22:35:42 -03:00
Mark Walters
ae06fbfc76 emacs: add a tag jump menu
Add a customisable "jump" style menu for doing tagging operations.
2016-10-04 07:55:16 -03:00
Mark Walters
51d27e0855 emacs: tag deleted face bugfix
Commit d25d33ff cleaned up some of the tag face code. However, for the
face notmuch-tag-deleted it used the test

((class color) (supports :strike-through))

to decide whether to use red strikethrough or inverse-video (emacs in
a terminal typically doesn't support red strikethrough, but in X it does).

However, it seems that test often returns true even though red
strikethrough is not supported. This breaks the tag update code -- the
wrong thing is displayed to the user.

Thus we make the test explicitly more specific, changing the test to

((class color) (supports :strike-through "red"))
2016-09-25 07:42:01 -03:00
Matt Armstrong
d25d33ff2d emacs: make the remaining faces configurable.
I believe this moves all "anonymous" face specifications in notmuch
code into a configurable defface.
2016-09-12 08:12:10 -03:00
Daniel Kahn Gillmor
6a833a6e83 Use https instead of http where possible
Many of the external links found in the notmuch source can be resolved
using https instead of http.  This changeset addresses as many as i
could find, without touching the e-mail corpus or expected outputs
found in tests.
2016-06-05 08:32:17 -03:00
Chunyang Xu
0cf457b73b emacs: Fix packaging
Refer to (info "(elisp) Library Headers") for package conventions.
2016-04-16 08:24:42 -03:00
Daniel Schoepe
3b348ab1e1 Fix documentation for notmuch--tag-hook functions
The second argument to notmuch-tag is now called tag-changes, but the
documentation for notmuch-before-tag-hook and notmuch-after-tag-hook
still used the old argument name `tags'. This resulted in broken hooks
when following the documentation.
2015-06-30 21:37:25 +02:00
Mark Walters
83f531ad7e emacs: make sure tagging on an empty query is harmless
Currently notmuch-tag throws a "wrong-type-argument stringp nil" if
passed a nil query-string. Catch this and provide a more useful error
message. This fixes a case in notmuch-tree (if you try to tag when at
the end of the buffer).

Secondly, as pointed out by David (dme)
`notmuch-search-find-stable-query-region' can return the query string
() if there are no messages in the region. This gets passed to notmuch
tag, and due to interactions in the optimize_query code in
notmuch-tag.c becomes, in the case tag-change is -inbox, "( () ) and
(tag:inbox)". This query matches some strange collection of messages
which then get archived. This should probably be fixed, but in any
case make `notmuch-search-find-stable-query-region' return a nil
query-string in this case.

This avoids data-loss (random tag removal) in this case.
2014-05-27 20:40:04 -03:00
Mark Walters
941e172724 emacs: show: mark tags changed since buffer loaded
This allows (and requires) the original-tags to be passed along with
the current-tags to be passed to notmuch-tag-format-tags. This allows
the tag formatting to show added and deleted tags.By default a removed
tag is displayed with strike-through in red (if strike-through is not
available, eg on a terminal, inverse video is used instead) and an
added tag is displayed underlined in green.

If the caller does not wish to use the new feature it can pass
current-tags for both arguments and, at this point, we do exactly that
in the three callers of this function.

Note, we cannot tidily allow original-tags to be optional because we would
need to distinguish nil meaning "we are not specifying original-tags"
from nil meaning there were no original-tags (an empty list).

We use this in subsequent patches to make it clear when a message was
unread when you first loaded a show buffer (previously the unread tag
could be removed before a user realised that it had been unread).

The code adds into the existing tag formatting code. The user can
specify exactly how a tag should be displayed normally, when deleted,
or when added.

Since the formatting code matches regexps a user can match all deleted
tags with a ".*" in notmuch-tag-deleted-formats.  For example setting
notmuch-tag-deleted-formats to '((".*" nil)) tells notmuch not to show
deleted tags at all.

All the variables are customizable; however, more complicated cases
like changing the face depending on the type of display will require
custom lisp.

Currently this overrides notmuch-tag-deleted-formats for the tests
setting it to '((".*" nil)) so that they get removed from the display
and, thus, all tests still pass.
2014-03-24 19:48:04 -03:00
Mark Walters
d5acfdda5f emacs: tag: add customize for deleted/added tag formats
Add customize options for deleted/added tag formats.  These are not
used yet but will be later in the series.

We switch to using `notmuch-apply-face' rather than `propertize' in
the defcustom for faces so that the faces for deleted/added tags add
to the default face attributes for the tag.

We special case deleting the unread tag as that tag is a strong visual
cue and we don't need that cue when we are just saying it used to be
unread. Thus, we revert to the normal tag face with strikethough for
deleted unread tags.
2014-03-24 19:47:49 -03:00
Mark Walters
b9a777e0a3 emacs: tag split customise option for format-tags into a widget
We will re-use the customize option for format-tags for formattting
deleted tags to added tags in the next patch so split it into a
widget. There should be no functional change.
2014-03-24 19:47:35 -03:00
Austin Clements
7023466ece 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-24 19:43:00 -03:00
Austin Clements
dfab8e5e49 emacs: Combine notmuch-combine-face-text-property{, -string}
This combines our two face combining functions into one, easy to use
function with a much shorter name: `notmuch-apply-face'.  This
function takes the full set of arguments that
`notmuch-combine-face-text-property' took, but takes them in a more
convenient order and provides smarter defaults that make the function
easy to use on both strings and buffers.
2014-03-24 19:42:33 -03:00
Mark Walters
17e44cd584 emacs: tree: use tag-format-tags
Previously tree did not use tag-format-tags: since tree wants to
distinguish matching messages from non-matching messages it is not a
perfect fit.

However, in preparation for allowing tag-changes to be shown (i.e.,
added or deleted tags to be indicated) it is convenient to make all
places displaying tags call the same routines.

We modify notmuch-tag-format-tags slightly so that it can take and
argument for the default characteristics of the face before the
special tag features are applied.

This also means that things like the star symbol for flagged messages
all work in tree.
2014-01-18 14:41:50 -04:00
Austin Clements
730b8f61e0 emacs: Use notmuch tag --batch for large tag queries
(Unfortunately, it's difficult to first demonstrate this problem with
a known-broken test because modern Linux kernels have argument length
limits in the megabytes, which makes Emacs really slow!)
2013-11-08 20:35:13 -04:00
Austin Clements
9f9a63c863 emacs: Add a space after completed tag operations
Previously, when a user fully completed a tag operation, they had to
press space to begin entering another tag operation.  This is
different from, say, shell file name completion, which typically
inserts a space after an unambiguous completion under the assumption
that the user will want to enter more input.

This patch tweaks `notmuch-read-tag-changes' to act more like shell
file name completion: after an unambiguous tag completion, it now
inserts a space, ready and waiting for another tagging operation from
the user.  This is backwards-compatible with old habits, since there's
no harm in putting an extra space.
2013-10-27 17:35:58 -03:00
Austin Clements
45444eebe5 emacs: Remove interactive behavior of `notmuch-tag'
We no longer use this, since we've lifted all interactive behavior to
the appropriate interactive entry points.  Because of this,
`notmuch-tag' also no longer needs to return the tag changes list,
since the caller always passes it in.
2013-10-25 21:31:20 -03:00