aboutsummaryrefslogtreecommitdiff
path: root/emacs/notmuch-lib.el
AgeCommit message (Collapse)Author
2024-04-06emacs: Add new option notmuch-search-hide-excludedMohsin Kaleem
The new notmuch-search-hide-excluded option allows users to configure whether to show or hide excluded messages (as determined by search.exclude_tags in the local notmuch config file). It defaults to true for now to maintain backwards-compatibility with how notmuch-{search,tree} already worked. New commands notmuch-search-toggle-hide-excluded and notmuch-tree-toggle-exclude have also been added. They toggle the value of notmuch-search-hide-excluded for the search in the current search or tree buffer. It's bound to "i" in the respective keymaps for these modes. Lastly I've amended some calls to notmuch-tree and notmuch-unthreaded which didn't pass through the buffer local value of notmuch-search-oldest-first (and now notmuch-search-exclude). Examples of where I've done this include: + notmuch-jump-search + notmuch-tree-from-search-current-query + notmuch-unthreaded-from-search-current-query + notmuch-tree-from-search-thread A new test file for Emacs has been added which covers the usage of the new `notmuch-search-hide-excluded' option and interactively hiding or showing mail with excluded tags. These test cover the basic usage of the `notmuch-search-toggle-hide-excluded' command in notmuch-search, notmuch-tree and notmuch-unthreaded searches. These tests also cover the persistence of the current value of the hide-excluded mail option as a user switches from between these different search commands. [1]: id:87ilxlxsng.fsf@kisara.moe Amended-by: db, fix indentation in T461-emacs-search-exclude.sh
2023-10-06emacs: update quoting in docstringsDavid Bremner
The complicated looking escapes are needed to avoid compile time warnings. (info "(elisp) Text Quoting Style") for details.
2023-10-01emacs: save undisplayer function for MIME partsDavid Bremner
For some kinds of MIME parts (at least images), our trickery with overlays will not work, so save the more drastic function created by Gnus that actually deletes the part from the buffer. In an ideal world we would return this function as (part of) a value, but here the call stack is too complicated for anything that simple, so we stash it in the part plist and rely on that being preserved (unlike the mm handle, which is transient).
2022-07-30emacs/show: provide notmuch-show-choose-duplicateDavid Bremner
This new command allows the user to interactively choose a different duplicate (file) to display for a given message in notmuch-show-mode. Since both tree and unthreaded view use notmuch-show-mode, this provides the same facility there.
2022-07-03emacs: mark notmuch-query.el as obsoleteDavid Bremner
The only functionality actually used by notmuch is the base function notmuch-query-get-threads; the other functions in this file have nothing to do with that (single) use. Move that function into notmuch-lib.el and rename to reflect use. Deprecate the other functions in notmuch-query.el.
2022-05-20emacs: document/defcustom notmuch-multipart/alternative-discouragedDavid Bremner
This variable is important for people who want to change the default behaviour when displaying multipart/alternative messages. Previously it was undocumented. Add a defcustom to help users and copy some documentation from the wiki. The usual machinery of re-using docstrings is a bit tricky to use here because it mangles the example lisp code, and the link to the info node should not be in e.g. the html page. Add a simple test to make sure the switch from defvar to defcustom did not break something obvious.
2022-05-16emacs: factor out calculation of mm-inline-override-typesDavid Bremner
The intended use case of this new function is to make reply behaviour track that of show with respect to attachments. Also fix the glob (which worked by fluke) into the documented regexp.
2022-02-26emacs: redirect undo to notmuch-tag-undoDavid Bremner
The double remap is a bit ugly, but it seems better than adding another layer of keymaps for those modes where notmuch-tag-undo makes sense.
2021-09-11emacs: wrap call-processDavid Bremner
Provide safe working directory
2021-09-11emacs: wrap make-processDavid Bremner
Provide a safe working directory.
2021-09-11emacs: wrap call-process-regionDavid Bremner
As with notmuch--process-lines, initial purpose is to provide a safe binding for default-directory. This is enough to make notmuch-hello robust against non-existent or corrupt values default-directory, but probably not other views.
2021-09-11emacs: wrap process-linesDavid Bremner
Initially just set the working directory, to avoid (the implicit) call-process crashing when the default-directory points to a non-existent location. Use of a macro here is over-engineering for this change, but the same change needs to be applied to several other process creation primitives.
2021-01-15emacs: avoid type errors due to nil as content-typeJonas Bernoulli
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-15emacs: use string-empty-pJonas Bernoulli
2021-01-15emacs: make subr-x available in all librariesJonas Bernoulli
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-15emacs: improve how cl-lib and pcase are requiredJonas Bernoulli
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-15emacs: avoid unnecessary let-bindingsJonas Bernoulli
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-15emacs: define a few variables as automatically buffer-localJonas Bernoulli
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-15emacs: various comment improvementsJonas Bernoulli
2021-01-15emacs: various cosmetic improvementsJonas Bernoulli
2021-01-13emacs: deal with unused lexical arguments and variablesJonas Bernoulli
The previous commit switched to lexical-binding but without dealing with the new warnings about unused lexical arguments and variables. This commit deals with most of them, in most cases by either removing leftover bindings that are actually unnecessary, or by marking certain arguments as "known to be unused" by prefixing their names with "_". In the case of the functions named `notmuch-show-insert-...' the amount of silencing that is required is a bit extreme and we might want to investigate if there is a better way. In the case of `notmuch-mua-mail', ignoring CONTINUE means that we do not fully follow the intended behavior described in `compose-mail's doc-string.
2021-01-13emacs: use lexical-bindings in all librariesJonas Bernoulli
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-13emacs: make headings outline-minor-mode compatibleJonas Bernoulli
`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-13emacs: avoid killing process buffer when process is still aliveJonas Bernoulli
In practice this probably does not make a difference or we would have heard about it many times, but better be safe than sorry. Process sentinels are called not only when the process has finished but also on other state changes.
2021-01-13emacs: avoid passing around some redundant informationJonas Bernoulli
When running "notmuch" we use its full path but when displaying the command to the user we show just its name for readability reasons. Avoid passing around both representations because it is very easy to get the name from the path. Notmuch itself uses the involved functions just for "notmuch" but there might be extensions that use them for other executable so we forgo other potential simplifications.
2021-01-13emacs: notmuch-start-notmuch: avoid storing process buffer twiceJonas Bernoulli
The buffer of the error process is accessible using `process-buffer'. We still have to store the error-buffer in the non-error process because for that process `process-buffer' obviously returns its own buffer.
2021-01-13emacs: notmuch-start-notmuch-sentinel: assert buffer is aliveJonas Bernoulli
2021-01-13emacs: notmuch-start-notmuch-error-sentinel: assert buffer is aliveJonas Bernoulli
2021-01-13emacs: notmuch-start-notmuch: remove backward compatibility codeJonas Bernoulli
We no longer support Emacs releases before version 25.1. Also adjust the sentinels which only had to deal with an error file when using an older Emacs release was used.
2020-12-06emacs: use defvar-localJonas Bernoulli
It is available since Emacs 24.3 and we require at least Emacs 25.
2020-12-06emacs: inline notmuch-split-content-typeJonas Bernoulli
This trivial helper function actually made things slightly *less* readable by adding an unnecessary indirection.
2020-12-06emacs: inline notmuch-documentation-first-lineJonas Bernoulli
Inline a simplified version of `notmuch-documentation-first-line' into its only caller. The new code snippet differs from the removed function in that it returns nil instead of the empty string for symbols that have no function documentation. That value is ultimately used as an argument to `concat', which treats nil like the empty string. So we can do the logical thing without changing the behavior.
2020-12-06emacs: remove unnecessary notmuch-remove-if-notJonas Bernoulli
We could just have switched to using `cl-remove-if-not' instead, but the two uses of the *remove-if-not function are pretty strange to begin with so we refactor to not use any such function at all.
2020-12-06emacs: sanitize function that displays versionJonas Bernoulli
Previously it was defined in "notmuch-hello.el" and its name contained "hello" solely because it replaced an anonymous function that was mistakenly only bound in `notmuch-hello-mode-map'. But it makes more sense to bind it in all notmuch modes and even if we did not change that aspect it still would make no sense to have "hello" in its name.
2020-12-06emacs: more cleanup since dropping support for Emacs 24Jonas Bernoulli
Notmuch requires at least version 25 of Emacs now. Adjust comments that previously referenced version 24 specifically, even though they also apply to later releases. Remove documentation and code that no longer applies. - `mm-shr' no longer references `gnus-inhibit-images'.
2020-08-09emacs: Use new advice mechanism do advice mm-shrJonas Bernoulli
Also because we now only support Emacs >= 25, we can remove the check for Emacs >= 24.
2020-08-09emacs: Use cl-incf where appropriateJonas Bernoulli
It's shorter. That's it pretty much.
2020-08-09Fix typosJonas Bernoulli
2020-08-09emacs: Increase consistency of library headersJonas Bernoulli
2020-08-09emacs: Various cosmetic changesJonas Bernoulli
2020-08-09emacs: Autoload notmuch-jump-search only onceJonas Bernoulli
This function is being autoloaded using an autoload cookie, so it shouldn't additionally be autoloaded using an `autoload' form. When building libraries we don't actually load the autoloads file and dropping the `autoload' form results in an error, which reveals a so far unspecified dependency: `notmuch-tree' needs `notmuch-jump'. Before this commit compiling (or even just loading) `notmuch-tree' resulted in `notmuch-jump' being loaded because the former requires `notmuch-lib', which autoloaded `notmuch-jump-search'. The bug was that this dependency was not explicitly specified, which we fix by adding the respective `require' form.
2020-08-09emacs: notmuch-poll: Let the user know we are pollingJonas Bernoulli
It is done synchronously and it can take a while, so we should let the user know what is going on.
2020-08-09emacs: Use one or three lines for 'if' formsJonas Bernoulli
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-09emacs: Use 'when' instead of 'if' when there is no ELSE partJonas Bernoulli
2020-08-09emacs: Use 'and' instead of 'when' when the return value mattersJonas Bernoulli
Also do so for some 'if' forms that lack an ELSE part. Even go as far as using 'and' and 'not' instead of 'unless'.
2020-08-09emacs: Only set one variable per setq formJonas Bernoulli
It's a bit weird to avoid having to write the "(setq ... )" more than once, just because we can. In a language that uses '=' for the same purpose we also happily use that once per assignment. While there are no benefit to using just one 'setq' there are some drawbacks. It is not always clear on first what is a key and what a value and as a result it is easy to make a mistake. Also it becomes harder to comment out just one assignment.
2020-08-09emacs: Closing parenthesis go on the same lineJonas Bernoulli
2020-08-09emacs: Fix indentationJonas Bernoulli
2020-08-09emacs: Remove excess empty linesJonas Bernoulli
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-09emacs: Shorten long linesJonas Bernoulli