Commit graph

237 commits

Author SHA1 Message Date
Mark Walters
a673d618d1 emacs: show: use orig-tags for tag display
This uses the previous patch to show the tag changes that have occured
in the show buffer since it was last loaded/refreshed.
2014-03-24 19:48:22 -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
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
Jani Nikula
ec13bd12e3 emacs: use the originating buffer's working directory for pipe
Currently notmuch-show-pipe-message runs the command in the working
directory of the *notmuch-pipe* buffer if it exists, and the current
buffer's working directory (which is inherited to the new
*notmuch-pipe* buffer) otherwise. This is all very surprising to the
user, and it's difficult to know or change where the command will be
run.

Always use the current show buffer's working directory for piping. The
user can check that with M-x pwd and change it with M-x cd. This is
consistent with notmuch-show-pipe-part.
2014-03-04 20:00:50 -04:00
Jed Brown
718d58ade0 emacs: update alist for mail-archive.com API change
Searching by Message-Id no longer works via the old mail-archive.com
API, though I have contacted them in hopes that they restore it to
prevent dead links.  Anyway, the new API is cleaner.

Acked-by: Austin Clements <amdragon@MIT.EDU>
2014-02-16 18:55:24 -04:00
Mark Walters
6d6006bea9 emacs: add '?' to some prefix keymaps to describe its bindings
Added function notmuch-subkeymap-help to describe keybindings of a
subkeymap (eg after . or c in notmuch-search and notmuch-show).
2013-12-10 03:52:54 +08:00
Mark Walters
9c25d4bbf0 emacs: show: stop stderr appearing in buffer
In emacs 24.3+ the stdout/stderr from externally displaying an
attachment gets inserted into the show buffer. This is caused by
changes in mm-display-external in mm-decode.el.

Ideally, we would put this output in the notmuch errors buffer but the
handler is called asynchronously so we don't know when the output will
appear. Thus if we put it straight into the errors buffer it could get
interleaved with other errors. Also we can't easily tell when we
have got all the error output so can't wait until the process is complete.

One solution would be to create a new buffer for the stderr of each
attachment viewed. Again, since we can't tell when the process has
finished, we can't close these buffers automatically so this will
leave lots of buffers around.

Thus we add a debug variable notmuch-show-attachment-debug: it this is
non-nil we create a new buffer for each viewer; if this variable is
nil we just use a temp buffer which means all error output is
discarded (this is the same behaviour as with emacs pre 24.3).
2013-11-20 18:14:35 -04:00
Mark Walters
3cf926463e emacs: move the show entry to tree into show.el
Move the keybinding and show specific helper from tree.el to show.el
2013-11-07 08:01:22 -04:00
Austin Clements
a7964c86d1 emacs: Sanitize authors and subjects in search and show
Authors and subjects can contain embedded, encoded control characters
like "\n" and "\t" that mess up display.  Transform control characters
into spaces everywhere we display them in search and show.
2013-10-27 09:31:29 -03:00
Austin Clements
47792533b3 emacs: Use interactive specifications for tag changes in show
This modifies all tagging operations in show to call
`notmuch-read-tag-changes' in their interactive specification to input
tag changes, rather than depending on lower-level functions to prompt
for tag changes regardless of their calling context.

Besides being more Elispy and providing a more consistent programmatic
API, this enables callers to provide two call site-specific pieces of
information: an appropriate prompt, and the set of visible tags.  The
prompt lets us differentiate * from +/-.  Providing visible tags
enables a more consistent user experience than retrieving the
(potentially different) tags from the database, and avoids a
round-trip to the CLI and database.
2013-10-25 21:26:13 -03:00
Mark Walters
99d474c484 emacs: show: use interactive instead of current-prefix-arg
Currently notmuch-show looks at the prefix-arg directly via
current-prefix-arg. This changes it to use the interactive
specification.

One test (for elide-toggle functionality) set the prefix arg
directly. Update this test to set the new argument directly.
2013-10-19 22:42:49 -03:00
Austin Clements
c1221dd65a emacs: Improve interactive use documentation
This improves the function documentation for many interactive
commands, either by improving their documentation string where the
improvement also makes sense for programmatic use or by adding a
'notmuch-doc property where it doesn't.

For nearly all commands that support a prefix argument, this adds a
'notmuch-prefix-doc property to document their prefixed behavior This
omits prefix documentation for a few commands where I thought the
prefixed behavior was too obscure (or too complex to fit in one line).
2013-10-07 20:32:08 -03:00
Austin Clements
adfff87a71 emacs: Clean up a few documentation strings
Correct some grammatical errors, fix some violations of standard
documentation string formatting conventions, and be more precise.
2013-10-07 20:31:40 -03:00
Austin Clements
fd656d7683 emacs: Move ?, q, s, m, =, and G to the common keymap
The only user-visible effect of this should be that "G" now works in
show mode (previously it was unbound for no apparent reason).

This shared keymap gives us one place to put global commands, which
both forces us to think about what commands should be global, and
ensures their bindings can't diverge (like the missing "G" in show).
2013-09-10 08:07:38 -03:00
Austin Clements
c52fee6bcb emacs: Define a common shared keymap for all of notmuch
This defines a single, currently empty keymap that all other notmuch
mode maps inherit from.
2013-09-10 08:07:28 -03:00
Austin Clements
21474f0e09 emacs: Add unified refresh-this-buffer function
This unifies the various refresh and poll-and-refresh functions we
have for different modes.  Now all modes bind "=" and "G" (except
show, which doesn't bind "G" for some reason) to
`notmuch-refresh-this-buffer' and
`notmuch-poll-and-refresh-this-buffer', respectively.
2013-09-10 08:07:06 -03:00
Istvan Marko
654260420d emacs: add buttons for all multipart/related parts
When text/html parts include images as multipart/related and the
text/plain alternative is used these images can be completely hidden
with no easy way to access them or even find out that they are there.

Make notmuch-show-insert-part-multipart/related add buttons for all
parts, the first one visible the rest hidden.
2013-09-10 08:05:31 -03:00
Mark Walters
ee8305b519 emacs: show: lazy part handling bugfix
The lazy part handler had a bug that it allowed the button to be
toggled to be specified. During toggling it needs to save and restore
the text-properties for the button but it actually saved the text
properties at point rather than from the button.

In almost all cases this didn't matter as as point had the same text
properties as the button. However, it is a bug and did cause incorrect
behaviour in some cases: see id:87txhz14z6.fsf@qmul.ac.uk for details.
2013-09-10 08:05:05 -03:00
Jani Nikula
5c19eb46a9 emacs: insert quotable parts in reply as they are displayed in show view
In reply, insert quotable parts using notmuch-show-insert-bodypart
instead of calling notmuch-mm-display-part-inline directly to render
the quoted parts as they are rendered in show view.

We use a temp buffer to not leak text properties from the show
renderer into the reply. This way we also don't need to worry about
narrowing or point placement. Credits to Mark Walters
<markwalters1009@gmail.com> and Austin Clements <amdragon@MIT.EDU> for
getting this part straight.

The notable change is that replies to text/calendar parts quote the
pretty printed output of icalendar-import-buffer rather than the ugly
raw vcalendar.
2013-09-05 06:38:24 -03:00
Tomi Ollila
3e60e0b3e9 emacs: removed 3 duplicate functions from notmuch-show.el
notmuch-show.el and notmuch.el had 3 duplicate, identical functions:
notmuch-foreach-mime-part, notmuch-count-attachments and
notmuch-save-attachments. Now these functions in notmuch-show.el
are replaced with declare-functions pointing to "notmuch"(.el).
2013-08-27 07:53:28 -03:00
Mark Walters
15f5fc513d emacs: bugfix attachment content-type as mime-type handling
Notmuch puts attachments in as declared content-type except when the
content-type is application/octet-stream it tries to guess the type
from the filename/extension. This means that viewing a pdf (for
example) which is sent as application/octet-strem invokes the pdf
viewer rather than just offering to save the part.

Recent changes to the attachment handling (commit 1546387d) changed
(broke) this. This patch stores the calculated mime-type with the part
and changes the attachment part handlers can use it instead.
2013-07-31 17:46:09 -03:00
Tomi Ollila
2bd374c91e emacs: dropped rest of now-unused JSON functionality
Notmuch cli provides all structured data previously provided
in json format now in s-expression format, rendering all current
json functionality obsolete.
2013-07-20 09:13:48 -03:00
Austin Clements
eb7d096edc emacs: Remove v command
This removes the v command, since we now have much nicer part commands,
and deprecates the underlying notmuch-show-view-all-mime-parts.  This
also means that people who try using the old unprefixed 'v' command on
a part button will no longer be greeted by ALL of their parts popping
up.
2013-06-24 22:52:10 -07:00
Mark Walters
7bc404f0a4 emacs: show: change emacs interactive pipe message.
Previously the query string for piping a message to a command was
"Pipe message to command: " regardless of whether the function was
called with a prefix argument (which pipes all open messages to the
command). This patch modifies the `interactive' command to reflect
this.
2013-06-24 22:49:33 -07:00
Mark Walters
d0bd88f06d emacs: show: implement lazy hidden part handling
This adds the actual code to do the lazy insertion of hidden parts.

We use a memory inefficient but simple method: when we come to insert
the part if it is hidden we just store all of the arguments to the
part insertion function as a button property. This means when we want
to show the part we can just resume where we left off.

One thing is that we can't tell if a lazy part will produce text until
we try to render it so when unhiding a part we check to see if it
rendered; if not we invoke the default part handler (e.g. an external
viewer).

Also, we would like to insert the lazy part at the start of the line
after the part button. But if this line has some text properties
(e.g. the colours for a following message header) then the lazy part
gets these properties. Thus we start at the end of the part button
line, insert a newline, insert the lazy part, and then delete the
extra newline at the end of the part.
2013-06-13 00:07:19 +09:00
Mark Walters
055f7621d6 emacs: show move addition of :notmuch-part to separate function
This separates out the adding of the :notmuch-part text property to a
separate function to simplify calling from the lazy part insertion
code.
2013-06-13 00:07:07 +09:00
Mark Walters
490b02345e emacs: show: modify the way hidden state is recorded.
Previously, whether a part was hidden or shown was recorded in the
invisibility/visibility of the part overlay. Since we are going to
have lazily rendered parts with no overlay store the hidden/shown
state in the part button itself.

Additionally, in preparation for the invisible part handling move the
actual hiding of the hidden parts to insert-bodypart from
create-part-overlays.

Finally, we will need to know whether a part-insertion has done
anything (it won't if the invisible part cannot be displayed by emacs)
so we slightly rejig the code order in
notmuch-show-toggle-part-invisibility to make it easier for the
function to set an appropriate return value.
2013-06-13 00:06:59 +09:00
Mark Walters
81c199c962 emacs: show: pass button to create-overlays
Now that the bodypart code has the button we can pass that to
create-overlays and simplify that.
2013-06-13 00:06:51 +09:00
Mark Walters
702210b84d emacs: show: move the insertion of the header button to the top level
Previously each of the part insertion handlers inserted the part
button themselves. Move this up into
notmuch-show-insert-bodypart. Since a small number of the handlers
modify the button (the encryption/signature ones) we need to pass the
header button as an argument into the individual part insertion
handlers. However, the declared-type argument was only used for the
text for the part buttons we can now omit it.

The patch is large but mostly simple. The only things of note are that
we let the text/plain handler applies notmuch-wash to the whole part
including the part button. In particular, notmuch-wash removes leading
blank lines from a text/plain part, but since the button is counted as
part of the part this does not happen with text/plain buttons that
have a button. This is probably a bug in notmuch-wash but changing it
does make several tests fail (that rely on this blank line) so, for
the moment, keep the old behaviour.
2013-06-13 00:05:59 +09:00
Mark Walters
27768309ce emacs: show: fake wash parts are handled at insert-bodypart level
Earlier patches have moved the handling of wash fake inline patch
parts to insert-bodypart so we can drop the function
notmuch-show-insert-part-inline-patch-fake-part
2013-06-13 00:05:40 +09:00
Austin Clements
109a0355d6 emacs: Fix applying stickiness to the :notmuch-part property
Previously, we simply called pushnew to add :notmuch-part to the
front-sticky and rear-nonsticky text property lists.  This works if
these are nil or lists, but they can also have the value t, meaning
that all properties are front-sticky/rear-nonsticky.  In this case,
pushnew will signal an error because t is not a list.  We never set
these properties to t ourselves, but since we apply these property
changes over arbitrary renderer output, we have to deal with this
possibility.
2013-06-04 08:39:42 -03:00
David Bremner
915a707ae4 emacs: add `notmuch-archive-tags' cross references in docstrings
Several function docstrings refer to behaviour in docstrings that is
really controlled by notmuch-archive-tags. Add cross references, and
replace hardcoding.
2013-06-02 20:43:14 -03:00
David Bremner
487359e9cc emacs: remove hardcoded defaults values from docstrings
These functions refer to default values of variables, but it seems
less confusing and less likely to get out of date to just allow the
user to follow the help cross-reference links.
2013-06-02 20:43:02 -03:00
David Bremner
63782f4023 emacs: replace setq + let with let*
I found several places where a setq is immediately followed by a let
or a let*. This seems to be the pessimal combination, with the
implicit scope of the setq combined with the extra indentation of the let.
I combined these cases into a single let* which I think is easier to read.
2013-06-02 20:38:17 -03:00
David Bremner
9de0639126 emacs: replace (funcall 'foo ...) with (foo ...)
I can't see any benefit to the funcall, and it looks like the result
of cut-and-paste from some code that actually used a variable for the
function to call.
2013-06-02 11:37:22 -03:00
Austin Clements
edc740857f emacs: Bind MIME part commands to "." submap
Since the part commands are no longer tied to a button, but can be
applied with point anywhere within a part, bind the part commands
keymap to "." everywhere in the show buffer.  This lets you save or
view parts without having to navigate to the part button, and is
particularly useful for parts that have no button.

This removes the un-prefixed MIME part commands from the part button
keymap, but that's okay because those clashed in annoying ways with
show buffer bindings like "s" for search.  RET on part buttons is
unaffected, which is the most important part button binding.
2013-05-31 22:01:12 -03:00
Austin Clements
1546387d72 emacs: Simplify MIME part command implementation
This unifies the part button actions and the underlying part action
functions into single interactive command that simply applies to the
part containing point using the just-added part p-list text property
instead of button properties.  Since all part actions can be performed
by applying the appropriate mm function to an mm-handle, this patch
abstracts out the creation of mm handles, making the implementations
of the part commands trivial.  This also eliminates our special
handling for part save in favor of using the appropriate mm function.

This necessarily modifies the way we handle the default part button
action, but in a way that does not change the meaning of the
notmuch-show-part-button-default-action defcustom.

Since these commands are no longer specific to buttons, this patch
eliminates the extra metadata stored with each button.  This also
eliminates one rather special-purpose macro for a collection of
general purpose part handling utilities.
2013-05-31 22:01:02 -03:00
Austin Clements
04725cfbe5 emacs: Record part p-list in a text property
This is similar to what we already do with the message p-list, though
we apply the part's text property to the whole part's text, in
contrast with the message p-list, which is (rather obscurely) only
applied to the first character.
2013-05-31 22:00:52 -03:00
Austin Clements
6bbb91f8b6 emacs: Retain text properties when toggling buttons
Previously, we lost any text properties applied to part buttons or
wash buttons when they were toggled because `insert' directly copies
the text properties of the string being inserted.  Fix this by
capturing the properties applied to the button beforehand and
re-applying them after inserting the new text.
2013-05-31 22:00:44 -03:00
Jani Nikula
8a164516ee emacs: add show view bindings to move to previous/next thread
We have most of the plumbing in place, add the bindings M-n and M-p.
2013-05-26 18:48:31 -03:00
Austin Clements
d4940d4716 emacs: Don't override mm-show-part in notmuch-show-view-part
Previously, notmuch-show-view-part overrode the function binding of
mm-show-part to redirect it to notmuch-show-save-part to get notmuch's
default file name handling in case mm-display-part decided to fall
back to saving the part.  In addition to being messy, this depended on
the now-deprecated dynamic binding behavior of flet.

This patch removes the mm-show-part override in favor of passing the
file name in to mm-show-part the way it expects, so we get its default
file name handling.  It's not clear why we didn't do this before;
mm-show-part has supported default file names since at least Emacs
23.1.
2013-05-26 18:45:10 -03:00
Mark Walters
c8589e4eb8 emacs: show: handle inline patch fake parts at top level
The inline patch fake part handler also modifies the content-type so
handle this in notmuch-show-insert-bodypart too.
2013-05-20 15:01:59 -03:00
Mark Walters
b681aa8235 emacs:show: separate out handling of application/octet-stream
Currently mime parts are basically handled based on their mime-type
with the exception of application/octet-stream parts. Deal with these
parts at the top level (notmuch-show-insert-bodypart).

This is needed later in the series as we need to put in a part button
for each part (which means knowing its mime type) while deferring the
actual insertion of the part.
2013-05-20 15:01:48 -03:00
Jani Nikula
c75dff3c1a emacs: add kernel.org mail archive redirector
See http://lkml.kernel.org/
2013-05-05 13:56:52 -03:00
Tomi Ollila
8bee3c417c emacs: fixed (declare-function ...) definitions
Some (declare-function ...) definitions were drifted away from the
actual (defun ...)'s. To find the drifts and to verify changes
the following command line was used:

$ emacs --batch -L emacs --eval '(check-declare-directory "emacs")'
2013-04-30 06:13:18 -03:00
Damien Cassou
b714a808a6 emacs: possibility to customize the rendering of tags
This patch extracts the rendering of tags in notmuch-show to
the notmuch-tag file.

This file introduces a `notmuch-tag-formats' variable that associates
each tag to a particular format. This variable can be customized
thanks to the work of Austin Clements. For example,

  '(("unread" (propertize tag 'face '(:foreground "red")))
    ("flagged" (notmuch-tag-format-image tag "star.svg")))

associates a red foreground to the "unread" tag and a star picture to
the "flagged" tag.

Signed-off-by: Damien Cassou <damien.cassou@gmail.com>
2013-03-25 11:38:49 -04:00
Mark Walters
3901bbca2e emacs: show: make buttons select window
Emacs has two button type objects: widgets (as used for saved searches
in notmuch-hello) and buttons as used by parts/citations and id links
in notmuch-show. These two behave subtly differently when clicked with
the mouse: widgets select the window clicked before running the
action, buttons do not.

This patch makes all of these behave the same: clicking always selects
the clicked window. It does this by defining a notmuch-button-type
supertype that the other notmuch buttons can inherit from. This
supertype binds the mouse-action to select the window and then
activate the button.
2013-02-18 20:13:19 -04:00
Mark Walters
f1a355febf emacs: show: w3m/invisibility workaround
There is a bug in the current notmuch code with w3m and invisible
parts. w3m sets a keymap, and if we have a hidden [text/html] point
at the start of the following line still gets this w3m keymap which
causes some strange effects. For example, RET gives an error "No URL
at Point" rather than hiding the message, <down> goes to the next link
rather than just down a line.

These keybinding are also inconvenient when the text/html part is
displayed so we ask w3m not to install a keymap.

This is only likely to be a problem for emacs 23 as shr is preferred
as html renderer on emacs 24 (although the user can set the renderer
to w3m even on emacs 24).

This solution was suggested by Tomi Ollila <tomi.ollila@iki.fi>
2013-01-14 19:46:13 -04:00
Mark Walters
4af1ac604e emacs: show: set default show-all-multipart/alternatives to nil
Now that the invisibility display of parts is present we no longer
need to force the display of all multipart/alternatives: users can
toggle them for themselves when needed.
2012-12-21 10:03:06 -04:00
Mark Walters
a5b5404976 emacs: show: add invisibility button action
This adds a button action to show hidden parts. In this version "RET"
toggles the visibility of any part which puts content in the buffer
(as opposed to attachments such as application/pdf).

The button is used to hide parts when appropriate (eg text/html in
multipart/alternative).
2012-12-21 10:02:57 -04:00