Re: [PATCH] emacs: Use `cl-lib' instead of deprecated `cl'

2020-04-25 Thread Jonas Bernoulli
I have fixed the remaining issues and added two small commits.
See v3.  

> Or of course you can/should get the tests running locally.

The problem was that there are incompatible changes in Emacs 27.
I am using Emacs 26 for the time being but will look into these
breaking changes later.  The first one was easy to work around,
but that just revealed a second one... 

  Jonas
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 1/3] emacs: Use `cl-lib' instead of deprecated `cl'

2020-04-25 Thread Jonas Bernoulli
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.
---
 emacs/notmuch-company.el  |   5 +-
 emacs/notmuch-draft.el|   2 +-
 emacs/notmuch-hello.el| 147 +++---
 emacs/notmuch-jump.el |  45 +
 emacs/notmuch-lib.el  |  18 ++--
 emacs/notmuch-maildir-fcc.el  |  35 +++
 emacs/notmuch-mua.el  |  76 +++
 emacs/notmuch-parser.el   |  18 ++--
 emacs/notmuch-pkg.el.tmpl |   3 +-
 emacs/notmuch-show.el | 103 +++--
 emacs/notmuch-tag.el  |  45 +
 emacs/notmuch-tree.el |  20 ++--
 emacs/notmuch.el  |  62 ++---
 test/T450-emacs-show.sh   |   2 +-
 test/emacs-attachment-warnings.el |   4 +-
 test/test-lib.el  |  18 ++--
 16 files changed, 304 insertions(+), 299 deletions(-)

diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index 3e12e7a9..ac998f9b 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -27,7 +27,8 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl-lib))
+
 (require 'notmuch-lib)
 
 (defvar notmuch-company-last-prefix nil)
@@ -65,7 +66,7 @@ (defun notmuch-company (command  arg  _ignore)
   (require 'company)
   (let ((case-fold-search t)
(completion-ignore-case t))
-(case command
+(cl-case command
   (interactive (company-begin-backend 'notmuch-company))
   (prefix (and (derived-mode-p 'message-mode)
   (looking-back (concat 
notmuch-address-completion-headers-regexp ".*")
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index e22e0d16..504b33be 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -152,7 +152,7 @@ (defun notmuch-draft--query-encryption ()
   "Checks if we should save a message that should be encrypted.
 
 `notmuch-draft-save-plaintext' controls the behaviour."
-  (case notmuch-draft-save-plaintext
+  (cl-case notmuch-draft-save-plaintext
((ask)
 (unless (yes-or-no-p "(Customize `notmuch-draft-save-plaintext' to 
avoid this warning)
 This message contains mml tags that suggest it is intended to be encrypted.
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index ab6ee798..bdf584e6 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -21,7 +21,8 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl-lib))
+
 (require 'widget)
 (require 'wid-edit) ; For `widget-forward'.
 
@@ -47,17 +48,19 @@ (defun notmuch-saved-search-get (saved-search field)
((keywordp (car saved-search))
 (plist-get saved-search field))
;; It is not a plist so it is an old-style entry.
-   ((consp (cdr saved-search)) ;; It is a list (NAME QUERY COUNT-QUERY)
-(case field
-  (:name (first saved-search))
-  (:query (second saved-search))
-  (:count-query (third saved-search))
-  (t nil)))
-   (t  ;; It is a cons-cell (NAME . QUERY)
-(case field
-  (:name (car saved-search))
-  (:query (cdr saved-search))
-  (t nil)
+   ((consp (cdr saved-search))
+(pcase-let ((`(,name ,query ,count-query) saved-search))
+  (cl-case field
+   (:name name)
+   (:query query)
+   (:count-query count-query)
+   (t nil
+   (t
+(pcase-let ((`(,name . ,query) saved-search))
+  (cl-case field
+   (:name name)
+   (:query query)
+   (t nil))
 
 (defun notmuch-hello-saved-search-to-plist (saved-search)
   "Return a copy of SAVED-SEARCH in plist form.
@@ -66,7 +69,7 @@ (defun notmuch-hello-saved-search-to-plist 

[PATCH v3 2/3] emacs: Add simple make target to compile emacs lisp tests

2020-04-25 Thread Jonas Bernoulli
---
 test/Makefile.local | 4 
 1 file changed, 4 insertions(+)

diff --git a/test/Makefile.local b/test/Makefile.local
index 47244e8f..3c043717 100644
--- a/test/Makefile.local
+++ b/test/Makefile.local
@@ -78,6 +78,10 @@ endif
 
 check: test
 
+compile-elisp-tests:
+   $(EMACS) --batch -L emacs -L test -l notmuch.el -l test-lib.el -f \
+   batch-byte-compile test/*.el
+
 SRCS := $(SRCS) $(test_srcs)
 CLEAN += $(TEST_BINARIES) $(addsuffix .o,$(TEST_BINARIES)) \
 $(dir)/database-test.o \
-- 
2.26.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 3/3] emacs: Use `dolist' instead of `mapcar' for side-effects

2020-04-25 Thread Jonas Bernoulli
As recommended by the byte-compiler.
---
 test/emacs-attachment-warnings.el | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/test/emacs-attachment-warnings.el 
b/test/emacs-attachment-warnings.el
index a23692d7..8f4918ef 100644
--- a/test/emacs-attachment-warnings.el
+++ b/test/emacs-attachment-warnings.el
@@ -67,16 +67,15 @@ (defvar attachment-check-tests
 
 (defun notmuch-test-attachment-warning-1 ()
   (let (output expected)
-(mapcar (lambda (test)
- (let* ((expect (car test))
-(body (cdr test))
-(result (attachment-check-test body)))
-   (push expect expected)
-   (push (if (eq result expect)
- result
-   ;; In the case of a failure, include the test
-   ;; details to make it simpler to debug.
-   (format "%S <-- %S" result body))
- output)))
-   attachment-check-tests)
+(dolist (test attachment-check-tests)
+  (let* ((expect (car test))
+(body (cdr test))
+(result (attachment-check-test body)))
+   (push expect expected)
+   (push (if (eq result expect)
+ result
+   ;; In the case of a failure, include the test
+   ;; details to make it simpler to debug.
+   (format "%S <-- %S" result body))
+ output)))
 (notmuch-test-expect-equal output expected)))
-- 
2.26.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs/tree: add notmuch-tree-filter

2020-04-25 Thread William Casarin
This implements the notmuch-tree version of notmuch-show-filter-thread
and binds it to the L key.

Signed-off-by: William Casarin 
---
 emacs/notmuch-tree.el | 9 +
 1 file changed, 9 insertions(+)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index e5c23de2..8f7738d7 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -328,6 +328,7 @@ FUNC."
 (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 "L" 'notmuch-tree-filter)
 (define-key map (kbd "M-p") 'notmuch-tree-prev-thread)
 (define-key map (kbd "M-n") 'notmuch-tree-next-thread)
 (define-key map "k" 'notmuch-tag-jump)
@@ -965,6 +966,14 @@ Complete list of currently available key bindings:
  (insert (format " (process returned %d)" exit-status)))
(insert "\n")
 
+(defun notmuch-tree-filter (query)
+  "Filter or LIMIT the current tree based on a new query string.
+
+Reshows the current tree with matches defined by the new query-string."
+  (interactive (list (notmuch-read-query "Filter tree: ")))
+  (setq notmuch-tree-query-context (if (string= query "") nil query))
+  (notmuch-tree-refresh-view t))
+
 (defun notmuch-tree-process-filter (proc string)
   "Process and filter the output of \"notmuch show\" for tree view"
   (let ((results-buf (process-buffer proc))
-- 
2.25.1

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Emacs: make browsing URLs friendlier with Helm

2020-04-25 Thread Ori
Hi David,

  Keegan Carruthers-Smith posted a patch with a suggested
  change for this in id:m2r1wrxin8@gmail.com. Could you
  try that and see if it addresses your concerns?

  That patch is now in HEAD, but I presume not yet in a
  release.

Yes that patch fixes the issue in Helm. My mistake for searching the
list archives for "helm" but not for "ivy"! I had suspected the issue
might be similar for other completion frameworks and Keegan confirms
this.

Ori
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Emacs: make browsing URLs friendlier with Helm

2020-04-25 Thread David Edmondson
On Friday, 2020-04-24 at 15:46:20 -04, Ori wrote:

> Hi,
>
> This is a fairly small point and was easy for me to locally address, and
> that in itself may be valuable in sharing, but I wondered if it would be
> worth putting a change behind a defcustom option, or depending on how this
> works with other completion frameworks, changing it altogether?
>
> The "B" shortcut calls notmuch-show-browse-urls, which calls completing-read
> with an INITIAL-INPUT of the first URL in the message. On Helm, this shows
> a near-blank list (blank unless other URLs have the first one as a
> substring). It's a nicer behavior for Helm to start off with no initial
> input, as that first URL is highlighted automatically anyway.

Keegan Carruthers-Smith posted a patch with a suggested change for this
in id:m2r1wrxin8@gmail.com. Could you try that and see if it
addresses your concerns?

That patch is now in HEAD, but I presume not yet in a release.

> Locally I simply redefine the function with a minor change (highlighted)
> after loading notmuch:
>
> (defun notmuch-show-browse-urls ( kill)
> "Offer to browse any URLs in the current message.
> With a prefix argument, copy the URL to the kill ring rather than
> browsing."
> (interactive "P")
> (let ((urls (notmuch-show--gather-urls))
>   (prompt (if kill "Copy URL to kill ring: " "Browse URL: "))
>   (fn (if kill #'kill-new #'browse-url)))
>   (if urls
>   (funcall fn (completing-read prompt urls))
> (message "No URLs found."
>
> For reference, in notmuch-show.el that highlighted part is:
> (completing-read prompt (cdr urls) nil nil (car urls))
>
> As I said, I'm not sure how this works with other popular completion
> alternatives like ivy and if the redefined function is better or worse with
> those. Perhaps this post is only here to be useful for other Helm users!
>
> Ori
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

dme.
-- 
Right across from where I'm standing, on the dance floor she was landing.
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Emacs: make browsing URLs friendlier with Helm

2020-04-25 Thread Ori
Hi,

This is a fairly small point and was easy for me to locally address, and
that in itself may be valuable in sharing, but I wondered if it would be
worth putting a change behind a defcustom option, or depending on how this
works with other completion frameworks, changing it altogether?

The "B" shortcut calls notmuch-show-browse-urls, which calls completing-read
with an INITIAL-INPUT of the first URL in the message. On Helm, this shows
a near-blank list (blank unless other URLs have the first one as a
substring). It's a nicer behavior for Helm to start off with no initial
input, as that first URL is highlighted automatically anyway.

Locally I simply redefine the function with a minor change (highlighted)
after loading notmuch:

(defun notmuch-show-browse-urls ( kill)
"Offer to browse any URLs in the current message.
With a prefix argument, copy the URL to the kill ring rather than
browsing."
(interactive "P")
(let ((urls (notmuch-show--gather-urls))
  (prompt (if kill "Copy URL to kill ring: " "Browse URL: "))
  (fn (if kill #'kill-new #'browse-url)))
  (if urls
  (funcall fn (completing-read prompt urls))
(message "No URLs found."

For reference, in notmuch-show.el that highlighted part is:
(completing-read prompt (cdr urls) nil nil (car urls))

As I said, I'm not sure how this works with other popular completion
alternatives like ivy and if the redefined function is better or worse with
those. Perhaps this post is only here to be useful for other Helm users!

Ori
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch