unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope
@ 2020-12-14 16:23 Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 01/32] emacs: use setq instead of set Jonas Bernoulli
                   ` (33 more replies)
  0 siblings, 34 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

Hello,

This patch serious changes a number of things, including boring
cleanup, but the big changes are the following.  The respective
commits are also marked in the list below.  See these commits
for longer descriptions.

1. Split all libraries into sections by adding new headings or
   formatting existing headings properly to be compatible with
   outline-minor-mode.

2. Use lexical-scope in all libraries.  This is potentially faster
   and is recommended for all new code (and old code someone cares
   about enough).  It also has the advantage that it can reveal
   subtle bugs.

Among the many more commits that do not concern these two big
changes, there are a few that might need special attention.
(Again see the commits for details.)

3. No longer use Ido in notmuch-mua-prompt-for-sender.  Might be
   controversial.

4. Stop using unnecessary let-bindings, though how "unnecessary"
   these bindings are is somewhat subjective.

     Cheers,
     Jonas

PS: Don't worry.  I do NOT have another large patch series waiting
    after this.  Future changes should be more focused or even come
    in the form of independent extensions.

Jonas Bernoulli (32):
  emacs: use setq instead of set
  emacs: sanitize dedicated widget action/notify functions
  emacs: define new notmuch-search-item widget type
  emacs: notmuch-start-notmuch: remove backward compatibility code
  emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive
  emacs: notmuch-start-notmuch-sentinel: assert buffer is alive
  emacs: notmuch-start-notmuch: avoid storing process buffer twice
  emacs: avoid passing around some redundant information
  emacs: avoid killing process buffer when process is still alive
1 emacs: make headings outline-minor-mode compatible
2 emacs: use lexical-bindings in all libraries
" emacs: deal with unused lexical arguments and variables
" emacs: notmuch-tag--get-formats: silence byte-compiler
  emacs: inline notmuch-sexp-eof into only caller
  emacs: notmuch-wash-region-to-button: remove unused MSG argument
  emacs: silence compiler wrt notmuch-show-insert-part-text/plain
  emacs: define notmuch-message-queued-tag-changes as buffer-local
  emacs: notmuch-message-apply-queued-tag-changes: cosmetics
  emacs: notmuch-wash.el: require diff-mode at beginning of code
3 emacs: notmuch-mua-prompt-for-sender: don't force Ido on users
  emacs: notmuch-mua.el: move all options into "Options" section
  emacs: notmuch-crypto-status-button-type: fix potential bug
  emacs: various cosmetic improvements
  emacs: various comment improvements
  emacs: various doc-string improvements
  emacs: remove variable notmuch-search-disjunctive-regexp
  emacs: define a few variables as automatically buffer-local
  emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string
  emacs: reorder notmuch.el a bit
4 emacs: avoid unnecessary let-bindings
  emacs: use string-empty-p
  emacs: notmuch-tree-get-match: No longer define as command

 emacs/coolj.el               |  14 +-
 emacs/make-deps.el           |   2 +-
 emacs/notmuch-address.el     |  65 +++++----
 emacs/notmuch-company.el     |   1 -
 emacs/notmuch-compat.el      |   4 +-
 emacs/notmuch-crypto.el      |  14 +-
 emacs/notmuch-draft.el       |  23 +++-
 emacs/notmuch-hello.el       | 228 +++++++++++++++---------------
 emacs/notmuch-jump.el        |  14 +-
 emacs/notmuch-lib.el         | 198 +++++++++++++-------------
 emacs/notmuch-maildir-fcc.el | 112 +++++++--------
 emacs/notmuch-message.el     |  21 ++-
 emacs/notmuch-mua.el         | 123 +++++++++--------
 emacs/notmuch-parser.el      |  18 +--
 emacs/notmuch-print.el       |  16 ++-
 emacs/notmuch-query.el       |  21 ++-
 emacs/notmuch-show.el        | 127 ++++++++++-------
 emacs/notmuch-tag.el         | 100 ++++++++------
 emacs/notmuch-tree.el        |  59 ++++----
 emacs/notmuch-wash.el        |  54 ++++----
 emacs/notmuch.el             | 260 +++++++++++++++++++----------------
 emacs/rstdoc.el              |   2 +-
 test/test-lib.el             |   4 +-
 23 files changed, 786 insertions(+), 694 deletions(-)

-- 
2.29.1

^ permalink raw reply	[flat|nested] 79+ messages in thread

* [PATCH 01/32] emacs: use setq instead of set
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
                   ` (32 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

Commonly `set' is only used if there is no way around it;
i.e. when the variable cannot be known until runtime.
---
 emacs/notmuch-tree.el |  2 +-
 emacs/notmuch.el      | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 57843e25..17863f6a 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1133,7 +1133,7 @@ (defun notmuch-tree (&optional query query-context target buffer-name open-targe
 	(inhibit-read-only t))
     (pop-to-buffer-same-window buffer))
   ;; Don't track undo information for this buffer
-  (set 'buffer-undo-list t)
+  (setq buffer-undo-list t)
   (notmuch-tree-worker query query-context target open-target unthreaded)
   (setq notmuch-tree-parent-buffer parent-buffer)
   (setq truncate-lines t))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 95770fc3..b221be05 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -693,7 +693,7 @@ (defun notmuch-search-process-sentinel (proc msg)
 		    (throw 'return nil))
 		  (when (and atbob
 			     (not (string= notmuch-search-target-thread "found")))
-		    (set 'never-found-target-thread t)))))
+		    (setq never-found-target-thread t)))))
 	    (when (and never-found-target-thread
 		       notmuch-search-target-line)
 	      (goto-char (point-min))
@@ -1000,11 +1000,11 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
     (unless (eq major-mode 'notmuch-search-mode)
       (notmuch-search-mode))
     ;; Don't track undo information for this buffer
-    (set 'buffer-undo-list t)
-    (set 'notmuch-search-query-string query)
-    (set 'notmuch-search-oldest-first oldest-first)
-    (set 'notmuch-search-target-thread target-thread)
-    (set 'notmuch-search-target-line target-line)
+    (setq buffer-undo-list t)
+    (setq notmuch-search-query-string query)
+    (setq notmuch-search-oldest-first oldest-first)
+    (setq notmuch-search-target-thread target-thread)
+    (setq notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
     (let ((proc (get-buffer-process (current-buffer)))
 	  (inhibit-read-only t))
@@ -1052,7 +1052,7 @@ (defun notmuch-search-toggle-order ()
 This command toggles the sort order for the current search. The
 default sort order is defined by `notmuch-search-oldest-first'."
   (interactive)
-  (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
+  (setq notmuch-search-oldest-first (not notmuch-search-oldest-first))
   (notmuch-search-refresh-view))
 
 (defun notmuch-group-disjunctive-query-string (query-string)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 01/32] emacs: use setq instead of set Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 03/32] emacs: define new notmuch-search-item widget type Jonas Bernoulli
                   ` (31 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

These functions are used as action/notify functions.  That dictates
the appropriate function signatures but even though these functions
are not used for anything else they use incompatible signatures,
forcing the callers to use lambda expressions to deal with these
incompatibilities.

Fix that by adjusting the function signatures to the needs of the
only intended callers.

Two of these functions were defined as commands but because the
interactive form did not return the mandatory arguments, we know
that nobody (successfully) used these as commands.

In one case we move the location of a y-or-n-p prompt.
---
 emacs/notmuch-hello.el | 47 +++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index fa31694f..767c6874 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -385,18 +385,16 @@ (defun notmuch-hello-nice-number (n)
 		     (format "%s%03d" notmuch-hello-thousands-separator elem))
 		   (cdr result)))))
 
-(defun notmuch-hello-search (&optional search)
-  (unless (null search)
-    (setq search (string-trim search))
-    (let ((history-delete-duplicates t))
-      (add-to-history 'notmuch-search-history search)))
-  (notmuch-search search notmuch-search-oldest-first))
-
-(defun notmuch-hello-add-saved-search (widget)
-  (interactive)
-  (let ((search (widget-value
-		 (symbol-value
-		  (widget-get widget :notmuch-saved-search-widget))))
+(defun notmuch-hello-search (widget &rest _event)
+  (let ((search (widget-value widget)))
+    (when search
+      (setq search (string-trim search))
+      (let ((history-delete-duplicates t))
+	(add-to-history 'notmuch-search-history search)))
+    (notmuch-search search notmuch-search-oldest-first)))
+
+(defun notmuch-hello-add-saved-search (widget &rest _event)
+  (let ((search (widget-value (widget-get widget :parent)))
 	(name (completing-read "Name for saved search: "
 			       notmuch-saved-searches)))
     ;; If an existing saved search with this name exists, remove it.
@@ -412,13 +410,11 @@ (defun notmuch-hello-add-saved-search (widget)
     (message "Saved '%s' as '%s'." search name)
     (notmuch-hello-update)))
 
-(defun notmuch-hello-delete-search-from-history (widget)
-  (interactive)
-  (let ((search (widget-value
-		 (symbol-value
-		  (widget-get widget :notmuch-saved-search-widget)))))
-    (setq notmuch-search-history (delete search
-					 notmuch-search-history))
+(defun notmuch-hello-delete-search-from-history (widget &rest _event)
+  (when (y-or-n-p "Are you sure you want to delete this search? ")
+    (let ((search (widget-value (widget-get widget :parent))))
+      (setq notmuch-search-history
+	    (delete search notmuch-search-history)))
     (notmuch-hello-update)))
 
 (defun notmuch-hello-longest-label (searches-alist)
@@ -768,8 +764,7 @@ (defun notmuch-hello-insert-search ()
 		 ;; search boxes.
 		 :size (max 8 (- (window-width) notmuch-hello-indent
 				 (length "Search: ")))
-		 :action (lambda (widget &rest ignore)
-			   (notmuch-hello-search (widget-value widget))))
+		 :action #'notmuch-hello-search)
   ;; Add an invisible dot to make `widget-end-of-line' ignore
   ;; trailing spaces in the search widget field.  A dot is used
   ;; instead of a space to make `show-trailing-whitespace'
@@ -816,20 +811,16 @@ (defun notmuch-hello-insert-recent-searches ()
 						   ;; button. 5 for the
 						   ;; `[del]' button.
 						   1 5))
-				     :action (lambda (widget &rest ignore)
-					       (notmuch-hello-search (widget-value widget)))
+				     :action #'notmuch-hello-search
 				     search))
 		 (widget-insert " ")
 		 (widget-create 'push-button
-				:notify (lambda (widget &rest ignore)
-					  (notmuch-hello-add-saved-search widget))
+				:notify #'notmuch-hello-add-saved-search
 				:notmuch-saved-search-widget widget-symbol
 				"save")
 		 (widget-insert " ")
 		 (widget-create 'push-button
-				:notify (lambda (widget &rest ignore)
-					  (when (y-or-n-p "Are you sure you want to delete this search? ")
-					    (notmuch-hello-delete-search-from-history widget)))
+				:notify #'notmuch-hello-delete-search-from-history
 				:notmuch-saved-search-widget widget-symbol
 				"del"))
 	       (widget-insert "\n"))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 03/32] emacs: define new notmuch-search-item widget type
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 01/32] emacs: use setq instead of set Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 04/32] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
                   ` (30 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

This is complex enough to warrant a dedicated widget type,
which will make future improvements less messy to implement.
---
 emacs/notmuch-hello.el | 92 +++++++++++++++++++++---------------------
 1 file changed, 45 insertions(+), 47 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 767c6874..7bc713f3 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -385,6 +385,40 @@ (defun notmuch-hello-nice-number (n)
 		     (format "%s%03d" notmuch-hello-thousands-separator elem))
 		   (cdr result)))))
 
+(define-widget 'notmuch-search-item 'item
+  "A recent search."
+  :format "%v\n"
+  :value-create 'notmuch-search-item-value-create)
+
+(defun notmuch-search-item-value-create (widget)
+  (let ((value (widget-get widget :value)))
+    (widget-insert (make-string notmuch-hello-indent ?\s))
+    (widget-create 'editable-field
+		   :size (widget-get widget :size)
+		   :parent widget
+		   :action #'notmuch-hello-search
+		   value)
+    (widget-insert " ")
+    (widget-create 'push-button
+		   :parent widget
+		   :notify #'notmuch-hello-add-saved-search
+		   "save")
+    (widget-insert " ")
+    (widget-create 'push-button
+		   :parent widget
+		   :notify #'notmuch-hello-delete-search-from-history
+		   "del")))
+
+(defun notmuch-search-item-field-width ()
+  (max 8 ; Don't let the search boxes be less than 8 characters wide.
+       (- (window-width)
+	  notmuch-hello-indent ; space at bol
+	  notmuch-hello-indent ; space at eol
+	  1    ; for the space before the [save] button
+	  6    ; for the [save] button
+	  1    ; for the space before the [del] button
+	  5))) ; for the [del] button
+
 (defun notmuch-hello-search (widget &rest _event)
   (let ((search (widget-value widget)))
     (when search
@@ -778,54 +812,18 @@ (defun notmuch-hello-insert-recent-searches ()
   "Insert recent searches."
   (when notmuch-search-history
     (widget-insert "Recent searches: ")
-    (widget-create 'push-button
-		   :notify (lambda (&rest ignore)
-			     (when (y-or-n-p "Are you sure you want to clear the searches? ")
-			       (setq notmuch-search-history nil)
-			       (notmuch-hello-update)))
-		   "clear")
+    (widget-create
+     'push-button
+     :notify (lambda (&rest _ignore)
+	       (when (y-or-n-p "Are you sure you want to clear the searches? ")
+		 (setq notmuch-search-history nil)
+		 (notmuch-hello-update)))
+     "clear")
     (widget-insert "\n\n")
-    (let ((start (point)))
-      (cl-loop for i from 1 to notmuch-hello-recent-searches-max
-	       for search in notmuch-search-history do
-	       (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
-		 (set widget-symbol
-		      (widget-create 'editable-field
-				     ;; Don't let the search boxes be
-				     ;; less than 8 characters wide.
-				     :size (max 8
-						(- (window-width)
-						   ;; Leave some space
-						   ;; at the start and
-						   ;; end of the
-						   ;; boxes.
-						   (* 2 notmuch-hello-indent)
-						   ;; 1 for the space
-						   ;; before the
-						   ;; `[save]' button. 6
-						   ;; for the `[save]'
-						   ;; button.
-						   1 6
-						   ;; 1 for the space
-						   ;; before the `[del]'
-						   ;; button. 5 for the
-						   ;; `[del]' button.
-						   1 5))
-				     :action #'notmuch-hello-search
-				     search))
-		 (widget-insert " ")
-		 (widget-create 'push-button
-				:notify #'notmuch-hello-add-saved-search
-				:notmuch-saved-search-widget widget-symbol
-				"save")
-		 (widget-insert " ")
-		 (widget-create 'push-button
-				:notify #'notmuch-hello-delete-search-from-history
-				:notmuch-saved-search-widget widget-symbol
-				"del"))
-	       (widget-insert "\n"))
-      (indent-rigidly start (point) notmuch-hello-indent))
-    nil))
+    (let ((width (notmuch-search-item-field-width)))
+      (dolist (search (seq-take notmuch-search-history
+				notmuch-hello-recent-searches-max))
+	(widget-create 'notmuch-search-item :value search :size width)))))
 
 (defun notmuch-hello-insert-searches (title query-list &rest options)
   "Insert a section with TITLE showing a list of buttons made from QUERY-LIST.
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 04/32] emacs: notmuch-start-notmuch: remove backward compatibility code
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (2 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 03/32] emacs: define new notmuch-search-item widget type Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 05/32] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
                   ` (29 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 64 ++++++++++++--------------------------------
 1 file changed, 17 insertions(+), 47 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index e23999ad..76387779 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -896,42 +896,19 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 invoke `set-process-sentinel' directly on the returned process,
 as that will interfere with the handling of stderr and the exit
 status."
-  (let (err-file err-buffer proc err-proc
-		 ;; Find notmuch using Emacs' `exec-path'
-		 (command (or (executable-find notmuch-command)
-			      (error "Command not found: %s" notmuch-command))))
-    (if (fboundp 'make-process)
-	(progn
-	  (setq err-buffer (generate-new-buffer " *notmuch-stderr*"))
-	  ;; Emacs 25 and newer has `make-process', which allows
-	  ;; redirecting stderr independently from stdout to a
-	  ;; separate buffer. As this allows us to avoid using a
-	  ;; temporary file and shell invocation, use it when
-	  ;; available.
-	  (setq proc (make-process
-		      :name name
-		      :buffer buffer
-		      :command (cons command args)
-		      :connection-type 'pipe
-		      :stderr err-buffer))
-	  (setq err-proc (get-buffer-process err-buffer))
-	  (process-put proc 'err-buffer err-buffer)
-
-	  (process-put err-proc 'err-file err-file)
-	  (process-put err-proc 'err-buffer err-buffer)
-	  (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel))
-      ;; On Emacs versions before 25, there is no way to capture
-      ;; stdout and stderr separately for asynchronous processes, or
-      ;; even to redirect stderr to a file, so we use a trivial shell
-      ;; wrapper to send stderr to a temporary file and clean things
-      ;; up in the sentinel.
-      (setq err-file (make-temp-file "nmerr"))
-      (let ((process-connection-type nil)) ;; Use a pipe
-	(setq proc (apply #'start-process name buffer
-			  "/bin/sh" "-c"
-			  "exec 2>\"$1\"; shift; exec \"$0\" \"$@\""
-			  command err-file args)))
-      (process-put proc 'err-file err-file))
+  (let* ((command (or (executable-find notmuch-command)
+		      (error "Command not found: %s" notmuch-command)))
+	 (err-buffer (generate-new-buffer " *notmuch-stderr*"))
+	 (proc (make-process
+		:name name
+		:buffer buffer
+		:command (cons command args)
+		:connection-type 'pipe
+		:stderr err-buffer))
+	 (err-proc (get-buffer-process err-buffer)))
+    (process-put err-proc 'err-buffer err-buffer)
+    (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
+    (process-put proc 'err-buffer err-buffer)
     (process-put proc 'sub-sentinel sentinel)
     (process-put proc 'real-command (cons notmuch-command args))
     (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
@@ -939,9 +916,7 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 
 (defun notmuch-start-notmuch-sentinel (proc event)
   "Process sentinel function used by `notmuch-start-notmuch'."
-  (let* ((err-file (process-get proc 'err-file))
-	 (err-buffer (or (process-get proc 'err-buffer)
-			 (find-file-noselect err-file)))
+  (let* ((err-buffer (process-get proc 'err-buffer))
 	 (err (and (not (zerop (buffer-size err-buffer)))
 		   (with-current-buffer err-buffer (buffer-string))))
 	 (sub-sentinel (process-get proc 'sub-sentinel))
@@ -977,16 +952,11 @@ (defun notmuch-start-notmuch-sentinel (proc event)
       (error
        ;; Emacs behaves strangely if an error escapes from a sentinel,
        ;; so turn errors into messages.
-       (message "%s" (error-message-string err))))
-    (when err-file (ignore-errors (delete-file err-file)))))
+       (message "%s" (error-message-string err))))))
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
-  (let* ((err-file (process-get proc 'err-file))
-	 ;; When `make-process' is available, use the error buffer
-	 ;; associated with the process, otherwise the error file.
-	 (err-buffer (or (process-get proc 'err-buffer)
-			 (find-file-noselect err-file))))
-    (when err-buffer (kill-buffer err-buffer))))
+  (let ((buffer (process-get proc 'err-buffer)))
+    (kill-buffer buffer)))
 
 (defvar-local notmuch-show-process-crypto nil)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 05/32] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (3 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 04/32] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 06/32] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
                   ` (28 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-lib.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 76387779..21fa2582 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -956,7 +956,8 @@ (defun notmuch-start-notmuch-sentinel (proc event)
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
   (let ((buffer (process-get proc 'err-buffer)))
-    (kill-buffer buffer)))
+    (when (buffer-live-p buffer)
+      (kill-buffer buffer))))
 
 (defvar-local notmuch-show-process-crypto nil)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 06/32] emacs: notmuch-start-notmuch-sentinel: assert buffer is alive
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (4 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 05/32] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 07/32] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
                   ` (27 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-lib.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 21fa2582..06ca8cdc 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -917,7 +917,8 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 (defun notmuch-start-notmuch-sentinel (proc event)
   "Process sentinel function used by `notmuch-start-notmuch'."
   (let* ((err-buffer (process-get proc 'err-buffer))
-	 (err (and (not (zerop (buffer-size err-buffer)))
+	 (err (and (buffer-live-p err-buffer)
+		   (not (zerop (buffer-size err-buffer)))
 		   (with-current-buffer err-buffer (buffer-string))))
 	 (sub-sentinel (process-get proc 'sub-sentinel))
 	 (real-command (process-get proc 'real-command)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 07/32] emacs: notmuch-start-notmuch: avoid storing process buffer twice
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (5 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 06/32] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 08/32] emacs: avoid passing around some redundant information Jonas Bernoulli
                   ` (26 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 06ca8cdc..be15af5e 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -906,12 +906,11 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 		:connection-type 'pipe
 		:stderr err-buffer))
 	 (err-proc (get-buffer-process err-buffer)))
-    (process-put err-proc 'err-buffer err-buffer)
-    (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
     (process-put proc 'err-buffer err-buffer)
     (process-put proc 'sub-sentinel sentinel)
     (process-put proc 'real-command (cons notmuch-command args))
     (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
+    (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
     proc))
 
 (defun notmuch-start-notmuch-sentinel (proc event)
@@ -956,7 +955,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
        (message "%s" (error-message-string err))))))
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
-  (let ((buffer (process-get proc 'err-buffer)))
+  (let ((buffer (process-buffer proc)))
     (when (buffer-live-p buffer)
       (kill-buffer buffer))))
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 08/32] emacs: avoid passing around some redundant information
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (6 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 07/32] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 09/32] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
                   ` (25 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index be15af5e..e09912d3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -800,20 +800,27 @@ (defun notmuch-check-exit-status (exit-status command &optional output err)
 Emacs requested a newer output format than supported by the notmuch CLI.
 You may need to restart Emacs or upgrade your notmuch package."))
    (t
-    (let* ((command-string
-	    (mapconcat (lambda (arg)
-			 (shell-quote-argument
-			  (cond ((stringp arg) arg)
-				((symbolp arg) (symbol-name arg))
-				(t "*UNKNOWN ARGUMENT*"))))
-		       command " "))
-	   (extra
-	    (concat "command: " command-string "\n"
-		    (if (integerp exit-status)
-			(format "exit status: %s\n" exit-status)
-		      (format "exit signal: %s\n" exit-status))
-		    (and err    (concat "stderr:\n" err))
-		    (and output (concat "stdout:\n" output)))))
+    (pcase-let*
+	((`(,command . ,args) command)
+	 (command (if (equal (file-name-nondirectory command)
+			     notmuch-command)
+		      notmuch-command
+		    command))
+	 (command-string
+	  (mapconcat (lambda (arg)
+		       (shell-quote-argument
+			(cond ((stringp arg) arg)
+			      ((symbolp arg) (symbol-name arg))
+			      (t "*UNKNOWN ARGUMENT*"))))
+		     (cons command args)
+		     " "))
+	 (extra
+	  (concat "command: " command-string "\n"
+		  (if (integerp exit-status)
+		      (format "exit status: %s\n" exit-status)
+		    (format "exit signal: %s\n" exit-status))
+		  (and err    (concat "stderr:\n" err))
+		  (and output (concat "stdout:\n" output)))))
       (if err
 	  ;; We have an error message straight from the CLI.
 	  (notmuch-logged-error
@@ -821,7 +828,7 @@ (defun notmuch-check-exit-status (exit-status command &optional output err)
 	;; We only have combined output from the CLI; don't inundate
 	;; the user with it.  Mimic `process-lines'.
 	(notmuch-logged-error (format "%s exited with status %s"
-				      (car command) exit-status)
+				      command exit-status)
 			      extra))
       ;; `notmuch-logged-error' does not return.
       ))))
@@ -908,7 +915,6 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 	 (err-proc (get-buffer-process err-buffer)))
     (process-put proc 'err-buffer err-buffer)
     (process-put proc 'sub-sentinel sentinel)
-    (process-put proc 'real-command (cons notmuch-command args))
     (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
     (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
     proc))
@@ -919,8 +925,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
 	 (err (and (buffer-live-p err-buffer)
 		   (not (zerop (buffer-size err-buffer)))
 		   (with-current-buffer err-buffer (buffer-string))))
-	 (sub-sentinel (process-get proc 'sub-sentinel))
-	 (real-command (process-get proc 'real-command)))
+	 (sub-sentinel (process-get proc 'sub-sentinel)))
     (condition-case err
 	(progn
 	  ;; Invoke the sub-sentinel, if any
@@ -932,7 +937,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
 	  ;; and there's no point in telling the user that (but we
 	  ;; still check for and report stderr output below).
 	  (when (buffer-live-p (process-buffer proc))
-	    (notmuch-check-async-exit-status proc event real-command err))
+	    (notmuch-check-async-exit-status proc event nil err))
 	  ;; If that didn't signal an error, then any error output was
 	  ;; really warning output.  Show warnings, if any.
 	  (let ((warnings
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 09/32] emacs: avoid killing process buffer when process is still alive
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (7 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 08/32] emacs: avoid passing around some redundant information Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 10/32] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
                   ` (24 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index e09912d3..0e235fa3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -960,9 +960,10 @@ (defun notmuch-start-notmuch-sentinel (proc event)
        (message "%s" (error-message-string err))))))
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
-  (let ((buffer (process-buffer proc)))
-    (when (buffer-live-p buffer)
-      (kill-buffer buffer))))
+  (unless (process-live-p proc)
+    (let ((buffer (process-buffer proc)))
+      (when (buffer-live-p buffer)
+	(kill-buffer buffer)))))
 
 (defvar-local notmuch-show-process-crypto nil)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 10/32] emacs: make headings outline-minor-mode compatible
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (8 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 09/32] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 11/32] emacs: use lexical-bindings in all libraries Jonas Bernoulli
                   ` (23 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

`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.
---
 emacs/coolj.el               | 12 +++----
 emacs/notmuch-address.el     | 28 +++++++++++-----
 emacs/notmuch-company.el     |  1 -
 emacs/notmuch-compat.el      |  2 --
 emacs/notmuch-crypto.el      |  8 ++++-
 emacs/notmuch-draft.el       |  9 ++++-
 emacs/notmuch-hello.el       | 47 ++++++++++++++++++--------
 emacs/notmuch-jump.el        |  2 --
 emacs/notmuch-lib.el         | 41 ++++++++++++++++++-----
 emacs/notmuch-maildir-fcc.el | 18 +++++-----
 emacs/notmuch-mua.el         | 18 +++++++---
 emacs/notmuch-print.el       |  8 +++--
 emacs/notmuch-query.el       |  8 ++---
 emacs/notmuch-show.el        | 64 ++++++++++++++++++++++++++----------
 emacs/notmuch-tag.el         | 16 ++++++++-
 emacs/notmuch-tree.el        | 25 +++++++++++---
 emacs/notmuch-wash.el        | 18 +++++-----
 emacs/notmuch.el             | 32 +++++++++++++++++-
 test/test-lib.el             |  4 ++-
 19 files changed, 263 insertions(+), 98 deletions(-)

diff --git a/emacs/coolj.el b/emacs/coolj.el
index 0385872f..b3e314f0 100644
--- a/emacs/coolj.el
+++ b/emacs/coolj.el
@@ -25,13 +25,13 @@
 
 ;;; Commentary:
 
-;;; This is a simple derivative of some functionality from
-;;; `longlines.el'. The key difference is that this version will
-;;; insert a prefix at the head of each wrapped line. The prefix is
-;;; calculated from the originating long line.
+;; This is a simple derivative of some functionality from
+;; `longlines.el'. The key difference is that this version will
+;; insert a prefix at the head of each wrapped line. The prefix is
+;; calculated from the originating long line.
 
-;;; No minor-mode is provided, the caller is expected to call
-;;; `coolj-wrap-region' to wrap the region of interest.
+;; No minor-mode is provided, the caller is expected to call
+;; `coolj-wrap-region' to wrap the region of interest.
 
 ;;; Code:
 
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 71985ed7..bf29c3a0 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -25,9 +25,11 @@ (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
 (require 'notmuch-company)
-;;
+
 (declare-function company-manual-begin "company")
 
+;;; Cache internals
+
 (defvar notmuch-address-last-harvest 0
   "Time of last address harvest.")
 
@@ -47,6 +49,8 @@ (defun notmuch-address--harvest-ready ()
   (or notmuch-address-full-harvest-finished
       (notmuch-address--load-address-hash)))
 
+;;; Options
+
 (defcustom notmuch-address-command 'internal
   "Determines how address completion candidates are generated.
 
@@ -133,6 +137,14 @@ (defcustom notmuch-address-post-completion-functions nil
   :group 'notmuch-address
   :group 'notmuch-hooks)
 
+(defcustom notmuch-address-use-company t
+  "If available, use company mode for address completion."
+  :type 'boolean
+  :group 'notmuch-send
+  :group 'notmuch-address)
+
+;;; Setup
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
       PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -147,12 +159,6 @@ (defvar notmuch-address-history nil)
 (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
-(defcustom notmuch-address-use-company t
-  "If available, use company mode for address completion."
-  :type 'boolean
-  :group 'notmuch-send
-  :group 'notmuch-address)
-
 (defun notmuch-address-setup ()
   (let* ((setup-company (and notmuch-address-use-company
 			     (require 'company nil t)))
@@ -178,6 +184,8 @@ (defun notmuch-address-toggle-internal-completion ()
 	(kill-local-variable 'company-idle-delay)
       (setq-local company-idle-delay nil))))
 
+;;; Completion
+
 (defun notmuch-address-matching (substring)
   "Returns a list of completion candidates matching SUBSTRING.
 The candidates are taken from `notmuch-address-completions'."
@@ -250,6 +258,8 @@ (defun notmuch-address-expand-name ()
 	(ding))))
    (t nil)))
 
+;;; Harvest
+
 (defun notmuch-address-harvest-addr (result)
   (let ((name-addr (plist-get result :name-addr)))
     (puthash name-addr t notmuch-address-completions)))
@@ -406,7 +416,7 @@ (defun notmuch-address-harvest-trigger ()
 	       (setq notmuch-address-full-harvest-finished t))
 	   (setq notmuch-address-last-harvest 0)))))))
 
-;;
+;;; Standalone completion
 
 (defun notmuch-address-from-minibuffer (prompt)
   (if (not notmuch-address-command)
@@ -425,7 +435,7 @@ (defun notmuch-address-from-minibuffer (prompt)
       (let ((minibuffer-local-map rmap))
 	(read-string prompt)))))
 
-;;
+;;; _
 
 (provide 'notmuch-address)
 
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index b50e73c8..4439cc15 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -102,7 +102,6 @@ (defun notmuch-company (command &optional arg &rest _ignore)
        (run-hook-with-args 'notmuch-address-post-completion-functions arg))
       (no-cache t))))
 
-
 (provide 'notmuch-company)
 
 ;;; notmuch-company.el ends here
diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el
index 2975f4c2..c4e07780 100644
--- a/emacs/notmuch-compat.el
+++ b/emacs/notmuch-compat.el
@@ -41,8 +41,6 @@ (defun notmuch-message--fold-long-headers ()
 (unless (fboundp 'message--fold-long-headers)
   (add-hook 'message-header-hook 'notmuch-message--fold-long-headers))
 
-;; End of compatibility functions
-
 (provide 'notmuch-compat)
 
 ;;; notmuch-compat.el ends here
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 9e6f3a9d..6d2d35a5 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -26,6 +26,8 @@ (require 'notmuch-lib)
 
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 
+;;; Options
+
 (defcustom notmuch-crypto-process-mime t
   "Whether to process cryptographic MIME parts.
 
@@ -55,6 +57,8 @@ (defcustom notmuch-crypto-gpg-program epg-gpg-program
   :type 'string
   :group 'notmuch-crypto)
 
+;;; Faces
+
 (defface notmuch-crypto-part-header
   '((((class color)
       (background dark))
@@ -96,6 +100,8 @@ (defface notmuch-crypto-decryption
   :group 'notmuch-crypto
   :group 'notmuch-faces)
 
+;;; Functions
+
 (define-button-type 'notmuch-crypto-status-button-type
   'action (lambda (button) (message (button-get button 'help-echo)))
   'follow-link t
@@ -259,7 +265,7 @@ (defun notmuch-crypto-insert-encstatus-button (encstatus)
    'mouse-face 'notmuch-crypto-decryption)
   (insert "\n"))
 
-;;
+;;; _
 
 (provide 'notmuch-crypto)
 
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index f928be87..9ce9e736 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -31,6 +31,8 @@ (require 'notmuch-tag)
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 (declare-function notmuch-message-mode "notmuch-mua")
 
+;;; Options
+
 (defgroup notmuch-draft nil
   "Saving and editing drafts in Notmuch."
   :group 'notmuch)
@@ -85,6 +87,8 @@ (i.e with an mml encryption tag in it)."
   :group 'notmuch-draft
   :group 'notmuch-crypto)
 
+;;; Internal
+
 (defvar notmuch-draft-encryption-tag-regex
   "<#\\(part encrypt\\|secure.*mode=.*encrypt>\\)"
   "Regular expression matching mml tags indicating encryption of part or message.")
@@ -169,6 +173,8 @@ (defun notmuch-draft--make-message-id ()
   ;; but notmuch doesn't want that form, so remove them.
   (concat "draft-" (substring (message-make-message-id) 1 -1)))
 
+;;; Commands
+
 (defun notmuch-draft-save ()
   "Save the current draft message in the notmuch database.
 
@@ -226,6 +232,7 @@ (defun notmuch-draft-postpone ()
 
 (defun notmuch-draft-resume (id)
   "Resume editing of message with id ID."
+  ;; Used by command `notmuch-show-resume-message'.
   (let* ((tags (process-lines notmuch-command "search" "--output=tags"
 			      "--exclude=false" id))
 	 (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
@@ -265,10 +272,10 @@ (defun notmuch-draft-resume (id)
       ;; message is resaved or sent.
       (setq notmuch-draft-id (and draft id)))))
 
+;;; _
 
 (add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
 
-
 (provide 'notmuch-draft)
 
 ;;; notmuch-draft.el ends here
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 7bc713f3..28ffedd9 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -37,6 +37,8 @@ (declare-function notmuch-unthreaded
 		  (&optional query query-context target buffer-name open-target))
 
 
+;;; Options
+
 (defun notmuch-saved-search-get (saved-search field)
   "Get FIELD from SAVED-SEARCH.
 
@@ -192,6 +194,8 @@ (defcustom notmuch-saved-search-sort-function nil
 (defvar notmuch-hello-indent 4
   "How much to indent non-headers.")
 
+(defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))
+
 (defcustom notmuch-show-logo t
   "Should the notmuch logo be shown?"
   :type 'boolean
@@ -367,23 +371,15 @@ (defcustom notmuch-hello-auto-refresh t
   :group 'notmuch-hello
   :type 'boolean)
 
+;;; Internal variables
+
 (defvar notmuch-hello-hidden-sections nil
   "List of sections titles whose contents are hidden.")
 
 (defvar notmuch-hello-first-run t
   "True if `notmuch-hello' is run for the first time, set to nil afterwards.")
 
-(defun notmuch-hello-nice-number (n)
-  (let (result)
-    (while (> n 0)
-      (push (% n 1000) result)
-      (setq n (/ n 1000)))
-    (setq result (or result '(0)))
-    (apply #'concat
-	   (number-to-string (car result))
-	   (mapcar (lambda (elem)
-		     (format "%s%03d" notmuch-hello-thousands-separator elem))
-		   (cdr result)))))
+;;; Widgets for inserters
 
 (define-widget 'notmuch-search-item 'item
   "A recent search."
@@ -419,6 +415,8 @@ (defun notmuch-search-item-field-width ()
 	  1    ; for the space before the [del] button
 	  5))) ; for the [del] button
 
+;;; Widget actions
+
 (defun notmuch-hello-search (widget &rest _event)
   (let ((search (widget-value widget)))
     (when search
@@ -451,6 +449,13 @@ (defun notmuch-hello-delete-search-from-history (widget &rest _event)
 	    (delete search notmuch-search-history)))
     (notmuch-hello-update)))
 
+;;; Button utilities
+
+;; `notmuch-hello-query-counts', `notmuch-hello-nice-number' and
+;; `notmuch-hello-insert-buttons' are used outside this section.
+;; All other functions that are defined in this section are only
+;; used by these two functions.
+
 (defun notmuch-hello-longest-label (searches-alist)
   (or (cl-loop for elem in searches-alist
 	       maximize (length (notmuch-saved-search-get elem :name)))
@@ -585,6 +590,18 @@ (defun notmuch-hello-query-counts (query-list &rest options)
 	   (list (plist-put elem-plist :count message-count)))))
      query-list)))
 
+(defun notmuch-hello-nice-number (n)
+  (let (result)
+    (while (> n 0)
+      (push (% n 1000) result)
+      (setq n (/ n 1000)))
+    (setq result (or result '(0)))
+    (apply #'concat
+	   (number-to-string (car result))
+	   (mapcar (lambda (elem)
+		     (format "%s%03d" notmuch-hello-thousands-separator elem))
+		   (cdr result)))))
+
 (defun notmuch-hello-insert-buttons (searches)
   "Insert buttons for SEARCHES.
 
@@ -639,7 +656,7 @@ (defun notmuch-hello-insert-buttons (searches)
     (unless (eq (% count tags-per-line) 0)
       (widget-insert "\n"))))
 
-(defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))
+;;; Mode
 
 (defun notmuch-hello-update ()
   "Update the notmuch-hello buffer."
@@ -723,6 +740,8 @@ (define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
   ;;(setq buffer-read-only t)
   )
 
+;;; Inserters
+
 (defun notmuch-hello-generate-tag-alist (&optional hide-tags)
   "Return an alist from tags to queries to display in the all-tags section."
   (cl-mapcan (lambda (tag)
@@ -922,6 +941,8 @@ (defun notmuch-hello-insert-footer ()
     (let ((fill-column (- (window-width) notmuch-hello-indent)))
       (center-region start (point)))))
 
+;;; Hello!
+
 ;;;###autoload
 (defun notmuch-hello (&optional no-display)
   "Run notmuch and display saved searches, known tags, etc."
@@ -973,7 +994,7 @@ (defun notmuch-hello (&optional no-display)
   (run-hooks 'notmuch-hello-refresh-hook)
   (setq notmuch-hello-first-run nil))
 
-;;
+;;; _
 
 (provide 'notmuch-hello)
 
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index ff622055..7a27b6b3 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -198,8 +198,6 @@ (defun notmuch-jump--make-keymap (action-map prompt)
 		 (exit-minibuffer)))))))
     map))
 
-;;
-
 (provide 'notmuch-jump)
 
 ;;; notmuch-jump.el ends here
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0e235fa3..0b698d59 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -33,6 +33,8 @@ (unless (require 'notmuch-version nil t)
   (defconst notmuch-emacs-version "unknown"
     "Placeholder variable when notmuch-version.el[c] is not available."))
 
+;;; Groups
+
 (defgroup notmuch nil
   "Notmuch mail reader for Emacs."
   :group 'mail)
@@ -78,6 +80,8 @@ (defgroup notmuch-faces nil
   "Graphical attributes for displaying text"
   :group 'notmuch)
 
+;;; Options
+
 (defcustom notmuch-command "notmuch"
   "Name of the notmuch binary.
 
@@ -125,11 +129,6 @@ (defcustom notmuch-poll-script nil
 		 (string :tag "Custom script"))
   :group 'notmuch-external)
 
-;;
-
-(defvar notmuch-search-history nil
-  "Variable to store notmuch searches history.")
-
 (defcustom notmuch-archive-tags '("-inbox")
   "List of tag changes to apply to a message or a thread when it is archived.
 
@@ -144,6 +143,11 @@ (defcustom notmuch-archive-tags '("-inbox")
   :group 'notmuch-search
   :group 'notmuch-show)
 
+;;; Variables
+
+(defvar notmuch-search-history nil
+  "Variable to store notmuch searches history.")
+
 (defvar notmuch-common-keymap
   (let ((map (make-sparse-keymap)))
     (define-key map "?" 'notmuch-help)
@@ -177,6 +181,8 @@ (define-button-type 'notmuch-button-type
 		  (select-window (posn-window (event-start last-input-event)))
 		  (button-activate button)))
 
+;;; CLI Utilities
+
 (defun notmuch-command-to-string (&rest args)
   "Synchronously invoke \"notmuch\" with the given list of arguments.
 
@@ -234,6 +240,8 @@ (defun notmuch-version ()
 	       (concat cli-version
 		       " (emacs mua version " notmuch-emacs-version ")")))))
 
+;;; Notmuch Configuration
+
 (defun notmuch-config-get (item)
   "Return a value from the notmuch configuration."
   (let* ((val (notmuch-command-to-string "config" "get" item))
@@ -263,6 +271,8 @@ (defun notmuch-user-other-email ()
 (defun notmuch-user-emails ()
   (cons (notmuch-user-primary-email) (notmuch-user-other-email)))
 
+;;; Commands
+
 (defun notmuch-poll ()
   "Run \"notmuch new\" or an external script to import mail.
 
@@ -287,6 +297,8 @@ (defun notmuch-bury-or-kill-this-buffer ()
       (bury-buffer)
     (kill-buffer)))
 
+;;; Describe Key Bindings
+
 (defun notmuch-prefix-key-description (key)
   "Given a prefix key code, return a human-readable string representation.
 
@@ -297,7 +309,6 @@ (defun notmuch-prefix-key-description (key)
 	"M-"
       (concat desc " "))))
 
-
 (defun notmuch-describe-key (actual-key binding prefix ua-keys tail)
   "Prepend cons cells describing prefix-arg ACTUAL-KEY and ACTUAL-KEY to TAIL.
 
@@ -435,6 +446,8 @@ (defun notmuch-subkeymap-help ()
 	  (insert desc)))
       (pop-to-buffer (help-buffer)))))
 
+;;; Refreshing Buffers
+
 (defvar-local notmuch-buffer-refresh-function nil
   "Function to call to refresh the current buffer.")
 
@@ -466,6 +479,8 @@ (defun notmuch-refresh-all-buffers ()
 	(with-current-buffer buffer
 	  (notmuch-refresh-this-buffer))))))
 
+;;; String Utilities
+
 (defun notmuch-prettify-subject (subject)
   ;; This function is used by `notmuch-search-process-filter' which
   ;; requires that we not disrupt its' matching state.
@@ -509,8 +524,6 @@ (defun notmuch-hex-encode (str)
   (replace-regexp-in-string
    "[ %\"]" (lambda (match) (format "%%%02x" (aref match 0))) str))
 
-;;
-
 (defun notmuch-common-do-stash (text)
   "Common function to stash text in kill ring, and display in minibuffer."
   (if text
@@ -522,7 +535,7 @@ (defun notmuch-common-do-stash (text)
     (kill-new "")
     (message "Nothing to stash!")))
 
-;;
+;;; Generic Utilities
 
 (defun notmuch-plist-delete (plist property)
   (let* ((xplist (cons nil plist))
@@ -533,6 +546,8 @@ (defun notmuch-plist-delete (plist property)
       (setq pred (cddr pred)))
     (cdr xplist)))
 
+;;; MML Utilities
+
 (defun notmuch-match-content-type (t1 t2)
   "Return t if t1 and t2 are matching content types, taking wildcards into account."
   (let ((st1 (split-string t1 "/"))
@@ -673,6 +688,8 @@ (defun notmuch-mm-display-part-inline (msg part content-type process-crypto)
 	    (mm-display-part handle)
 	    t))))))
 
+;;; Generic Utilities
+
 ;; Converts a plist of headers to an alist of headers. The input plist should
 ;; have symbols of the form :Header as keys, and the resulting alist will have
 ;; symbols of the form 'Header as keys.
@@ -739,6 +756,8 @@ (defun notmuch-map-text-property (start end prop func &optional object)
       (put-text-property start next prop (funcall func value) object)
       (setq start next))))
 
+;;; Running Notmuch
+
 (defun notmuch-logged-error (msg &optional extra)
   "Log MSG and EXTRA to *Notmuch errors* and signal MSG.
 
@@ -967,6 +986,8 @@ (defun notmuch-start-notmuch-error-sentinel (proc event)
 
 (defvar-local notmuch-show-process-crypto nil)
 
+;;; Generic Utilities
+
 (defun notmuch-interactive-region ()
   "Return the bounds of the current interactive region.
 
@@ -981,6 +1002,8 @@ (define-obsolete-function-alias
   'notmuch-interactive-region
   "notmuch 0.29")
 
+;;; _
+
 (provide 'notmuch-lib)
 
 ;;; notmuch-lib.el ends here
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 32b8100e..5de03cc2 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -29,6 +29,8 @@ (require 'notmuch-lib)
 
 (defvar notmuch-maildir-fcc-count 0)
 
+;;; Options
+
 (defcustom notmuch-fcc-dirs "sent"
   "Determines the Fcc Header which says where to save outgoing mail.
 
@@ -83,8 +85,7 @@ (defcustom notmuch-maildir-use-notmuch-insert t
 		 (const :tag "Use simple fcc" nil))
   :group 'notmuch-send)
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions which set up the fcc header in the message buffer.
+;;; Functions which set up the fcc header in the message buffer.
 
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
@@ -142,9 +143,7 @@ (defun notmuch-maildir-add-file-style-fcc-header (subdir)
 		subdir
 	      (concat (notmuch-database-path) "/" subdir))))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions for saving a message either using notmuch insert or file
-;; fcc. First functions common to the two cases.
+;;; Functions for saving a message using either method.
 
 (defmacro with-temporary-notmuch-message-buffer (&rest body)
   "Set-up a temporary copy of the current message-mode buffer."
@@ -204,8 +203,7 @@ (defun notmuch-fcc-handler (fcc-header)
       (notmuch-maildir-fcc-with-notmuch-insert fcc-header)
     (notmuch-maildir-fcc-file-fcc fcc-header)))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions for saving a message using notmuch insert.
+;;; Functions for saving a message using notmuch insert.
 
 (defun notmuch-maildir-notmuch-insert-current-buffer (folder &optional create tags)
   "Use notmuch insert to put the current buffer in the database.
@@ -251,9 +249,7 @@ (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
 	   (?e (notmuch-maildir-fcc-with-notmuch-insert
 		(read-from-minibuffer "Fcc header: " fcc-header)))))))))
 
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions for saving a message using file fcc.
+;;; Functions for saving a message using file fcc.
 
 (defun notmuch-maildir-fcc-host-fixer (hostname)
   (replace-regexp-in-string "/\\|:"
@@ -362,6 +358,8 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
 	  (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
+;;; _
+
 (provide 'notmuch-maildir-fcc)
 
 ;;; notmuch-maildir-fcc.el ends here
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index c38cb5aa..6fe5f6d0 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -38,7 +38,7 @@ (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
 (declare-function notmuch-draft-postpone "notmuch-draft" ())
 (declare-function notmuch-draft-save "notmuch-draft" ())
 
-;;
+;;; Options
 
 (defcustom notmuch-mua-send-hook nil
   "Hook run before sending messages."
@@ -120,7 +120,7 @@ (defcustom notmuch-mua-attachment-regexp
   :type 'regexp
   :group 'notmuch-send)
 
-;;
+;;; Various functions
 
 (defun notmuch-mua-attachment-check ()
   "Signal an error if the message text indicates that an
@@ -215,6 +215,8 @@ (defun notmuch-mua-insert-references (original-func header references)
   (funcall original-func header references)
   (unless (bolp) (insert "\n")))
 
+;;; Mua reply
+
 (defun notmuch-mua-reply (query-string &optional sender reply-all)
   (let ((args '("reply" "--format=sexp" "--format-version=4"))
 	(process-crypto notmuch-show-process-crypto)
@@ -318,6 +320,8 @@ (defun notmuch-mua-reply (query-string &optional sender reply-all)
   (message-goto-body)
   (set-buffer-modified-p nil))
 
+;;; Mode and keymap
+
 (defvar notmuch-message-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
@@ -333,6 +337,8 @@ (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
 
 (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
 
+;;; New messages
+
 (defun notmuch-mua-pop-to-buffer (name switch-function)
   "Pop to buffer NAME, and warn if it already exists and is modified.
 Like `message-pop-to-buffer' but enable `notmuch-message-mode'
@@ -528,6 +534,8 @@ (defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all
     (notmuch-mua-reply query-string sender reply-all)
     (deactivate-mark)))
 
+;;; Checks
+
 (defun notmuch-mua-check-no-misplaced-secure-tag ()
   "Query user if there is a misplaced secure mml tag.
 
@@ -570,6 +578,8 @@ (defun notmuch-mua-check-secure-tag-has-newline ()
 newline. It is likely that the message will be sent unsigned and
 unencrypted.  Really send? "))))
 
+;;; Finishing commands
+
 (defun notmuch-mua-send-common (arg &optional exit)
   (interactive "P")
   (run-hooks 'notmuch-mua-send-hook)
@@ -593,7 +603,7 @@ (defun notmuch-mua-kill-buffer ()
   (interactive)
   (message-kill-buffer))
 
-;;
+;;; _
 
 (define-mail-user-agent 'notmuch-user-agent
   'notmuch-mua-mail 'notmuch-mua-send-and-exit
@@ -603,8 +613,6 @@ (define-mail-user-agent 'notmuch-user-agent
 ;; composing a message.
 (notmuch-mua-add-more-hidden-headers)
 
-;;
-
 (provide 'notmuch-mua)
 
 ;;; notmuch-mua.el ends here
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 6dd9f775..d7b2fcce 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -25,6 +25,8 @@ (require 'notmuch-lib)
 
 (declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
 
+;;; Options
+
 (defcustom notmuch-print-mechanism 'notmuch-print-lpr
   "How should printing be done?"
   :group 'notmuch-show
@@ -36,7 +38,7 @@ (defcustom notmuch-print-mechanism 'notmuch-print-lpr
 	  (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
 	  (function :tag "Using a custom function")))
 
-;; Utility functions:
+;;; Utility functions
 
 (defun notmuch-print-run-evince (file)
   "View FILE using 'evince'."
@@ -54,7 +56,7 @@ (defun notmuch-print-run-muttprint (&optional output)
 	 "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
 	 output))
 
-;; User-visible functions:
+;;; User-visible functions
 
 (defun notmuch-print-lpr (msg)
   "Print a message buffer using lpr."
@@ -91,6 +93,8 @@ (defun notmuch-print-message (msg)
   (set-buffer-modified-p nil)
   (funcall notmuch-print-mechanism msg))
 
+;;; _
+
 (provide 'notmuch-print)
 
 ;;; notmuch-print.el ends here
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 3cfccbc3..72ddd2ce 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -23,6 +23,8 @@
 
 (require 'notmuch-lib)
 
+;;; Basic query function
+
 (defun notmuch-query-get-threads (search-terms)
   "Return a list of threads of messages matching SEARCH-TERMS.
 
@@ -35,8 +37,7 @@ (defun notmuch-query-get-threads (search-terms)
     (setq args (append args search-terms))
     (apply #'notmuch-call-notmuch-sexp args)))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Mapping functions across collections of messages.
+;;; Mapping functions across collections of messages
 
 (defun notmuch-query-map-aux  (mapper function seq)
   "Private function to do the actual mapping and flattening."
@@ -64,8 +65,7 @@ (defun notmuch-query-map-tree (fn tree)
 `notmuch-query-get-threads' for more information."
   (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Predefined queries
+;;; Predefined queries
 
 (defun notmuch-query-get-message-ids (&rest search-terms)
   "Return a list of message-ids of messages that match SEARCH-TERMS."
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 056c4e30..7dfbb327 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -59,6 +59,8 @@ (declare-function notmuch-unthreaded
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-draft-resume "notmuch-draft" (id))
 
+;;; Options
+
 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
   "Headers that should be shown in a message, in this order.
 
@@ -162,6 +164,8 @@ (defcustom notmuch-show-text/html-blocked-images "."
   :type '(choice (const nil) regexp)
   :group 'notmuch-show)
 
+;;; Variables
+
 (defvar-local notmuch-show-thread-id nil)
 
 (defvar-local notmuch-show-parent-buffer nil)
@@ -182,6 +186,8 @@ (defvar notmuch-show-attachment-debug nil
 each attachment handler is logged in buffers with names beginning
 \" *notmuch-part*\".")
 
+;;; Options
+
 (defcustom notmuch-show-stash-mlarchive-link-alist
   '(("Gmane" . "https://mid.gmane.org/")
     ("MARC" . "https://marc.info/?i=")
@@ -260,6 +266,8 @@ (defcustom notmuch-show-imenu-indent nil
   :type 'boolean
   :group 'notmuch-show)
 
+;;; Utilities
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message."
   `(save-excursion
@@ -275,6 +283,8 @@ (defun notmuch-show-turn-on-visual-line-mode ()
   "Enable Visual Line mode."
   (visual-line-mode t))
 
+;;; Commands
+
 ;; DEPRECATED in Notmuch 0.16 since we now have convenient part
 ;; commands.  We'll keep the command around for a version or two in
 ;; case people want to bind it themselves.
@@ -355,6 +365,8 @@ (defun notmuch-show-print-message ()
   (interactive)
   (notmuch-show-with-message-as-text 'notmuch-print-message))
 
+;;; Headers
+
 (defun notmuch-show-fontify-header ()
   (let ((face (cond
 	       ((looking-at "[Tt]o:")
@@ -493,6 +505,8 @@ (defun notmuch-show-insert-headers (headers)
 	(narrow-to-region start (point-max))
 	(run-hooks 'notmuch-show-markup-headers-hook)))))
 
+;;; Parts
+
 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
   'follow-link t
@@ -548,7 +562,7 @@ (defun notmuch-show-toggle-part-invisibility (&optional button)
 	      (overlay-put overlay 'invisible (not show))
 	      t)))))))
 
-;; Part content ID handling
+;;; Part content ID handling
 
 (defvar notmuch-show--cids nil
   "Alist from raw content ID to (MSG PART).")
@@ -811,7 +825,8 @@ (defun notmuch-show-insert-part-text/html (msg part content-type nth depth butto
 	  (gnus-blocked-images notmuch-show-text/html-blocked-images))
       (notmuch-show-insert-part-*/* msg part content-type nth depth button))))
 
-;; These functions are used by notmuch-show--insert-part-text/html-shr
+;;; Functions used by notmuch-show--insert-part-text/html-shr
+
 (declare-function libxml-parse-html-region "xml.c")
 (declare-function shr-insert-document "shr")
 
@@ -836,7 +851,7 @@ (defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)
   (notmuch-mm-display-part-inline msg part content-type notmuch-show-process-crypto)
   t)
 
-;; Functions for determining how to handle MIME parts.
+;;; Functions for determining how to handle MIME parts.
 
 (defun notmuch-show-handlers-for (content-type)
   "Return a list of content handlers for a part of type CONTENT-TYPE."
@@ -852,7 +867,7 @@ (defun notmuch-show-handlers-for (content-type)
 		(intern (concat "notmuch-show-insert-part-" content-type))))
     result))
 
-;; \f
+;;; Parts
 
 (defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button)
   ;; Run the handlers until one of them succeeds.
@@ -1098,6 +1113,8 @@ (defun notmuch-show-insert-msg (msg depth)
     (notmuch-show-message-visible msg (and (plist-get msg :match)
 					   (not (plist-get msg :excluded))))))
 
+;;; Toggle commands
+
 (defun notmuch-show-toggle-process-crypto ()
   "Toggle the processing of cryptographic MIME parts."
   (interactive)
@@ -1126,6 +1143,8 @@ (defun notmuch-show-toggle-thread-indentation ()
 	     "Content is not indented."))
   (notmuch-show-refresh-view))
 
+;;; Main insert functions
+
 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -1143,6 +1162,8 @@ (defun notmuch-show-insert-forest (forest)
   "Insert the forest of threads FOREST."
   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
 
+;;; Link buttons
+
 (defvar notmuch-id-regexp
   (concat
    ;; Match the id: prefix only if it begins a word (to disallow, for
@@ -1203,6 +1224,8 @@ (defun notmuch-show-buttonise-links (start end)
 			  'help-echo "Mouse-1, RET: search for this message"
 			  'face goto-address-mail-face)))))
 
+;;; Show command
+
 ;;;###autoload
 (defun notmuch-show (thread-id &optional elide-toggle parent-buffer query-context buffer-name)
   "Run \"notmuch show\" with the given thread ID and display results.
@@ -1325,6 +1348,8 @@ (defun notmuch-show--build-buffer (&optional state)
     ;; Report back to the caller whether any messages matched.
     forest))
 
+;;; Refresh command
+
 (defun notmuch-show-capture-state ()
   "Capture the state of the current buffer.
 
@@ -1399,6 +1424,8 @@ (defun notmuch-show-refresh-view (&optional reset-state)
       (ding)
       (message "Refreshing the buffer resulted in no messages!"))))
 
+;;; Keymaps
+
 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
     (define-key map "c" 'notmuch-show-stash-cc)
@@ -1479,6 +1506,8 @@ (defvar notmuch-show-mode-map
     map)
   "Keymap for \"notmuch show\" buffers.")
 
+;;; Mode
+
 (define-derived-mode notmuch-show-mode fundamental-mode "notmuch-show"
   "Major mode for viewing a thread with notmuch.
 
@@ -1515,6 +1544,8 @@ (define-derived-mode notmuch-show-mode fundamental-mode "notmuch-show"
   (setq imenu-extract-index-name-function
 	#'notmuch-show-imenu-extract-index-name-function))
 
+;;; Tree commands
+
 (defun notmuch-tree-from-show-current-query ()
   "Call notmuch tree with the current query."
   (interactive)
@@ -1529,17 +1560,14 @@ (defun notmuch-unthreaded-from-show-current-query ()
 		      notmuch-show-query-context
 		      (notmuch-show-get-message-id)))
 
+;;; Movement related functions.
+
 (defun notmuch-show-move-to-message-top ()
   (goto-char (notmuch-show-message-top)))
 
 (defun notmuch-show-move-to-message-bottom ()
   (goto-char (notmuch-show-message-bottom)))
 
-(defun notmuch-show-message-adjust ()
-  (recenter 0))
-
-;; Movement related functions.
-
 ;; There's some strangeness here where a text property applied to a
 ;; region a->b is not found when point is at b. We walk backwards
 ;; until finding the property.
@@ -1583,8 +1611,7 @@ (defun notmuch-show-mapc (function)
     (cl-loop do (funcall function)
 	     while (notmuch-show-goto-message-next))))
 
-;; Functions relating to the visibility of messages and their
-;; components.
+;;; Functions relating to the visibility of messages and their components.
 
 (defun notmuch-show-message-visible (props visible-p)
   (overlay-put (plist-get props :message-overlay) 'invisible (not visible-p))
@@ -1594,8 +1621,7 @@ (defun notmuch-show-headers-visible (props visible-p)
   (overlay-put (plist-get props :headers-overlay) 'invisible (not visible-p))
   (notmuch-show-set-prop :headers-visible visible-p props))
 
-;; Functions for setting and getting attributes of the current
-;; message.
+;;; Functions for setting and getting attributes of the current message.
 
 (defun notmuch-show-set-message-properties (props)
   (save-excursion
@@ -1768,8 +1794,7 @@ (defun notmuch-show-filter-thread (query)
     (notmuch-show-refresh-view t)
     (notmuch-show-goto-message msg-id)))
 
-;; Functions for getting attributes of several messages in the current
-;; thread.
+;;; Functions for getting attributes of several messages in the current thread.
 
 (defun notmuch-show-get-message-ids-for-open-messages ()
   "Return a list of all id: queries for open messages in the current thread."
@@ -1783,7 +1808,7 @@ (defun notmuch-show-get-message-ids-for-open-messages ()
 	(setq done (not (notmuch-show-goto-message-next))))
       message-ids)))
 
-;; Commands typically bound to keys.
+;;; Commands typically bound to keys.
 
 (defun notmuch-show-advance ()
   "Advance through thread.
@@ -1911,6 +1936,9 @@ (defun notmuch-show-resend-message (addresses)
     (message-resend addresses)
     (notmuch-bury-or-kill-this-buffer)))
 
+(defun notmuch-show-message-adjust ()
+  (recenter 0))
+
 (defun notmuch-show-next-message (&optional pop-at-end)
   "Show the next message.
 
@@ -2381,7 +2409,7 @@ (defun notmuch-show-stash-git-send-email (&optional no-in-reply-to)
 			  (list (notmuch-show-get-message-id t)) "--in-reply-to="))))
 	      " ")))
 
-;; Interactive part functions and their helpers
+;;; Interactive part functions and their helpers
 
 (defun notmuch-show-generate-part-buffer (msg part)
   "Return a temporary buffer containing the specified part's content."
@@ -2528,6 +2556,8 @@ (defun notmuch-show-browse-urls (&optional kill)
 	(funcall fn (completing-read prompt urls nil nil nil nil (car urls)))
       (message "No URLs found."))))
 
+;;; _
+
 (provide 'notmuch-show)
 
 ;;; notmuch-show.el ends here
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 925de78c..817ea99f 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -37,6 +37,8 @@ (declare-function notmuch-show-tag "notmuch-show" (tag-changes))
 (declare-function notmuch-tree-tag "notmuch-tree" (tag-changes))
 (declare-function notmuch-jump "notmuch-jump" (action-map prompt))
 
+;;; Keys
+
 (define-widget 'notmuch-tag-key-type 'list
   "A single key tagging binding."
   :format "%v"
@@ -84,6 +86,8 @@ (defcustom notmuch-tagging-keys
   :type '(repeat notmuch-tag-key-type)
   :group 'notmuch-tag)
 
+;;; Faces and Formats
+
 (define-widget 'notmuch-tag-format-type 'lazy
   "Customize widget for notmuch-tag-format and friends."
   :type '(alist :key-type (regexp :tag "Tag")
@@ -217,6 +221,8 @@ (defcustom notmuch-tag-added-formats
   :group 'notmuch-faces
   :type 'notmuch-tag-format-type)
 
+;;; Icons
+
 (defun notmuch-tag-format-image-data (tag data)
   "Replace TAG with image DATA, if available.
 
@@ -270,6 +276,8 @@ (defun notmuch-tag-tag-icon ()
   </g>
 </svg>")
 
+;;; Format Handling
+
 (defvar notmuch-tag--format-cache (make-hash-table :test 'equal)
   "Cache of tag format lookup.  Internal to `notmuch-tag-format-tag'.")
 
@@ -347,6 +355,8 @@ (defun notmuch-tag-format-tags (tags orig-tags &optional face)
      face
      t)))
 
+;;; Hooks
+
 (defcustom notmuch-before-tag-hook nil
   "Hooks that are run before tags of a message are modified.
 
@@ -369,6 +379,8 @@ (defcustom notmuch-after-tag-hook nil
   :options '(notmuch-hl-line-mode)
   :group 'notmuch-hooks)
 
+;;; User Input
+
 (defvar notmuch-select-tag-history nil
   "Variable to store minibuffer history for
 `notmuch-select-tag-with-completion' function.")
@@ -429,6 +441,8 @@ (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
 		nil nil initial-input
 		'notmuch-read-tag-changes-history))))
 
+;;; Tagging
+
 (defun notmuch-update-tags (tags tag-changes)
   "Return a copy of TAGS with additions and removals from TAG-CHANGES.
 
@@ -547,7 +561,7 @@ (defun notmuch-tag-jump (reverse)
     (setq action-map (nreverse action-map))
     (notmuch-jump action-map "Tag: ")))
 
-;;
+;;; _
 
 (provide 'notmuch-tag)
 
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 17863f6a..713b00da 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -54,6 +54,8 @@ (defvar notmuch-search-query-string)
 (defvar-local notmuch-tree-unthreaded nil
   "A buffer local copy of argument unthreaded to the function notmuch-tree.")
 
+;;; Options
+
 (defgroup notmuch-tree nil
   "Showing message and thread structure."
   :group 'notmuch)
@@ -118,7 +120,9 @@ (defun notmuch-tree-result-format ()
       notmuch-unthreaded-result-format
     notmuch-tree-result-format))
 
-;; Faces for messages that match the query.
+;;; Faces
+;;;; Faces for messages that match the query
+
 (defface notmuch-tree-match-face
   '((t :inherit default))
   "Default face used in tree mode face for matching messages"
@@ -169,7 +173,8 @@ (defface notmuch-tree-match-tag-face
   :group 'notmuch-tree
   :group 'notmuch-faces)
 
-;; Faces for messages that do not match the query.
+;;;; Faces for messages that do not match the query
+
 (defface notmuch-tree-no-match-face
   '((t (:foreground "gray")))
   "Default face used in tree mode face for non-matching messages."
@@ -206,6 +211,8 @@ (defface notmuch-tree-no-match-tag-face
   :group 'notmuch-tree
   :group 'notmuch-faces)
 
+;;; Variables
+
 (defvar-local notmuch-tree-previous-subject
   "The subject of the most recent result shown during the async display.")
 
@@ -238,6 +245,8 @@ (defvar-local notmuch-tree-message-buffer nil
 if the user has loaded a different buffer in that window.")
 (put 'notmuch-tree-message-buffer 'permanent-local t)
 
+;;; Tree wrapper commands
+
 (defmacro notmuch-tree--define-do-in-message-window (name cmd)
   "Define NAME as a command that calls CMD interactively in the message window.
 If the message pane is closed then this command does nothing.
@@ -305,6 +314,8 @@ (notmuch-tree--define-close-message-window-and
  notmuch-tree-view-raw-message
  notmuch-show-view-raw-message)
 
+;;; Keymap
+
 (defvar notmuch-tree-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
@@ -363,6 +374,8 @@ (defvar notmuch-tree-mode-map
     map)
   "Keymap for \"notmuch tree\" buffers.")
 
+;;; Message properties
+
 (defun notmuch-tree-get-message-properties ()
   "Return the properties of the current message as a plist.
 
@@ -414,6 +427,8 @@ (defun notmuch-tree-get-match ()
   (interactive)
   (notmuch-tree-get-prop :match))
 
+;;; Update display
+
 (defun notmuch-tree-refresh-result ()
   "Redisplay the current message line.
 
@@ -456,6 +471,8 @@ (defun notmuch-tree-tag-update-display (&optional tag-changes)
 	  (when (string= tree-msg-id (notmuch-show-get-message-id))
 	    (notmuch-show-update-tags new-tags)))))))
 
+;;; Commands (and some helper functions used by them)
+
 (defun notmuch-tree-tag (tag-changes)
   "Change tags for the current message."
   (interactive
@@ -835,7 +852,7 @@ (defun notmuch-tree-archive-thread (&optional unarchive)
     (notmuch-tree-tag-thread
      (notmuch-tag-change-list notmuch-archive-tags unarchive))))
 
-;; Functions below here display the tree buffer itself.
+;;; Functions for displaying the tree buffer itself
 
 (defun notmuch-tree-clean-address (address)
   "Try to clean a single email ADDRESS for display. Return
@@ -1142,7 +1159,7 @@ (defun notmuch-unthreaded (&optional query query-context target buffer-name open
   (interactive)
   (notmuch-tree query query-context target buffer-name open-target t))
 
-;;
+;;; _
 
 (provide 'notmuch-tree)
 
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index ce4b9637..f371cc4c 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -30,7 +30,7 @@ (declare-function notmuch-show-insert-bodypart "notmuch-show"
 		  (msg part depth &optional hide))
 (defvar notmuch-show-indent-messages-width)
 
-;;
+;;; Options
 
 (defgroup notmuch-wash nil
   "Cleaning up messages for display."
@@ -130,6 +130,8 @@ (defcustom notmuch-wash-wrap-lines-length nil
 		 (integer :tag "number of characters"))
   :group 'notmuch-wash)
 
+;;; Faces
+
 (defface notmuch-wash-toggle-button
   '((t (:inherit font-lock-comment-face)))
   "Face used for buttons toggling the visibility of washed away
@@ -143,6 +145,8 @@ (defface notmuch-wash-cited-text
   :group 'notmuch-wash
   :group 'notmuch-faces)
 
+;;; Buttons
+
 (defun notmuch-wash-toggle-invisible-action (cite-button)
   ;; Toggle overlay visibility
   (let ((overlay (button-get cite-button 'overlay)))
@@ -225,6 +229,8 @@ (defun notmuch-wash-region-to-button (msg beg end type &optional prefix)
 				   :type button-type)))
 	  (overlay-put overlay 'notmuch-wash-button button))))))
 
+;;; Hook functions
+
 (defun notmuch-wash-excerpt-citations (msg depth)
   "Excerpt citations and up to one signature."
   (goto-char (point-min))
@@ -270,8 +276,6 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	   msg sig-start-marker sig-end-marker
 	   "signature"))))))
 
-;;
-
 (defun notmuch-wash-elide-blank-lines (msg depth)
   "Elide leading, trailing and successive blank lines."
   ;; Algorithm derived from `article-strip-multiple-blank-lines' in
@@ -293,8 +297,6 @@ (defun notmuch-wash-elide-blank-lines (msg depth)
   (when (looking-at "\n")
     (delete-region (match-beginning 0) (match-end 0))))
 
-;;
-
 (defun notmuch-wash-tidy-citations (msg depth)
   "Improve the display of cited regions of a message.
 
@@ -319,8 +321,6 @@ (defun notmuch-wash-tidy-citations (msg depth)
   (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
     (replace-match "\\2")))
 
-;;
-
 (defun notmuch-wash-wrap-long-lines (msg depth)
   "Wrap long lines in the message.
 
@@ -342,7 +342,7 @@ (defun notmuch-wash-wrap-long-lines (msg depth)
 			 2)))
     (coolj-wrap-region (point-min) (point-max))))
 
-;;
+;;;; Convert Inline Patches
 
 (require 'diff-mode)
 
@@ -417,7 +417,7 @@ (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
 	(delete-region (point-min) (point-max))
 	(notmuch-show-insert-bodypart nil part depth)))))
 
-;;
+;;; _
 
 (provide 'notmuch-wash)
 
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index b221be05..fb042545 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -80,6 +80,8 @@ (require 'notmuch-maildir-fcc)
 (require 'notmuch-message)
 (require 'notmuch-parser)
 
+;;; Options
+
 (defcustom notmuch-search-result-format
   `(("date" . "%12s ")
     ("count" . "%-7s ")
@@ -115,6 +117,8 @@ (defcustom notmuch-init-file (locate-user-emacs-file "notmuch-config")
 (defvar notmuch-query-history nil
   "Variable to store minibuffer history for notmuch queries.")
 
+;;; Mime Utilities
+
 (defun notmuch-foreach-mime-part (function mm-handle)
   (cond ((stringp (car mm-handle))
 	 (dolist (part (cdr mm-handle))
@@ -151,6 +155,8 @@ (defun notmuch-save-attachments (mm-handle &optional queryp)
 	    (mm-save-part p))))
    mm-handle))
 
+;;; Integrations
+
 (require 'hl-line)
 
 (defun notmuch-hl-line-mode ()
@@ -158,6 +164,8 @@ (defun notmuch-hl-line-mode ()
     (when hl-line-overlay
       (overlay-put hl-line-overlay 'priority 1))))
 
+;;; Options
+
 (defcustom notmuch-search-hook '(notmuch-hl-line-mode)
   "List of functions to call when notmuch displays the search results."
   :type 'hook
@@ -165,6 +173,8 @@ (defcustom notmuch-search-hook '(notmuch-hl-line-mode)
   :group 'notmuch-search
   :group 'notmuch-hooks)
 
+;;; Keymap
+
 (defvar notmuch-search-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
@@ -195,6 +205,8 @@ (defvar notmuch-search-mode-map
     map)
   "Keymap for \"notmuch search\" buffers.")
 
+;;; Stashing
+
 (defvar notmuch-search-stash-map
   (let ((map (make-sparse-keymap)))
     (define-key map "i" 'notmuch-search-stash-thread-id)
@@ -214,12 +226,16 @@ (defun notmuch-stash-query ()
   (interactive)
   (notmuch-common-do-stash (notmuch-search-get-query)))
 
+;;; Variables
+
 (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
 (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")
 
+;;; Movement
+
 (defun notmuch-search-scroll-up ()
   "Move forward through search results by one window's worth."
   (interactive)
@@ -271,6 +287,8 @@ (defun notmuch-search-first-thread ()
   (interactive)
   (goto-char (point-min)))
 
+;;; Faces
+
 (defface notmuch-message-summary-face
   `((((class color) (background light))
      ,@(and (>= emacs-major-version 27) '(:extend t))
@@ -356,6 +374,8 @@ (defface notmuch-search-unread-face
   :group 'notmuch-search
   :group 'notmuch-faces)
 
+;;; Mode
+
 (define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
   "Major mode displaying results of a notmuch search.
 
@@ -400,6 +420,8 @@ (define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
   (setq imenu-extract-index-name-function
 	#'notmuch-search-imenu-extract-index-name-function))
 
+;;; Search Results
+
 (defun notmuch-search-get-result (&optional pos)
   "Return the result object for the thread at POS (or point).
 
@@ -558,6 +580,8 @@ (defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
   (let ((message-id (notmuch-search-find-thread-id)))
     (notmuch-mua-new-reply message-id prompt-for-sender nil)))
 
+;;; Tags
+
 (defun notmuch-search-set-tags (tags &optional pos)
   (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))
     (notmuch-search-update-result new-result pos)))
@@ -639,6 +663,8 @@ (defun notmuch-search-archive-thread (&optional unarchive beg end)
   (when (eq beg end)
     (notmuch-search-next-thread)))
 
+;;; Search Results
+
 (defun notmuch-search-update-result (result &optional pos)
   "Replace the result object of the thread at POS (or point) by
 RESULT and redraw it.
@@ -881,6 +907,8 @@ (defun notmuch-search-process-filter (proc string)
 	(notmuch-sexp-parse-partial-list 'notmuch-search-append-result
 					 results-buf)))))
 
+;;; Commands (and some helper functions used by them)
+
 (defun notmuch-search-tag-all (tag-changes)
   "Add/remove tags from all messages in current search buffer.
 
@@ -1136,7 +1164,7 @@ (defun notmuch-cycle-notmuch-buffers ()
 	  (pop-to-buffer-same-window first))
       (notmuch))))
 
-;;;; Imenu Support
+;;; Imenu Support
 
 (defun notmuch-search-imenu-prev-index-position-function ()
   "Move point to previous message in notmuch-search buffer.
@@ -1153,6 +1181,8 @@ (defun notmuch-search-imenu-extract-index-name-function ()
 	(author (notmuch-search-find-authors)))
     (format "%s (%s)" subject author)))
 
+;;; _
+
 (setq mail-user-agent 'notmuch-user-agent)
 
 (provide 'notmuch)
diff --git a/test/test-lib.el b/test/test-lib.el
index ec16c59c..4de5b292 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -1,4 +1,4 @@
-;; test-lib.el --- auxiliary stuff for Notmuch Emacs tests.
+;;; test-lib.el --- auxiliary stuff for Notmuch Emacs tests
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
@@ -20,6 +20,8 @@
 ;;
 ;; Authors: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
 
+;;; Code:
+
 (require 'cl-lib)
 
 ;; Ensure that the dynamic variables that are defined by this library
-- 
2.29.1\r

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 11/32] emacs: use lexical-bindings in all libraries
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (9 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 10/32] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 12/32] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
                   ` (22 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/coolj.el               |  2 +-
 emacs/make-deps.el           |  2 +-
 emacs/notmuch-address.el     |  2 +-
 emacs/notmuch-compat.el      |  2 +-
 emacs/notmuch-crypto.el      |  2 +-
 emacs/notmuch-draft.el       |  2 +-
 emacs/notmuch-hello.el       |  2 +-
 emacs/notmuch-jump.el        |  2 +-
 emacs/notmuch-lib.el         |  2 +-
 emacs/notmuch-maildir-fcc.el |  2 +-
 emacs/notmuch-message.el     |  2 +-
 emacs/notmuch-mua.el         |  7 ++++++-
 emacs/notmuch-parser.el      |  2 +-
 emacs/notmuch-print.el       |  2 +-
 emacs/notmuch-query.el       |  2 +-
 emacs/notmuch-show.el        |  6 +++++-
 emacs/notmuch-tag.el         | 18 ++++++++++--------
 emacs/notmuch-tree.el        |  2 +-
 emacs/notmuch-wash.el        |  2 +-
 emacs/notmuch.el             |  2 +-
 emacs/rstdoc.el              |  2 +-
 21 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/emacs/coolj.el b/emacs/coolj.el
index b3e314f0..d820525b 100644
--- a/emacs/coolj.el
+++ b/emacs/coolj.el
@@ -1,4 +1,4 @@
-;;; coolj.el --- automatically wrap long lines  -*- coding:utf-8 -*-
+;;; coolj.el --- automatically wrap long lines  -*- lexical-binding: t; coding: utf-8 -*-
 
 ;; Copyright (C) 2000, 2001, 2004-2009 Free Software Foundation, Inc.
 
diff --git a/emacs/make-deps.el b/emacs/make-deps.el
index a7699fb1..8c9e0a27 100644
--- a/emacs/make-deps.el
+++ b/emacs/make-deps.el
@@ -1,4 +1,4 @@
-;;; make-deps.el --- compute make dependencies for Elisp sources
+;;; make-deps.el --- compute make dependencies for Elisp sources  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Austin Clements
 ;;
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index bf29c3a0..6b117458 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -1,4 +1,4 @@
-;;; notmuch-address.el --- address completion with notmuch
+;;; notmuch-address.el --- address completion with notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el
index c4e07780..ad134dfe 100644
--- a/emacs/notmuch-compat.el
+++ b/emacs/notmuch-compat.el
@@ -1,4 +1,4 @@
-;;; notmuch-compat.el --- compatibility functions for earlier versions of emacs
+;;; notmuch-compat.el --- compatibility functions for earlier versions of emacs  -*- lexical-binding: t -*-
 ;;
 ;; The functions in this file are copied from more modern versions of
 ;; emacs and are Copyright (C) 1985-1986, 1992, 1994-1995, 1999-2017
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 6d2d35a5..ee5231e5 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -1,4 +1,4 @@
-;;; notmuch-crypto.el --- functions for handling display of cryptographic metadata
+;;; notmuch-crypto.el --- functions for handling display of cryptographic metadata  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Jameson Rollins
 ;;
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 9ce9e736..8af04598 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -1,4 +1,4 @@
-;;; notmuch-draft.el --- functions for postponing and editing drafts
+;;; notmuch-draft.el --- functions for postponing and editing drafts  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Mark Walters
 ;; Copyright © David Bremner
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 28ffedd9..586a2848 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -1,4 +1,4 @@
-;;; notmuch-hello.el --- welcome to notmuch, a frontend
+;;; notmuch-hello.el --- welcome to notmuch, a frontend  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 7a27b6b3..5dcec970 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -1,4 +1,4 @@
-;;; notmuch-jump.el --- User-friendly shortcut keys
+;;; notmuch-jump.el --- User-friendly shortcut keys  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Austin Clements
 ;;
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0b698d59..7595bbe1 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -1,4 +1,4 @@
-;;; notmuch-lib.el --- common variables, functions and function declarations
+;;; notmuch-lib.el --- common variables, functions and function declarations  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;;
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 5de03cc2..e880653c 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -1,4 +1,4 @@
-;;; notmuch-maildir-fcc.el --- inserting using a fcc handler
+;;; notmuch-maildir-fcc.el --- inserting using a fcc handler  -*- lexical-binding: t -*-
 
 ;; Copyright © Jesse Rosenthal
 ;;
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index c2242070..f0e9ffcc 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -1,4 +1,4 @@
-;;; notmuch-message.el --- message-mode functions specific to notmuch
+;;; notmuch-message.el --- message-mode functions specific to notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Jesse Rosenthal
 ;;
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 6fe5f6d0..d50fdb26 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -1,4 +1,4 @@
-;;; notmuch-mua.el --- emacs style mail-user-agent
+;;; notmuch-mua.el --- emacs style mail-user-agent  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
@@ -38,6 +38,11 @@ (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
 (declare-function notmuch-draft-postpone "notmuch-draft" ())
 (declare-function notmuch-draft-save "notmuch-draft" ())
 
+(defvar notmuch-show-indent-multipart)
+(defvar notmuch-show-insert-header-p-function)
+(defvar notmuch-show-max-text-part-size)
+(defvar notmuch-show-insert-text/plain-hook)
+
 ;;; Options
 
 (defcustom notmuch-mua-send-hook nil
diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index 4a437016..b8c3fd2c 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -1,4 +1,4 @@
-;;; notmuch-parser.el --- streaming S-expression parser
+;;; notmuch-parser.el --- streaming S-expression parser  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Austin Clements
 ;;
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index d7b2fcce..8da9a091 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -1,4 +1,4 @@
-;;; notmuch-print.el --- printing messages from notmuch
+;;; notmuch-print.el --- printing messages from notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 72ddd2ce..ffce8814 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -1,4 +1,4 @@
-;;; notmuch-query.el --- provide an emacs api to query notmuch
+;;; notmuch-query.el --- provide an emacs api to query notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Bremner
 ;;
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7dfbb327..72e21d94 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1,4 +1,4 @@
-;;; notmuch-show.el --- displaying notmuch forests
+;;; notmuch-show.el --- displaying notmuch forests  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
@@ -59,6 +59,10 @@ (declare-function notmuch-unthreaded
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-draft-resume "notmuch-draft" (id))
 
+(defvar shr-blocked-images)
+(defvar gnus-blocked-images)
+(defvar shr-content-function)
+
 ;;; Options
 
 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 817ea99f..fa376b02 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -1,4 +1,4 @@
-;;; notmuch-tag.el --- tag messages within emacs
+;;; notmuch-tag.el --- tag messages within emacs  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Damien Cassou
 ;; Copyright © Carl Worth
@@ -295,22 +295,24 @@ (defun notmuch-tag--get-formats (tag format-alist)
 		      (and (eq (string-match key tag) 0)
 			   (= (match-end 0) (length tag)))))))
 
-(defun notmuch-tag--do-format (tag formatted-tag formats)
+(defun notmuch-tag--do-format (bare-tag tag formats)
   "Apply a tag-formats entry to TAG."
   (cond ((null formats)		;; - Tag not in `formats',
-	 formatted-tag)	       	;;   the format is the tag itself.
+	 tag)			;;   the format is the tag itself.
 	((null (cdr formats))	;; - Tag was deliberately hidden,
 	 nil)			;;   no format must be returned
 	(t
 	 ;; Tag was found and has formats, we must apply all the
 	 ;; formats.  TAG may be null so treat that as a special case.
-	 (let ((bare-tag tag)
-	       (tag (copy-sequence (or formatted-tag ""))))
+	 (let ((return-tag (copy-sequence (or tag ""))))
 	   (dolist (format (cdr formats))
-	     (setq tag (eval format)))
-	   (if (and (null formatted-tag) (equal tag ""))
+	     (setq return-tag
+		   (eval format
+			 `((bare-tag . ,bare-tag)
+			   (tag . ,return-tag)))))
+	   (if (and (null tag) (equal return-tag ""))
 	       nil
-	     tag)))))
+	     return-tag)))))
 
 (defun notmuch-tag-format-tag (tags orig-tags tag)
   "Format TAG according to `notmuch-tag-formats'.
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 713b00da..1ed34801 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1,4 +1,4 @@
-;;; notmuch-tree.el --- displaying notmuch forests
+;;; notmuch-tree.el --- displaying notmuch forests  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index f371cc4c..70eff637 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -1,4 +1,4 @@
-;;; notmuch-wash.el --- cleaning up message bodies
+;;; notmuch-wash.el --- cleaning up message bodies  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index fb042545..9c06ad72 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -1,4 +1,4 @@
-;;; notmuch.el --- run notmuch within emacs
+;;; notmuch.el --- run notmuch within emacs  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;;
diff --git a/emacs/rstdoc.el b/emacs/rstdoc.el
index 4221f142..c7c13015 100644
--- a/emacs/rstdoc.el
+++ b/emacs/rstdoc.el
@@ -1,4 +1,4 @@
-;;; rstdoc.el --- help generate documentation from docstrings -*-lexical-binding: t-*-
+;;; rstdoc.el --- help generate documentation from docstrings  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2018 David Bremner
 
-- 
2.29.1\r

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 12/32] emacs: deal with unused lexical arguments and variables
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (10 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 11/32] emacs: use lexical-bindings in all libraries Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 13/32] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
                   ` (21 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-address.el     |  4 ++--
 emacs/notmuch-crypto.el      |  2 +-
 emacs/notmuch-hello.el       | 16 +++++++--------
 emacs/notmuch-jump.el        |  6 +++---
 emacs/notmuch-lib.el         |  2 +-
 emacs/notmuch-maildir-fcc.el |  4 ++--
 emacs/notmuch-mua.el         |  2 +-
 emacs/notmuch-print.el       |  6 +++---
 emacs/notmuch-show.el        | 38 ++++++++++++++++++------------------
 emacs/notmuch-tree.el        | 14 +++++--------
 emacs/notmuch-wash.el        | 16 +++++++--------
 emacs/notmuch.el             |  5 ++---
 12 files changed, 54 insertions(+), 61 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 6b117458..1017c3ce 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -191,7 +191,7 @@ (defun notmuch-address-matching (substring)
 The candidates are taken from `notmuch-address-completions'."
   (let ((candidates)
 	(re (regexp-quote substring)))
-    (maphash (lambda (key val)
+    (maphash (lambda (key _val)
 	       (when (string-match re key)
 		 (push key candidates)))
 	     notmuch-address-completions)
@@ -406,7 +406,7 @@ (defun notmuch-address-harvest-trigger ()
       (setq notmuch-address-last-harvest now)
       (notmuch-address-harvest
        nil nil
-       (lambda (proc event)
+       (lambda (_proc event)
 	 ;; If harvest fails, we want to try
 	 ;; again when the trigger is next
 	 ;; called
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index ee5231e5..50a3de46 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -171,7 +171,7 @@ (defun notmuch-crypto-sigstatus-good-callback (button)
 (declare-function notmuch-show-refresh-view "notmuch-show" (&optional reset-state))
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 
-(defun notmuch-crypto--async-key-sentinel (process event)
+(defun notmuch-crypto--async-key-sentinel (process _event)
   "When the user asks for a GPG key to be retrieved
 asynchronously, handle completion of that task.
 
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 586a2848..a134eb07 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -480,7 +480,7 @@ (defun notmuch-hello-reflect (list ncols)
     (cl-loop for row from 0 to (- nrows 1)
 	     append (notmuch-hello-reflect-generate-row ncols nrows row list))))
 
-(defun notmuch-hello-widget-search (widget &rest ignore)
+(defun notmuch-hello-widget-search (widget &rest _ignore)
   (cond
    ((eq (widget-get widget :notmuch-search-type) 'tree)
     (notmuch-tree (widget-get widget
@@ -775,14 +775,14 @@ (defun notmuch-hello-insert-header ()
   (let ((widget-link-prefix "")
 	(widget-link-suffix ""))
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (browse-url notmuch-hello-url))
 		   :help-echo "Visit the notmuch website."
 		   "notmuch")
     (widget-insert ". ")
     (widget-insert "You have ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (notmuch-hello-update))
 		   :help-echo "Refresh"
 		   (notmuch-hello-nice-number
@@ -801,7 +801,7 @@ (defun notmuch-hello-insert-saved-searches ()
     (when searches
       (widget-insert "Saved searches: ")
       (widget-create 'push-button
-		     :notify (lambda (&rest ignore)
+		     :notify (lambda (&rest _ignore)
 			       (customize-variable 'notmuch-saved-searches))
 		     "edit")
       (widget-insert "\n\n")
@@ -873,13 +873,13 @@ (defun notmuch-hello-insert-searches (title query-list &rest options)
 	(start (point)))
     (if is-hidden
 	(widget-create 'push-button
-		       :notify `(lambda (widget &rest ignore)
+		       :notify `(lambda (widget &rest _ignore)
 				  (setq notmuch-hello-hidden-sections
 					(delete ,title notmuch-hello-hidden-sections))
 				  (notmuch-hello-update))
 		       "show")
       (widget-create 'push-button
-		     :notify `(lambda (widget &rest ignore)
+		     :notify `(lambda (widget &rest _ignore)
 				(add-to-list 'notmuch-hello-hidden-sections
 					     ,title)
 				(notmuch-hello-update))
@@ -928,13 +928,13 @@ (defun notmuch-hello-insert-footer ()
     (widget-insert "Hit `?' for context-sensitive help in any Notmuch screen.\n")
     (widget-insert "Customize ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (customize-group 'notmuch))
 		   :button-prefix "" :button-suffix ""
 		   "Notmuch")
     (widget-insert " or ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (customize-variable 'notmuch-hello-sections))
 		   :button-prefix "" :button-suffix ""
 		   "this page.")
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 5dcec970..51bc4e31 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -120,7 +120,7 @@ (defun notmuch-jump--format-actions (action-map)
 buffer."
   ;; Compute the maximum key description width
   (let ((key-width 1))
-    (pcase-dolist (`(,key ,desc) action-map)
+    (pcase-dolist (`(,key ,_desc) action-map)
       (setq key-width
 	    (max key-width
 		 (string-width (format-kbd-macro key)))))
@@ -164,7 +164,7 @@ (defun notmuch-jump--make-keymap (action-map prompt)
   "Translate ACTION-MAP into a minibuffer keymap."
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-jump-minibuffer-map)
-    (pcase-dolist (`(,key ,name ,fn) action-map)
+    (pcase-dolist (`(,key ,_name ,fn) action-map)
       (when (= (length key) 1)
 	(define-key map key
 	  `(lambda () (interactive)
@@ -173,7 +173,7 @@ (defun notmuch-jump--make-keymap (action-map prompt)
     ;; By doing this in two passes (and checking if we already have a
     ;; binding) we avoid problems if the user specifies a binding which
     ;; is a prefix of another binding.
-    (pcase-dolist (`(,key ,name ,fn) action-map)
+    (pcase-dolist (`(,key ,_name ,_fn) action-map)
       (when (> (length key) 1)
 	(let* ((key (elt key 0))
 	       (keystr (string key))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 7595bbe1..1bdfc2b9 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -978,7 +978,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
        ;; so turn errors into messages.
        (message "%s" (error-message-string err))))))
 
-(defun notmuch-start-notmuch-error-sentinel (proc event)
+(defun notmuch-start-notmuch-error-sentinel (proc _event)
   (unless (process-live-p proc)
     (let ((buffer (process-buffer proc)))
       (when (buffer-live-p buffer)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index e880653c..9f09129d 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -346,12 +346,12 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
 	(let ((msg-id (notmuch-maildir-fcc-save-buffer-to-tmp destdir)))
 	  (when msg-id
 	    (cond (mark-seen
-		   (condition-case err
+		   (condition-case nil
 		       (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
 		     (file-already-exists
 		      (throw 'link-error nil))))
 		  (t
-		   (condition-case err
+		   (condition-case nil
 		       (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id)
 		     (file-already-exists
 		      (throw 'link-error nil))))))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index d50fdb26..b2930051 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -370,7 +370,7 @@ (defun notmuch-mua-pop-to-buffer (name switch-function)
     (erase-buffer)
     (notmuch-message-mode)))
 
-(defun notmuch-mua-mail (&optional to subject other-headers continue
+(defun notmuch-mua-mail (&optional to subject other-headers _continue
 				   switch-function yank-action send-actions
 				   return-action &rest ignored)
   "Invoke the notmuch mail composition window."
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 8da9a091..d0061499 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -58,7 +58,7 @@ (defun notmuch-print-run-muttprint (&optional output)
 
 ;;; User-visible functions
 
-(defun notmuch-print-lpr (msg)
+(defun notmuch-print-lpr (_msg)
   "Print a message buffer using lpr."
   (lpr-buffer))
 
@@ -78,11 +78,11 @@ (defun notmuch-print-ps-print/evince (msg)
     (ps-print-buffer ps-file)
     (notmuch-print-run-evince ps-file)))
 
-(defun notmuch-print-muttprint (msg)
+(defun notmuch-print-muttprint (_msg)
   "Print a message using muttprint."
   (notmuch-print-run-muttprint))
 
-(defun notmuch-print-muttprint/evince (msg)
+(defun notmuch-print-muttprint/evince (_msg)
   "Preview a message buffer using muttprint and evince."
   (let ((ps-file (make-temp-file "notmuch" nil ".ps")))
     (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 72e21d94..48374b38 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -517,7 +517,7 @@ (define-button-type 'notmuch-show-part-button-type
   'face 'message-mml
   :supertype 'notmuch-button-type)
 
-(defun notmuch-show-insert-part-header (nth content-type declared-type
+(defun notmuch-show-insert-part-header (_nth content-type declared-type
 					    &optional name comment)
   (let ((base-label (concat (and name (concat name ": "))
 			    declared-type
@@ -624,7 +624,7 @@ (defun notmuch-show-setup-w3m ()
   (setq mm-html-inhibit-images nil))
 
 (defvar w3m-current-buffer) ;; From `w3m.el'.
-(defun notmuch-show--cid-w3m-retrieve (url &rest args)
+(defun notmuch-show--cid-w3m-retrieve (url &rest _args)
   ;; url includes the cid: prefix and is URL encoded (see RFC 2392).
   (let* ((cid (url-unhex-string (substring url 4)))
 	 (content-and-type
@@ -640,7 +640,7 @@ (defun notmuch-show-multipart/*-to-list (part)
   (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
 	  (plist-get part :content)))
 
-(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/alternative (msg part _content-type _nth depth _button)
   (let ((chosen-type (car (notmuch-multipart/alternative-choose
 			   msg (notmuch-show-multipart/*-to-list part))))
 	(inner-parts (plist-get part :content))
@@ -659,7 +659,7 @@ (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/related (msg part _content-type _nth depth _button)
   (let ((inner-parts (plist-get part :content))
 	(start (point)))
     ;; Render the primary part.  FIXME: Support RFC 2387 Start header.
@@ -672,7 +672,7 @@ (defun notmuch-show-insert-part-multipart/related (msg part content-type nth dep
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/signed (msg part _content-type _nth depth button)
   (when button
     (button-put button 'face 'notmuch-crypto-part-header))
   ;; Insert a button detailing the signature status.
@@ -688,7 +688,7 @@ (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth dept
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/encrypted (msg part _content-type _nth depth button)
   (when button
     (button-put button 'face 'notmuch-crypto-part-header))
   ;; Insert a button detailing the encryption status.
@@ -706,10 +706,10 @@ (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth d
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-application/pgp-encrypted (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-application/pgp-encrypted (_msg _part _content-type _nth _depth _button)
   t)
 
-(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/* (msg part _content-type _nth depth _button)
   (let ((inner-parts (plist-get part :content))
 	(start (point)))
     ;; Show all of the parts.
@@ -720,7 +720,7 @@ (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth but
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-message/rfc822 (msg part _content-type _nth depth _button)
   (let* ((message (car (plist-get part :content)))
 	 (body (car (plist-get message :body)))
 	 (start (point)))
@@ -737,7 +737,7 @@ (defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-text/plain (msg part _content-type _nth depth button)
   ;; For backward compatibility we want to apply the text/plain hook
   ;; to the whole of the part including the part button if there is
   ;; one.
@@ -751,7 +751,7 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt
 	(run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))
   t)
 
-(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-text/calendar (msg part _content-type _nth _depth _button)
   (insert (with-temp-buffer
 	    (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto))
 	    ;; notmuch-get-bodypart-text does no newline conversion.
@@ -775,8 +775,8 @@ (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth b
   t)
 
 ;; For backwards compatibility.
-(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth button)
-  (notmuch-show-insert-part-text/calendar msg part content-type nth depth button))
+(defun notmuch-show-insert-part-text/x-vcalendar (msg part _content-type _nth depth _button)
+  (notmuch-show-insert-part-text/calendar msg part nil nil depth nil))
 
 (when (version< emacs-version "25.3")
   ;; https://bugs.gnu.org/28350
@@ -792,7 +792,7 @@ (when (version< emacs-version "25.3")
     ;; the first time).
     (require 'enriched)
     (cl-letf (((symbol-function 'enriched-decode-display-prop)
-	       (lambda (start end &optional param) (list start end))))
+	       (lambda (start end &optional _param) (list start end))))
       (notmuch-show-insert-part-*/* msg part content-type nth depth button))))
 
 (defun notmuch-show-get-mime-type-of-application/octet-stream (part)
@@ -850,7 +850,7 @@ (defun notmuch-show--insert-part-text/html-shr (msg part)
     (shr-insert-document dom)
     t))
 
-(defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-*/* (msg part content-type _nth _depth _button)
   ;; This handler _must_ succeed - it is the handler of last resort.
   (notmuch-mm-display-part-inline msg part content-type notmuch-show-process-crypto)
   t)
@@ -970,13 +970,13 @@ (defvar notmuch-show-insert-header-p-function 'notmuch-show-insert-header-p
 should return non-NIL if a header button should be inserted for
 this part.")
 
-(defun notmuch-show-insert-header-p (part hide)
+(defun notmuch-show-insert-header-p (part _hide)
   ;; Show all part buttons except for the first part if it is text/plain.
   (let ((mime-type (notmuch-show-mime-type part)))
     (not (and (string= mime-type "text/plain")
 	      (<= (plist-get part :id) 1)))))
 
-(defun notmuch-show-reply-insert-header-p-never (part hide)
+(defun notmuch-show-reply-insert-header-p-never (_part _hide)
   nil)
 
 (defun notmuch-show-reply-insert-header-p-trimmed (part hide)
@@ -1759,7 +1759,7 @@ (defun notmuch-show-mark-read (&optional unread)
     (apply 'notmuch-show-tag-message
 	   (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
 
-(defun notmuch-show-seen-current-message (start end)
+(defun notmuch-show-seen-current-message (_start _end)
   "Mark the current message read if it is open.
 
 We only mark it read once: if it is changed back then that is a
@@ -1777,7 +1777,7 @@ (defun notmuch-show-command-hook ()
     ;; We need to redisplay to get window-start and window-end correct.
     (redisplay)
     (save-excursion
-      (condition-case err
+      (condition-case nil
 	  (funcall notmuch-show-mark-read-function (window-start) (window-end))
 	((debug error)
 	 (unless notmuch-show--seen-has-errored
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 1ed34801..e254593f 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -598,8 +598,7 @@ (defun notmuch-tree-show-message-out ()
   "Show the current message (in whole window)."
   (interactive)
   (let ((id (notmuch-tree-get-message-id))
-	(inhibit-read-only t)
-	buffer)
+	(inhibit-read-only t))
     (when id
       ;; We close the window to kill off un-needed buffers.
       (notmuch-tree-close-message-window)
@@ -1033,19 +1032,17 @@ (define-derived-mode notmuch-tree-mode fundamental-mode "notmuch-tree"
   (setq buffer-read-only t)
   (setq truncate-lines t))
 
-(defun notmuch-tree-process-sentinel (proc msg)
+(defun notmuch-tree-process-sentinel (proc _msg)
   "Add a message to let user know when \"notmuch tree\" exits."
   (let ((buffer (process-buffer proc))
 	(status (process-status proc))
-	(exit-status (process-exit-status proc))
-	(never-found-target-thread nil))
+	(exit-status (process-exit-status proc)))
     (when (memq status '(exit signal))
       (kill-buffer (process-get proc 'parse-buf))
       (when (buffer-live-p buffer)
 	(with-current-buffer buffer
 	  (save-excursion
-	    (let ((inhibit-read-only t)
-		  (atbob (bobp)))
+	    (let ((inhibit-read-only t))
 	      (goto-char (point-max))
 	      (when (eq status 'signal)
 		(insert "Incomplete search results (tree view process was killed).\n"))
@@ -1059,8 +1056,7 @@ (defun notmuch-tree-process-filter (proc string)
   "Process and filter the output of \"notmuch show\" for tree view."
   (let ((results-buf (process-buffer proc))
 	(parse-buf (process-get proc 'parse-buf))
-	(inhibit-read-only t)
-	done)
+	(inhibit-read-only t))
     (if (not (buffer-live-p results-buf))
 	(delete-process proc)
       (with-current-buffer parse-buf
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 70eff637..36041904 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -237,11 +237,10 @@ (defun notmuch-wash-excerpt-citations (msg depth)
   (beginning-of-line)
   (when (and (< (point) (point-max))
 	     (re-search-forward notmuch-wash-original-regexp nil t))
-    (let* ((msg-start (match-beginning 0))
-	   (msg-end (point-max))
-	   (msg-lines (count-lines msg-start msg-end)))
-      (notmuch-wash-region-to-button
-       msg msg-start msg-end "original")))
+    (notmuch-wash-region-to-button msg
+				   (match-beginning 0)
+				   (point-max)
+				   "original"))
   (while (and (< (point) (point-max))
 	      (re-search-forward notmuch-wash-citation-regexp nil t))
     (let* ((cite-start (match-beginning 0))
@@ -262,10 +261,9 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	   "citation")))))
   (when (and (not (eobp))
 	     (re-search-forward notmuch-wash-signature-regexp nil t))
-    (let* ((sig-start (match-beginning 0))
-	   (sig-end (match-end 0))
-	   (sig-lines (count-lines sig-start (point-max))))
-      (when (<= sig-lines notmuch-wash-signature-lines-max)
+    (let ((sig-start (match-beginning 0)))
+      (when (<= (count-lines sig-start (point-max))
+		notmuch-wash-signature-lines-max)
 	(let ((sig-start-marker (make-marker))
 	      (sig-end-marker (make-marker)))
 	  (set-marker sig-start-marker sig-start)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 9c06ad72..dc1874ce 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -693,7 +693,7 @@ (defun notmuch-search-update-result (result &optional pos)
 			  (min init-point (- new-end 1)))))
 	(goto-char new-point)))))
 
-(defun notmuch-search-process-sentinel (proc msg)
+(defun notmuch-search-process-sentinel (proc _msg)
   "Add a message to let user know when \"notmuch search\" exits."
   (let ((buffer (process-buffer proc))
 	(status (process-status proc))
@@ -896,8 +896,7 @@ (defun notmuch-search-process-filter (proc string)
   "Process and filter the output of \"notmuch search\"."
   (let ((results-buf (process-buffer proc))
 	(parse-buf (process-get proc 'parse-buf))
-	(inhibit-read-only t)
-	done)
+	(inhibit-read-only t))
     (when (buffer-live-p results-buf)
       (with-current-buffer parse-buf
 	;; Insert new data
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 13/32] emacs: notmuch-tag--get-formats: silence byte-compiler
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (11 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 12/32] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 14/32] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
                   ` (20 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

`format-alist' is a global variable and the byte-compiler is unhappy
when a lexical function argument shadows a global (dynamic) binding.
---
 emacs/notmuch-tag.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index fa376b02..a553dfd9 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -285,12 +285,12 @@ (defun notmuch-tag-clear-cache ()
   "Clear the internal cache of tag formats."
   (clrhash notmuch-tag--format-cache))
 
-(defun notmuch-tag--get-formats (tag format-alist)
+(defun notmuch-tag--get-formats (tag alist)
   "Find the first item whose car regexp-matches TAG."
   (save-match-data
     ;; Don't use assoc-default since there's no way to distinguish a
     ;; missing key from a present key with a null cdr.
-    (cl-assoc tag format-alist
+    (cl-assoc tag alist
 	      :test (lambda (tag key)
 		      (and (eq (string-match key tag) 0)
 			   (= (match-end 0) (length tag)))))))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 14/32] emacs: inline notmuch-sexp-eof into only caller
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (12 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 13/32] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 15/32] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
                   ` (19 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

This function had a few issues.
- Neither its name nor the old comment before it is called made it
  clear what it does.
- It took one argument but didn't do anything with it.
- It's doc-string made a few claims, which are untrue and generally
  focused on details instead of that its purpose is.
---
 emacs/notmuch-parser.el | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index b8c3fd2c..294e0544 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -140,15 +140,6 @@ (defun notmuch-sexp-begin-list (sp)
 	 (forward-char)
 	 (signal 'invalid-read-syntax (list (string (char-before)))))))
 
-(defun notmuch-sexp-eof (sp)
-  "Signal an error if there is more data in SP's buffer.
-
-Moves point to the beginning of any trailing data or to the end
-of the buffer if there is only trailing whitespace."
-  (skip-chars-forward " \n\r\t")
-  (unless (eobp)
-    (error "Trailing garbage following expression")))
-
 (defvar notmuch-sexp--parser nil
   "The buffer-local notmuch-sexp-parser instance.
 
@@ -187,8 +178,11 @@ (defun notmuch-sexp-parse-partial-list (result-function result-buffer)
 	     (t     (with-current-buffer result-buffer
 		      (funcall result-function result))))))
 	(end
-	 ;; Any trailing data is unexpected
-	 (notmuch-sexp-eof notmuch-sexp--parser)
+	 ;; Skip over trailing whitespace.
+	 (skip-chars-forward " \n\r\t")
+	 ;; Any trailing data is unexpected.
+	 (unless (eobp)
+	   (error "Trailing garbage following expression"))
 	 (setq done t)))))
   ;; Clear out what we've parsed
   (delete-region (point-min) (point)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 15/32] emacs: notmuch-wash-region-to-button: remove unused MSG argument
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (13 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 14/32] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 16/32] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
                   ` (18 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-wash.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 36041904..4fbb4e12 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -200,7 +200,7 @@ (defun notmuch-wash-button-label (overlay)
 				   (overlay-end overlay))))
     (format label-format lines-count)))
 
-(defun notmuch-wash-region-to-button (msg beg end type &optional prefix)
+(defun notmuch-wash-region-to-button (beg end type &optional prefix)
   "Auxiliary function to do the actual making of overlays and buttons.
 
 BEG and END are buffer locations. TYPE should a string, either
@@ -237,8 +237,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
   (beginning-of-line)
   (when (and (< (point) (point-max))
 	     (re-search-forward notmuch-wash-original-regexp nil t))
-    (notmuch-wash-region-to-button msg
-				   (match-beginning 0)
+    (notmuch-wash-region-to-button (match-beginning 0)
 				   (point-max)
 				   "original"))
   (while (and (< (point) (point-max))
@@ -257,7 +256,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	  (goto-char cite-end)
 	  (forward-line (- notmuch-wash-citation-lines-suffix))
 	  (notmuch-wash-region-to-button
-	   msg hidden-start (point-marker)
+	   hidden-start (point-marker)
 	   "citation")))))
   (when (and (not (eobp))
 	     (re-search-forward notmuch-wash-signature-regexp nil t))
@@ -271,7 +270,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	  (overlay-put (make-overlay sig-start-marker sig-end-marker)
 		       'face 'message-cited-text)
 	  (notmuch-wash-region-to-button
-	   msg sig-start-marker sig-end-marker
+	   sig-start-marker sig-end-marker
 	   "signature"))))))
 
 (defun notmuch-wash-elide-blank-lines (msg depth)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 16/32] emacs: silence compiler wrt notmuch-show-insert-part-text/plain
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (14 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 15/32] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 17/32] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
                   ` (17 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

`notmuch-show-insert-part-text/plain' calls
`notmuch-show-insert-text/plain-hook' with two arguments
MSG and DEPTH. Currently all hook functions ignore MSG but
third-party functions may not.  One hook function uses DEPTH.
---
 emacs/notmuch-wash.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 4fbb4e12..d613e04c 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -231,7 +231,7 @@ (defun notmuch-wash-region-to-button (beg end type &optional prefix)
 
 ;;; Hook functions
 
-(defun notmuch-wash-excerpt-citations (msg depth)
+(defun notmuch-wash-excerpt-citations (_msg _depth)
   "Excerpt citations and up to one signature."
   (goto-char (point-min))
   (beginning-of-line)
@@ -273,7 +273,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	   sig-start-marker sig-end-marker
 	   "signature"))))))
 
-(defun notmuch-wash-elide-blank-lines (msg depth)
+(defun notmuch-wash-elide-blank-lines (_msg _depth)
   "Elide leading, trailing and successive blank lines."
   ;; Algorithm derived from `article-strip-multiple-blank-lines' in
   ;; `gnus-art.el'.
@@ -294,7 +294,7 @@ (defun notmuch-wash-elide-blank-lines (msg depth)
   (when (looking-at "\n")
     (delete-region (match-beginning 0) (match-end 0))))
 
-(defun notmuch-wash-tidy-citations (msg depth)
+(defun notmuch-wash-tidy-citations (_msg _depth)
   "Improve the display of cited regions of a message.
 
 Perform several transformations on the message body:
@@ -318,7 +318,7 @@ (defun notmuch-wash-tidy-citations (msg depth)
   (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
     (replace-match "\\2")))
 
-(defun notmuch-wash-wrap-long-lines (msg depth)
+(defun notmuch-wash-wrap-long-lines (_msg depth)
   "Wrap long lines in the message.
 
 If `notmuch-wash-wrap-lines-length' is a number, this will wrap
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 17/32] emacs: define notmuch-message-queued-tag-changes as buffer-local
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (15 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 16/32] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 18/32] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
                   ` (16 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

Also improve the doc-string.
---
 emacs/notmuch-message.el | 14 +++++++-------
 emacs/notmuch-mua.el     | 12 ++++++------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index f0e9ffcc..9dc8d056 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -50,14 +50,14 @@ (defcustom notmuch-message-forwarded-tags '("+forwarded")
   :type '(repeat string)
   :group 'notmuch-send)
 
-(defconst notmuch-message-queued-tag-changes nil
-  "List of messages and corresponding tag-changes to be applied when sending a message.
+(defvar-local notmuch-message-queued-tag-changes nil
+  "List of tag changes to be applied when sending a message.
 
-This variable is overridden by buffer-local versions in message
-buffers where tag changes should be triggered when sending off
-the message.  Each item in this list is a list of strings, where
-the first is a notmuch query and the rest are the tag changes to
-be applied to the matching messages.")
+A list of queries and tag changes that are to be applied to them
+when the message that was composed in the current buffer is being
+send.  Each item in this list is a list of strings, where the
+first is a notmuch query and the rest are the tag changes to be
+applied to the matching messages.")
 
 (defun notmuch-message-apply-queued-tag-changes ()
   ;; Apply the tag changes queued in the buffer-local variable
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index b2930051..95d1965b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -266,8 +266,8 @@ (defun notmuch-mua-reply (query-string &optional sender reply-all)
       ;; Create a buffer-local queue for tag changes triggered when
       ;; sending the reply.
       (when notmuch-message-replied-tags
-	(setq-local notmuch-message-queued-tag-changes
-		    (list (cons query-string notmuch-message-replied-tags))))
+	(setq notmuch-message-queued-tag-changes
+	      (list (cons query-string notmuch-message-replied-tags))))
       ;; Insert the message body - but put it in front of the signature
       ;; if one is present, and after any other content
       ;; message*setup-hooks may have added to the message body already.
@@ -507,10 +507,10 @@ (defun notmuch-mua-new-forward-messages (messages &optional prompt-for-sender)
       ;; Create a buffer-local queue for tag changes triggered when
       ;; sending the message.
       (when notmuch-message-forwarded-tags
-	(setq-local notmuch-message-queued-tag-changes
-		    (cl-loop for id in forward-queries
-			     collect
-			     (cons id notmuch-message-forwarded-tags))))
+	(setq notmuch-message-queued-tag-changes
+	      (cl-loop for id in forward-queries
+		       collect
+		       (cons id notmuch-message-forwarded-tags))))
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
       (message-hide-headers)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 18/32] emacs: notmuch-message-apply-queued-tag-changes: cosmetics
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (16 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 17/32] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 19/32] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
                   ` (15 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-message.el | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 9dc8d056..abeff53a 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -62,9 +62,8 @@ (defvar-local notmuch-message-queued-tag-changes nil
 (defun notmuch-message-apply-queued-tag-changes ()
   ;; Apply the tag changes queued in the buffer-local variable
   ;; notmuch-message-queued-tag-changes.
-  (dolist (query-and-tags notmuch-message-queued-tag-changes)
-    (notmuch-tag (car query-and-tags)
-		 (cdr query-and-tags))))
+  (pcase-dolist (`(,query . ,tags) notmuch-message-queued-tag-changes)
+    (notmuch-tag query tags)))
 
 (add-hook 'message-send-hook 'notmuch-message-apply-queued-tag-changes)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 19/32] emacs: notmuch-wash.el: require diff-mode at beginning of code
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (17 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 18/32] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 20/32] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
                   ` (14 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

That's what we usually do.  Also do not declare variable
`diff-file-header-re' because it is defined in `diff-mode.el',
which we always require.
---
 emacs/notmuch-wash.el | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index d613e04c..653ecc2a 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -24,6 +24,7 @@
 ;;; Code:
 
 (require 'coolj)
+(require 'diff-mode)
 (require 'notmuch-lib)
 
 (declare-function notmuch-show-insert-bodypart "notmuch-show"
@@ -341,10 +342,6 @@ (defun notmuch-wash-wrap-long-lines (_msg depth)
 
 ;;;; Convert Inline Patches
 
-(require 'diff-mode)
-
-(defvar diff-file-header-re) ; From `diff-mode.el'.
-
 (defun notmuch-wash-subject-to-filename (subject &optional maxlen)
   "Convert a mail SUBJECT into a filename.
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 20/32] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (18 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 19/32] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 21/32] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
                   ` (13 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

We shouldn't force `ido-completion-read' on users who do not otherwise
use Ido.  Unfortunately simply turning on `ido-mode' does not change
every `completing-read' into a `ido-completing-read', instead it only
changes file and buffer completion.

I do realize that existing Ido users will initially dislike this
change, but I would like to encourage them to see this as an
opportunity to learn about Fido.

Unlike `ido-mode', build-in `fido-mode' confirms to the standard
completion API, so turning it on causes every `completing-read' to
use the Fido completion mechanism and which is similar to the Ido
mechanism:

> An enhanced `icomplete-mode' that emulates `ido-mode'.  This global
> minor mode makes minibuffer completion behave more like `ido-mode'
> than regular `icomplete-mode'."
---
 emacs/notmuch-mua.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 95d1965b..2d0b7169 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -431,16 +431,16 @@ (defvar notmuch-mua-sender-history nil)
 (defun notmuch-mua-prompt-for-sender ()
   "Prompt for a sender from the user's configured identities."
   (if notmuch-identities
-      (ido-completing-read "Send mail from: " notmuch-identities
-			   nil nil nil 'notmuch-mua-sender-history
-			   (car notmuch-identities))
+      (completing-read "Send mail from: " notmuch-identities
+		       nil nil nil 'notmuch-mua-sender-history
+		       (car notmuch-identities))
     (let* ((name (notmuch-user-name))
 	   (addrs (cons (notmuch-user-primary-email)
 			(notmuch-user-other-email)))
 	   (address
-	    (ido-completing-read (concat "Sender address for " name ": ") addrs
-				 nil nil nil 'notmuch-mua-sender-history
-				 (car addrs))))
+	    (completing-read (concat "Sender address for " name ": ") addrs
+			     nil nil nil 'notmuch-mua-sender-history
+			     (car addrs))))
       (message-make-from name address))))
 
 (put 'notmuch-mua-new-mail 'notmuch-prefix-doc "... and prompt for sender")
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 21/32] emacs: notmuch-mua.el: move all options into "Options" section
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (19 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 20/32] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 22/32] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
                   ` (12 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

This is how we do it in other libraries.
---
 emacs/notmuch-mua.el | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 2d0b7169..74ffd8f2 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -82,6 +82,22 @@ (defcustom notmuch-mua-hidden-headers nil
   :type '(repeat string)
   :group 'notmuch-send)
 
+(defcustom notmuch-identities nil
+  "Identities that can be used as the From: address when composing a new message.
+
+If this variable is left unset, then a list will be constructed from the
+name and addresses configured in the notmuch configuration file."
+  :type '(repeat string)
+  :group 'notmuch-send)
+
+(defcustom notmuch-always-prompt-for-sender nil
+  "Always prompt for the From: address when composing or forwarding a message.
+
+This is not taken into account when replying to a message, because in that case
+the From: header is already filled in by notmuch."
+  :type 'boolean
+  :group 'notmuch-send)
+
 (defgroup notmuch-reply nil
   "Replying to messages in notmuch"
   :group 'notmuch)
@@ -410,22 +426,6 @@ (defun notmuch-mua-mail (&optional to subject other-headers _continue
   (notmuch-mua-maybe-set-window-dedicated)
   (message-goto-to))
 
-(defcustom notmuch-identities nil
-  "Identities that can be used as the From: address when composing a new message.
-
-If this variable is left unset, then a list will be constructed from the
-name and addresses configured in the notmuch configuration file."
-  :type '(repeat string)
-  :group 'notmuch-send)
-
-(defcustom notmuch-always-prompt-for-sender nil
-  "Always prompt for the From: address when composing or forwarding a message.
-
-This is not taken into account when replying to a message, because in that case
-the From: header is already filled in by notmuch."
-  :type 'boolean
-  :group 'notmuch-send)
-
 (defvar notmuch-mua-sender-history nil)
 
 (defun notmuch-mua-prompt-for-sender ()
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 22/32] emacs: notmuch-crypto-status-button-type: fix potential bug
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (20 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 21/32] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 23/32] emacs: various cosmetic improvements Jonas Bernoulli
                   ` (11 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

The "help-echo" can potentially contain an unintended %-spec
so we have to make sure it would not be treated as such.
---
 emacs/notmuch-crypto.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 50a3de46..db7cb75d 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -103,7 +103,7 @@ (defface notmuch-crypto-decryption
 ;;; Functions
 
 (define-button-type 'notmuch-crypto-status-button-type
-  'action (lambda (button) (message (button-get button 'help-echo)))
+  'action (lambda (button) (message "%s" (button-get button 'help-echo)))
   'follow-link t
   'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."
   :supertype 'notmuch-button-type)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 23/32] emacs: various cosmetic improvements
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (21 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 22/32] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 24/32] emacs: various comment improvements Jonas Bernoulli
                   ` (10 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-address.el     | 22 ++++------
 emacs/notmuch-hello.el       | 24 ++++-------
 emacs/notmuch-jump.el        |  4 +-
 emacs/notmuch-lib.el         | 26 +++++------
 emacs/notmuch-maildir-fcc.el | 61 +++++++++++---------------
 emacs/notmuch-mua.el         | 28 ++++++------
 emacs/notmuch-query.el       | 11 +++--
 emacs/notmuch-tag.el         | 14 +++---
 emacs/notmuch.el             | 83 ++++++++++++++++++------------------
 9 files changed, 125 insertions(+), 148 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1017c3ce..2f0ec9b3 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -21,6 +21,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
@@ -160,15 +162,12 @@ (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (let* ((setup-company (and notmuch-address-use-company
-			     (require 'company nil t)))
-	 (pair (cons notmuch-address-completion-headers-regexp
-		     #'notmuch-address-expand-name)))
-    (when setup-company
-      (notmuch-company-setup))
-    (unless (member pair message-completion-alist)
-      (setq message-completion-alist
-	    (push pair message-completion-alist)))))
+  (when (and notmuch-address-use-company
+	     (require 'company nil t))
+    (notmuch-company-setup))
+  (cl-pushnew (cons notmuch-address-completion-headers-regexp
+		    #'notmuch-address-expand-name)
+	      message-completion-alist :test #'equal))
 
 (defun notmuch-address-toggle-internal-completion ()
   "Toggle use of internal completion for current buffer.
@@ -264,9 +263,6 @@ (defun notmuch-address-harvest-addr (result)
   (let ((name-addr (plist-get result :name-addr)))
     (puthash name-addr t notmuch-address-completions)))
 
-(defun notmuch-address-harvest-handle-result (obj)
-  (notmuch-address-harvest-addr obj))
-
 (defun notmuch-address-harvest-filter (proc string)
   (when (buffer-live-p (process-buffer proc))
     (with-current-buffer (process-buffer proc)
@@ -274,7 +270,7 @@ (defun notmuch-address-harvest-filter (proc string)
 	(goto-char (point-max))
 	(insert string))
       (notmuch-sexp-parse-partial-list
-       'notmuch-address-harvest-handle-result (process-buffer proc)))))
+       'notmuch-address-harvest-addr (process-buffer proc)))))
 
 (defvar notmuch-address-harvest-procs '(nil . nil)
   "The currently running harvests.
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index a134eb07..ffd3d799 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -432,8 +432,7 @@ (defun notmuch-hello-add-saved-search (widget &rest _event)
     ;; If an existing saved search with this name exists, remove it.
     (setq notmuch-saved-searches
 	  (cl-loop for elem in notmuch-saved-searches
-		   if (not (equal name
-				  (notmuch-saved-search-get elem :name)))
+		   unless (equal name (notmuch-saved-search-get elem :name))
 		   collect elem))
     ;; Add the new one.
     (customize-save-variable 'notmuch-saved-searches
@@ -481,18 +480,14 @@ (defun notmuch-hello-reflect (list ncols)
 	     append (notmuch-hello-reflect-generate-row ncols nrows row list))))
 
 (defun notmuch-hello-widget-search (widget &rest _ignore)
-  (cond
-   ((eq (widget-get widget :notmuch-search-type) 'tree)
-    (notmuch-tree (widget-get widget
-			      :notmuch-search-terms)))
-   ((eq (widget-get widget :notmuch-search-type) 'unthreaded)
-    (notmuch-unthreaded (widget-get widget
-				    :notmuch-search-terms)))
+  (cl-case (widget-get widget :notmuch-search-type)
+   (tree
+    (notmuch-tree (widget-get widget :notmuch-search-terms)))
+   (unthreaded
+    (notmuch-unthreaded (widget-get widget :notmuch-search-terms)))
    (t
-    (notmuch-search (widget-get widget
-				:notmuch-search-terms)
-		    (widget-get widget
-				:notmuch-search-oldest-first)))))
+    (notmuch-search (widget-get widget :notmuch-search-terms)
+		    (widget-get widget :notmuch-search-oldest-first)))))
 
 (defun notmuch-saved-search-count (search)
   (car (process-lines notmuch-command "count" search)))
@@ -823,8 +818,7 @@ (defun notmuch-hello-insert-search ()
   ;; instead of a space to make `show-trailing-whitespace'
   ;; happy, i.e. avoid it marking the whole line as trailing
   ;; spaces.
-  (widget-insert ".")
-  (put-text-property (1- (point)) (point) 'invisible t)
+  (widget-insert (propertize "." 'invisible t))
   (widget-insert "\n"))
 
 (defun notmuch-hello-insert-recent-searches ()
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 51bc4e31..34d6c796 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -63,8 +63,8 @@ (defun notmuch-jump-search ()
     (setq action-map (nreverse action-map))
     (if action-map
 	(notmuch-jump action-map "Search: ")
-      (error "To use notmuch-jump, \
-please customize shortcut keys in notmuch-saved-searches."))))
+      (error "To use notmuch-jump, %s"
+	     "please customize shortcut keys in notmuch-saved-searches."))))
 
 (defvar notmuch-jump--action nil)
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 1bdfc2b9..3add992b 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -192,8 +192,8 @@ (defun notmuch-command-to-string (&rest args)
 
 Otherwise the output will be returned."
   (with-temp-buffer
-    (let* ((status (apply #'call-process notmuch-command nil t nil args))
-	   (output (buffer-string)))
+    (let ((status (apply #'call-process notmuch-command nil t nil args))
+	  (output (buffer-string)))
       (notmuch-check-exit-status status (cons notmuch-command args) output)
       output)))
 
@@ -248,7 +248,8 @@ (defun notmuch-config-get (item)
 	 (len (length val)))
     ;; Trim off the trailing newline (if the value is empty or not
     ;; configured, there will be no newline)
-    (if (and (> len 0) (= (aref val (- len 1)) ?\n))
+    (if (and (> len 0)
+	     (= (aref val (- len 1)) ?\n))
 	(substring val 0 -1)
       val)))
 
@@ -538,13 +539,12 @@ (defun notmuch-common-do-stash (text)
 ;;; Generic Utilities
 
 (defun notmuch-plist-delete (plist property)
-  (let* ((xplist (cons nil plist))
-	 (pred xplist))
-    (while (cdr pred)
-      (when (eq (cadr pred) property)
-	(setcdr pred (cdddr pred)))
-      (setq pred (cddr pred)))
-    (cdr xplist)))
+  (let (p)
+    (while plist
+      (unless (eq property (car plist))
+	(setq p (plist-put p (car plist) (cadr plist))))
+      (setq plist (cddr plist)))
+    p))
 
 ;;; MML Utilities
 
@@ -555,8 +555,10 @@ (defun notmuch-match-content-type (t1 t2)
     (if (or (string= (cadr st1) "*")
 	    (string= (cadr st2) "*"))
 	;; Comparison of content types should be case insensitive.
-	(string= (downcase (car st1)) (downcase (car st2)))
-      (string= (downcase t1) (downcase t2)))))
+	(string= (downcase (car st1))
+		 (downcase (car st2)))
+      (string= (downcase t1)
+	       (downcase t2)))))
 
 (defvar notmuch-multipart/alternative-discouraged
   '(;; Avoid HTML parts.
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 9f09129d..945a66fc 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -107,16 +107,13 @@ (defun notmuch-fcc-header-setup ()
 	   ;; Old style - no longer works.
 	   (error "Invalid `notmuch-fcc-dirs' setting (old style)"))
 	  ((listp notmuch-fcc-dirs)
-	   (let* ((from (message-field-value "From"))
-		  (match
-		   (catch 'first-match
-		     (dolist (re-folder notmuch-fcc-dirs)
-		       (when (string-match-p (car re-folder) from)
-			 (throw 'first-match re-folder))))))
-	     (if match
-		 (cdr match)
-	       (message "No Fcc header added.")
-	       nil)))
+	   (or (seq-some (let ((from (message-field-value "From")))
+			   (pcase-lambda (`(,regexp ,folder))
+			     (and (string-match-p regexp from)
+				  folder)))
+			 notmuch-fcc-dirs)
+	       (progn (message "No Fcc header added.")
+		      nil)))
 	  (t
 	   (error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))
     (when subdir
@@ -128,9 +125,9 @@ (defun notmuch-maildir-add-notmuch-insert-style-fcc-header (subdir)
   ;; Notmuch insert does not accept absolute paths, so check the user
   ;; really want this header inserted.
   (when (or (not (= (elt subdir 0) ?/))
-	    (y-or-n-p
-	     (format "Fcc header %s is an absolute path and notmuch insert is requested.
-Insert header anyway? " subdir)))
+	    (y-or-n-p (format "Fcc header %s is an absolute path%s%s" subdir
+			      "and notmuch insert is requested."
+			      "Insert header anyway? ")))
     (message-add-header (concat "Fcc: " subdir))))
 
 (defun notmuch-maildir-add-file-style-fcc-header (subdir)
@@ -173,7 +170,7 @@ (defun notmuch-maildir-message-do-fcc ()
   "Process Fcc headers in the current buffer.
 
 This is a rearranged version of message mode's message-do-fcc."
-  (let (list file)
+  (let (files file)
     (save-excursion
       (save-restriction
 	(message-narrow-to-headers)
@@ -183,13 +180,11 @@ (defun notmuch-maildir-message-do-fcc ()
 	 (save-restriction
 	   (message-narrow-to-headers)
 	   (while (setq file (message-fetch-field "fcc" t))
-	     (push file list)
+	     (push file files)
 	     (message-remove-header "fcc" nil t)))
 	 (notmuch-maildir-setup-message-for-saving)
 	 ;; Process FCC operations.
-	 (while list
-	   (setq file (pop list))
-	   (notmuch-fcc-handler file))
+	 (mapc #'notmuch-fcc-handler files)
 	 (kill-buffer (current-buffer)))))))
 
 (defun notmuch-fcc-handler (fcc-header)
@@ -201,7 +196,8 @@ (defun notmuch-fcc-handler (fcc-header)
   (message "Doing Fcc...")
   (if notmuch-maildir-use-notmuch-insert
       (notmuch-maildir-fcc-with-notmuch-insert fcc-header)
-    (notmuch-maildir-fcc-file-fcc fcc-header)))
+    (notmuch-maildir-fcc-file-fcc fcc-header))
+  (message "Doing Fcc...done"))
 
 ;;; Functions for saving a message using notmuch insert.
 
@@ -230,9 +226,8 @@ (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
 or surrounding the entire folder name in double quotes.
 
 If CREATE is non-nil then create the folder if necessary."
-  (let* ((args (split-string-and-unquote fcc-header))
-	 (folder (car args))
-	 (tags (cdr args)))
+  (pcase-let ((`(,folder . ,tags)
+	       (split-string-and-unquote fcc-header)))
     (condition-case nil
 	(notmuch-maildir-notmuch-insert-current-buffer folder create tags)
       ;; Since there are many reasons notmuch insert could fail, e.g.,
@@ -265,7 +260,7 @@ (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
   (let* ((ftime (float-time))
 	 (microseconds (mod (* 1000000 ftime) 1000000))
 	 (hostname (notmuch-maildir-fcc-host-fixer (system-name))))
-    (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
+    (cl-incf notmuch-maildir-fcc-count)
     (format "%d.%d_%d_%d.%s"
 	    ftime
 	    (emacs-pid)
@@ -298,9 +293,7 @@ (defun notmuch-maildir-fcc-save-buffer-to-tmp (destdir)
 	   (write-file (concat destdir "/tmp/" msg-id))
 	   msg-id)
 	  (t
-	   (error (format "Can't write to %s. Not a maildir."
-			  destdir))
-	   nil))))
+	   (error "Can't write to %s. Not a maildir." destdir)))))
 
 (defun notmuch-maildir-fcc-move-tmp-to-new (destdir msg-id)
   (add-name-to-file
@@ -345,16 +338,12 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
       (catch 'link-error
 	(let ((msg-id (notmuch-maildir-fcc-save-buffer-to-tmp destdir)))
 	  (when msg-id
-	    (cond (mark-seen
-		   (condition-case nil
-		       (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
-		     (file-already-exists
-		      (throw 'link-error nil))))
-		  (t
-		   (condition-case nil
-		       (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id)
-		     (file-already-exists
-		      (throw 'link-error nil))))))
+	    (condition-case nil
+		(if mark-seen
+		    (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
+		  (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id))
+	      (file-already-exists
+	       (throw 'link-error nil))))
 	  (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 74ffd8f2..4a08e8a7 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -179,13 +179,11 @@ (defun notmuch-mua-attachment-check ()
 
 (defun notmuch-mua-get-switch-function ()
   "Get a switch function according to `notmuch-mua-compose-in'."
-  (cond ((eq notmuch-mua-compose-in 'current-window)
-	 'switch-to-buffer)
-	((eq notmuch-mua-compose-in 'new-window)
-	 'switch-to-buffer-other-window)
-	((eq notmuch-mua-compose-in 'new-frame)
-	 'switch-to-buffer-other-frame)
-	(t (error "Invalid value for `notmuch-mua-compose-in'"))))
+  (pcase notmuch-mua-compose-in
+    ('current-window 'switch-to-buffer)
+    ('new-window     'switch-to-buffer-other-window)
+    ('new-frame      'switch-to-buffer-other-frame)
+    (_ (error "Invalid value for `notmuch-mua-compose-in'"))))
 
 (defun notmuch-mua-maybe-set-window-dedicated ()
   "Set the selected window as dedicated according to `notmuch-mua-compose-in'."
@@ -375,12 +373,10 @@ (defun notmuch-mua-pop-to-buffer (name switch-function)
 		(select-window window))
 	    (funcall switch-function buffer)
 	    (set-buffer buffer))
-	  (when (and (buffer-modified-p)
-		     (not (prog1
-			      (y-or-n-p
-			       "Message already being composed; erase? ")
-			    (message nil))))
-	    (error "Message being composed")))
+	  (when (buffer-modified-p)
+	    (if (y-or-n-p "Message already being composed; erase? ")
+		(message nil)
+	      (error "Message being composed"))))
       (funcall switch-function name)
       (set-buffer name))
     (erase-buffer)
@@ -611,8 +607,10 @@ (defun notmuch-mua-kill-buffer ()
 ;;; _
 
 (define-mail-user-agent 'notmuch-user-agent
-  'notmuch-mua-mail 'notmuch-mua-send-and-exit
-  'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
+  'notmuch-mua-mail
+  'notmuch-mua-send-and-exit
+  'notmuch-mua-kill-buffer
+  'notmuch-mua-send-hook)
 
 ;; Add some more headers to the list that `message-mode' hides when
 ;; composing a message.
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index ffce8814..d7349b77 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -41,11 +41,9 @@ (defun notmuch-query-get-threads (search-terms)
 
 (defun notmuch-query-map-aux  (mapper function seq)
   "Private function to do the actual mapping and flattening."
-  (apply 'append
-	 (mapcar
-	  (lambda (tree)
-	    (funcall mapper function tree))
-	  seq)))
+  (cl-mapcan (lambda (tree)
+	       (funcall mapper function tree))
+	     seq))
 
 (defun notmuch-query-map-threads (fn threads)
   "Apply function FN to every thread in THREADS.
@@ -63,7 +61,8 @@ (defun notmuch-query-map-tree (fn tree)
   "Apply function FN to every message in TREE.
 Flatten results to a list.  See the function
 `notmuch-query-get-threads' for more information."
-  (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
+  (cons (funcall fn (car tree))
+	(notmuch-query-map-forest fn (cadr tree))))
 
 ;;; Predefined queries
 
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index a553dfd9..0c9a32ac 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -454,8 +454,9 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((op (string-to-char tag-change))
-	    (tag (unless (string= tag-change "") (substring tag-change 1))))
+      (let ((op (aref tag-change 0))
+	    (tag (and (not (string= tag-change ""))
+		      (substring tag-change 1))))
 	(cl-case op
 	  (?+ (unless (member tag result-tags)
 		(push tag result-tags)))
@@ -482,13 +483,12 @@ (defun notmuch-tag (query tag-changes)
 directly, so that hooks specified in notmuch-before-tag-hook and
 notmuch-after-tag-hook will be run."
   ;; Perform some validation
-  (mapc (lambda (tag-change)
-	  (unless (string-match-p "^[-+]\\S-+$" tag-change)
-	    (error "Tag must be of the form `+this_tag' or `-that_tag'")))
-	tag-changes)
+  (dolist (tag-change tag-changes)
+    (unless (string-match-p "^[-+]\\S-+$" tag-change)
+      (error "Tag must be of the form `+this_tag' or `-that_tag'")))
   (unless query
     (error "Nothing to tag!"))
-  (unless (null tag-changes)
+  (when tag-changes
     (run-hooks 'notmuch-before-tag-hook)
     (if (<= (length query) notmuch-tag-argument-limit)
 	(apply 'notmuch-call-notmuch-process "tag"
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index dc1874ce..4e975d6a 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -179,7 +179,7 @@ (defvar notmuch-search-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
     (define-key map "x" 'notmuch-bury-or-kill-this-buffer)
-    (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
+    (define-key map (kbd "DEL") 'notmuch-search-scroll-down)
     (define-key map "b" 'notmuch-search-scroll-down)
     (define-key map " " 'notmuch-search-scroll-up)
     (define-key map "<" 'notmuch-search-first-thread)
@@ -232,7 +232,7 @@ (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
-(defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")
+(defvar notmuch-search-disjunctive-regexp "\\<[oO][rR]\\>")
 
 ;;; Movement
 
@@ -950,40 +950,39 @@ (defun notmuch-read-query (prompt)
   "Read a notmuch-query from the minibuffer with completion.
 
 PROMPT is the string to prompt with."
-  (let*
-      ((all-tags
-	(mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
-		(process-lines notmuch-command "search" "--output=tags" "*")))
-       (completions
-	(append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
-		      "subject:" "attachment:")
-		(mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
-		(mapcar (lambda (tag) (concat "is:" tag)) all-tags)
-		(mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
-			(mailcap-mime-types)))))
-    (let ((keymap (copy-keymap minibuffer-local-map))
-	  (current-query (cl-case major-mode
-			   (notmuch-search-mode (notmuch-search-get-query))
-			   (notmuch-show-mode (notmuch-show-get-query))
-			   (notmuch-tree-mode (notmuch-tree-get-query))))
-	  (minibuffer-completion-table
-	   (completion-table-dynamic
-	    (lambda (string)
-	      ;; generate a list of possible completions for the current input
-	      (cond
-	       ;; this ugly regexp is used to get the last word of the input
-	       ;; possibly preceded by a '('
-	       ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
-		(mapcar (lambda (compl)
-			  (concat (match-string-no-properties 1 string) compl))
-			(all-completions (match-string-no-properties 2 string)
-					 completions)))
-	       (t (list string)))))))
-      ;; this was simpler than convincing completing-read to accept spaces:
-      (define-key keymap (kbd "TAB") 'minibuffer-complete)
-      (let ((history-delete-duplicates t))
-	(read-from-minibuffer prompt nil keymap nil
-			      'notmuch-search-history current-query nil)))))
+  (let* ((all-tags
+	  (mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
+		  (process-lines notmuch-command "search" "--output=tags" "*")))
+	 (completions
+	  (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
+			"subject:" "attachment:")
+		  (mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
+		  (mapcar (lambda (tag) (concat "is:" tag)) all-tags)
+		  (mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
+			  (mailcap-mime-types))))
+	 (keymap (copy-keymap minibuffer-local-map))
+	 (current-query (cl-case major-mode
+			  (notmuch-search-mode (notmuch-search-get-query))
+			  (notmuch-show-mode (notmuch-show-get-query))
+			  (notmuch-tree-mode (notmuch-tree-get-query))))
+	 (minibuffer-completion-table
+	  (completion-table-dynamic
+	   (lambda (string)
+	     ;; Generate a list of possible completions for the current input.
+	     (cond
+	      ;; This ugly regexp is used to get the last word of the input
+	      ;; possibly preceded by a '('.
+	      ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
+	       (mapcar (lambda (compl)
+			 (concat (match-string-no-properties 1 string) compl))
+		       (all-completions (match-string-no-properties 2 string)
+					completions)))
+	      (t (list string)))))))
+    ;; This was simpler than convincing completing-read to accept spaces:
+    (define-key keymap (kbd "TAB") 'minibuffer-complete)
+    (let ((history-delete-duplicates t))
+      (read-from-minibuffer prompt nil keymap nil
+			    'notmuch-search-history current-query nil))))
 
 (defun notmuch-search-get-query ()
   "Return the current query in this search buffer."
@@ -1046,12 +1045,12 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
 		     (if oldest-first
 			 "--sort=oldest-first"
 		       "--sort=newest-first")
-		     query))
-	      ;; Use a scratch buffer to accumulate partial output.
-	      ;; This buffer will be killed by the sentinel, which
-	      ;; should be called no matter how the process dies.
-	      (parse-buf (generate-new-buffer " *notmuch search parse*")))
-	  (process-put proc 'parse-buf parse-buf)
+		     query)))
+	  ;; Use a scratch buffer to accumulate partial output.
+	  ;; This buffer will be killed by the sentinel, which
+	  ;; should be called no matter how the process dies.
+	  (process-put proc 'parse-buf
+		       (generate-new-buffer " *notmuch search parse*"))
 	  (set-process-filter proc 'notmuch-search-process-filter)
 	  (set-process-query-on-exit-flag proc nil))))
     (run-hooks 'notmuch-search-hook)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 24/32] emacs: various comment improvements
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (22 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 23/32] emacs: various cosmetic improvements Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 25/32] emacs: various doc-string improvements Jonas Bernoulli
                   ` (9 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-address.el | 5 ++---
 emacs/notmuch-hello.el   | 4 +---
 emacs/notmuch-lib.el     | 6 +++---
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 2f0ec9b3..1f22e377 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -381,7 +381,7 @@ (defun notmuch-address--load-address-hash ()
 (defun notmuch-address--save-address-hash ()
   (when notmuch-address-save-filename
     (if (or (not (file-exists-p notmuch-address-save-filename))
-	    ;; The file exists, check it is a file we saved
+	    ;; The file exists, check it is a file we saved.
 	    (notmuch-address--get-address-hash))
 	(with-temp-file notmuch-address-save-filename
 	  (let ((save-plist
@@ -404,8 +404,7 @@ (defun notmuch-address-harvest-trigger ()
        nil nil
        (lambda (_proc event)
 	 ;; If harvest fails, we want to try
-	 ;; again when the trigger is next
-	 ;; called
+	 ;; again when the trigger is next called.
 	 (if (string= event "finished\n")
 	     (progn
 	       (notmuch-address--save-address-hash)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index ffd3d799..186ac172 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -731,9 +731,7 @@ (define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
 Complete list of currently available key bindings:
 
 \\{notmuch-hello-mode-map}"
-  (setq notmuch-buffer-refresh-function #'notmuch-hello-update)
-  ;;(setq buffer-read-only t)
-  )
+  (setq notmuch-buffer-refresh-function #'notmuch-hello-update))
 
 ;;; Inserters
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 3add992b..72549a98 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -247,7 +247,7 @@ (defun notmuch-config-get (item)
   (let* ((val (notmuch-command-to-string "config" "get" item))
 	 (len (length val)))
     ;; Trim off the trailing newline (if the value is empty or not
-    ;; configured, there will be no newline)
+    ;; configured, there will be no newline).
     (if (and (> len 0)
 	     (= (aref val (- len 1)) ?\n))
 	(substring val 0 -1)
@@ -483,8 +483,8 @@ (defun notmuch-refresh-all-buffers ()
 ;;; String Utilities
 
 (defun notmuch-prettify-subject (subject)
-  ;; This function is used by `notmuch-search-process-filter' which
-  ;; requires that we not disrupt its' matching state.
+  ;; This function is used by `notmuch-search-process-filter',
+  ;; which requires that we not disrupt its matching state.
   (save-match-data
     (if (and subject
 	     (string-match "^[ \t]*$" subject))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 25/32] emacs: various doc-string improvements
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (23 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 24/32] emacs: various comment improvements Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 26/32] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
                   ` (8 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-draft.el       | 12 ++++++-----
 emacs/notmuch-maildir-fcc.el | 21 +++++++++---------
 emacs/notmuch-mua.el         |  9 ++++----
 emacs/notmuch-tag.el         | 41 ++++++++++++++++++------------------
 emacs/notmuch-tree.el        | 10 ++++-----
 emacs/notmuch.el             | 24 ++++++++++-----------
 6 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 8af04598..bc688434 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -77,9 +77,11 @@ (defcustom notmuch-draft-quoted-tags '()
   :group 'notmuch-send)
 
 (defcustom notmuch-draft-save-plaintext 'ask
-  "Should notmuch save/postpone in plaintext messages that seem
-like they are intended to be sent encrypted
-(i.e with an mml encryption tag in it)."
+  "Whether to allow saving plaintext when it seems encryption is intended.
+When a message contains mml tags, then that suggest it is
+intended to be encrypted.  If the user requests that such a
+message is saved locally, then this option controls whether
+that is allowed.  Beside a boolean, this can also be `ask'."
   :type '(radio
 	  (const :tag "Never" nil)
 	  (const :tag "Ask every time" ask)
@@ -146,13 +148,13 @@ (defun notmuch-draft-unquote-some-mml ()
 	(insert secure-tag "\n")))))
 
 (defun notmuch-draft--has-encryption-tag ()
-  "Returns t if there is an mml secure tag."
+  "Return non-nil if there is an mml secure tag."
   (save-excursion
     (message-goto-body)
     (re-search-forward notmuch-draft-encryption-tag-regex nil t)))
 
 (defun notmuch-draft--query-encryption ()
-  "Checks if we should save a message that should be encrypted.
+  "Return non-nil if we should save a message that should be encrypted.
 
 `notmuch-draft-save-plaintext' controls the behaviour."
   (cl-case notmuch-draft-save-plaintext
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 945a66fc..0000863d 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -90,10 +90,8 @@ (defcustom notmuch-maildir-use-notmuch-insert t
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
 
-Sets the Fcc header based on the values of `notmuch-fcc-dirs'.
-
-Originally intended to be use a hook function, but now called directly
-by notmuch-mua-mail."
+If the Fcc header is already set, then keep it as-is.
+Otherwise set it according to `notmuch-fcc-dirs'."
   (let ((subdir
 	 (cond
 	  ((or (not notmuch-fcc-dirs)
@@ -153,8 +151,9 @@ (defmacro with-temporary-notmuch-message-buffer (&rest body)
        ,@body)))
 
 (defun notmuch-maildir-setup-message-for-saving ()
-  "Setup message for saving. Should be called on a temporary copy.
+  "Setup message for saving.
 
+This should be called on a temporary copy.
 This is taken from the function message-do-fcc."
   (message-encode-message-body)
   (save-restriction
@@ -308,8 +307,8 @@ (defun notmuch-maildir-fcc-move-tmp-to-cur (destdir msg-id &optional mark-seen)
 (defun notmuch-maildir-fcc-file-fcc (fcc-header)
   "Write the message to the file specified by FCC-HEADER.
 
-It offers the user a chance to correct the header, or filesystem,
-if needed."
+If that fails, then offer the user a chance to correct the header
+or filesystem."
   (if (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)
       (notmuch-maildir-fcc-write-buffer-to-maildir fcc-header t)
     ;; The fcc-header is not a valid maildir see if the user wants to
@@ -329,9 +328,11 @@ (defun notmuch-maildir-fcc-file-fcc (fcc-header)
 	     (read-from-minibuffer "Fcc header: " fcc-header)))))))
 
 (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
-  "Writes the current buffer to maildir destdir. If mark-seen is
-non-nil, it will write it to cur/, and mark it as read. It should
-return t if successful, and nil otherwise."
+  "Write the current buffer to maildir destdir.
+
+If mark-seen is non-nil, then write it to \"cur/\", and mark it
+as read, otherwise write it to \"new/\". Return t if successful,
+and nil otherwise."
   (let ((orig-buffer (buffer-name)))
     (with-temp-buffer
       (insert-buffer-substring orig-buffer)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 4a08e8a7..2e4dc71a 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -99,7 +99,7 @@ (defcustom notmuch-always-prompt-for-sender nil
   :group 'notmuch-send)
 
 (defgroup notmuch-reply nil
-  "Replying to messages in notmuch"
+  "Replying to messages in notmuch."
   :group 'notmuch)
 
 (defcustom notmuch-mua-cite-function 'message-cite-original
@@ -144,9 +144,10 @@ (defcustom notmuch-mua-attachment-regexp
 ;;; Various functions
 
 (defun notmuch-mua-attachment-check ()
-  "Signal an error if the message text indicates that an
-attachment is expected but no MML referencing an attachment is
-found.
+  "Signal an error an attachement is expected but missing.
+
+Signal an error if the message text indicates that an attachment
+is expected but no MML referencing an attachment is found.
 
 Typically this is added to `notmuch-mua-send-hook'."
   (when (and
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 0c9a32ac..c006026c 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -141,20 +141,23 @@ (defcustom notmuch-tag-formats
      (notmuch-tag-format-image-data tag (notmuch-tag-star-icon))))
   "Custom formats for individual tags.
 
-This is an association list that maps from tag name regexps to
-lists of formatting expressions.  The first entry whose car
-regexp-matches a tag will be used to format that tag.  The regexp
-is implicitly anchored, so to match a literal tag name, just use
-that tag name (if it contains special regexp characters like
-\".\" or \"*\", these have to be escaped).  The cdr of the
-matching entry gives a list of Elisp expressions that modify the
-tag.  If the list is empty, the tag will simply be hidden.
-Otherwise, each expression will be evaluated in order: for the
-first expression, the variable `tag' will be bound to the tag
-name; for each later expression, the variable `tag' will be bound
-to the result of the previous expression.  In this way, each
+This is an association list of the form ((MATCH EXPR...)...),
+mapping tag name regexps to lists of formatting expressions.
+
+The first entry whose MATCH regexp-matches a tag is used to
+format that tag.  The regexp is implicitly anchored, so to match
+a literal tag name, just use that tag name (if it contains
+special regexp characters like \".\" or \"*\", these have to be
+escaped).
+
+The cdr of the matching entry gives a list of Elisp expressions
+that modify the tag.  If the list is empty, the tag is simply
+hidden.  Otherwise, each expression EXPR is evaluated in order:
+for the first expression, the variable `tag' is bound to the tag
+name; for each later expression, the variable `tag' is bound to
+the result of the previous expression.  In this way, each
 expression can build on the formatting performed by the previous
-expression.  The result of the last expression will displayed in
+expression.  The result of the last expression is displayed in
 place of the tag.
 
 For example, to replace a tag with another string, simply use
@@ -384,17 +387,15 @@ (defcustom notmuch-after-tag-hook nil
 ;;; User Input
 
 (defvar notmuch-select-tag-history nil
-  "Variable to store minibuffer history for
-`notmuch-select-tag-with-completion' function.")
+  "Minibuffer history of `notmuch-select-tag-with-completion' function.")
 
 (defvar notmuch-read-tag-changes-history nil
-  "Variable to store minibuffer history for
-`notmuch-read-tag-changes' function.")
+  "Minibuffer history of `notmuch-read-tag-changes' function.")
 
 (defun notmuch-tag-completions (&rest search-terms)
   "Return a list of tags for messages matching SEARCH-TERMS.
 
-Returns all tags if no search terms are given."
+Return all tags if no search terms are given."
   (unless search-terms
     (setq search-terms (list "*")))
   (split-string
@@ -411,8 +412,8 @@ (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
 (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
   "Prompt for tag changes in the minibuffer.
 
-CURRENT-TAGS is a list of tags that are present on the message or
-messages to be changed.  These are offered as tag removal
+CURRENT-TAGS is a list of tags that are present on the message
+or messages to be changed.  These are offered as tag removal
 completions.  CURRENT-TAGS may contain duplicates.  PROMPT, if
 non-nil, is the query string to present in the minibuffer.  It
 defaults to \"Tags\".  INITIAL-INPUT, if non-nil, will be the
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index e254593f..a06afc2d 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -791,8 +791,7 @@ (defun notmuch-tree-next-thread-from-search (&optional previous)
       (notmuch-tree-from-search-thread))))
 
 (defun notmuch-tree-next-thread (&optional previous)
-  "Move to the next thread in the current tree or parent search
-results
+  "Move to the next thread in the current tree or parent search results.
 
 If PREVIOUS is non-nil, move to the previous thread in the tree or
 search results instead."
@@ -802,14 +801,13 @@ (defun notmuch-tree-next-thread (&optional previous)
     (notmuch-tree-next-thread-from-search previous)))
 
 (defun notmuch-tree-prev-thread ()
-  "Move to the previous thread in the current tree or parent search
-results"
+  "Move to the previous thread in the current tree or parent search results."
   (interactive)
   (notmuch-tree-next-thread t))
 
 (defun notmuch-tree-thread-mapcar (function)
-  "Iterate through all messages in the current thread
- and call FUNCTION for side effects."
+  "Call FUNCTION for each message in the current thread.
+FUNCTION is called for side effects only."
   (save-excursion
     (notmuch-tree-thread-top)
     (cl-loop collect (funcall function)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 4e975d6a..20d2f095 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -494,7 +494,7 @@ (defun notmuch-search-find-thread-id (&optional bare)
 (defun notmuch-search-find-stable-query ()
   "Return the stable queries for the current thread.
 
-This returns a list (MATCHED-QUERY UNMATCHED-QUERY) for the
+Return a list (MATCHED-QUERY UNMATCHED-QUERY) for the
 matched and unmatched messages in the current thread."
   (plist-get (notmuch-search-get-result) :query))
 
@@ -599,7 +599,7 @@ (defun notmuch-search-get-tags-region (beg end)
 (defun notmuch-search-interactive-tag-changes (&optional initial-input)
   "Prompt for tag changes for the current thread or region.
 
-Returns (TAG-CHANGES REGION-BEGIN REGION-END)."
+Return (TAG-CHANGES REGION-BEGIN REGION-END)."
   (pcase-let ((`(,beg ,end) (notmuch-interactive-region)))
     (list (notmuch-read-tag-changes (notmuch-search-get-tags-region beg end)
 				    (if (= beg end) "Tag thread" "Tag region")
@@ -1105,10 +1105,10 @@ (defun notmuch-search-filter (query)
 		    notmuch-search-oldest-first)))
 
 (defun notmuch-search-filter-by-tag (tag)
-  "Filter the current search results based on a single tag.
+  "Filter the current search results based on a single TAG.
 
-Runs a new search matching only messages that match both the
-current search results AND that are tagged with the given tag."
+Run a new search matching only messages that match the current
+search results and that are also tagged with the given TAG."
   (interactive
    (list (notmuch-select-tag-with-completion "Filter by tag: "
 					     notmuch-search-query-string)))
@@ -1128,7 +1128,7 @@ (defun notmuch ()
   (notmuch-hello))
 
 (defun notmuch-interesting-buffer (b)
-  "Is the current buffer of interest to a notmuch user?"
+  "Whether the current buffer's major-mode is a notmuch mode."
   (with-current-buffer b
     (memq major-mode '(notmuch-show-mode
 		       notmuch-search-mode
@@ -1140,8 +1140,8 @@ (defun notmuch-interesting-buffer (b)
 (defun notmuch-cycle-notmuch-buffers ()
   "Cycle through any existing notmuch buffers (search, show or hello).
 
-If the current buffer is the only notmuch buffer, bury it. If no
-notmuch buffers exist, run `notmuch'."
+If the current buffer is the only notmuch buffer, bury it.
+If no notmuch buffers exist, run `notmuch'."
   (interactive)
   (let (start first)
     ;; If the current buffer is a notmuch buffer, remember it and then
@@ -1166,15 +1166,13 @@ (defun notmuch-cycle-notmuch-buffers ()
 
 (defun notmuch-search-imenu-prev-index-position-function ()
   "Move point to previous message in notmuch-search buffer.
-This function is used as a value for
-`imenu-prev-index-position-function'."
+Used as`imenu-prev-index-position-function' in notmuch buffers."
   (notmuch-search-previous-thread))
 
 (defun notmuch-search-imenu-extract-index-name-function ()
   "Return imenu name for line at point.
-This function is used as a value for
-`imenu-extract-index-name-function'.  Point should be at the
-beginning of the line."
+Used as `imenu-extract-index-name-function' in notmuch buffers.
+Point should be at the beginning of the line."
   (let ((subject (notmuch-search-find-subject))
 	(author (notmuch-search-find-authors)))
     (format "%s (%s)" subject author)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 26/32] emacs: remove variable notmuch-search-disjunctive-regexp
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (24 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 25/32] emacs: various doc-string improvements Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 27/32] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
                   ` (7 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch.el | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 20d2f095..35f825b9 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -232,8 +232,6 @@ (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
-(defvar notmuch-search-disjunctive-regexp "\\<[oO][rR]\\>")
-
 ;;; Movement
 
 (defun notmuch-search-scroll-up ()
@@ -1083,10 +1081,8 @@ (defun notmuch-search-toggle-order ()
 
 (defun notmuch-group-disjunctive-query-string (query-string)
   "Group query if it contains a complex expression.
-
-Enclose QUERY-STRING in parentheses if it matches
-`notmuch-search-disjunctive-regexp'."
-  (if (string-match-p notmuch-search-disjunctive-regexp query-string)
+Enclose QUERY-STRING in parentheses if contains \"OR\" operators."
+  (if (string-match-p "\\<[oO][rR]\\>" query-string)
       (concat "( " query-string " )")
     query-string))
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 27/32] emacs: define a few variables as automatically buffer-local
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (25 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 26/32] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 28/32] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
                   ` (6 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el |  1 +
 emacs/notmuch.el     | 16 ++++++----------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 72549a98..2fd9a27d 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -101,6 +101,7 @@ (defcustom notmuch-search-oldest-first t
 search."
   :type 'boolean
   :group 'notmuch-search)
+(make-variable-buffer-local 'notmuch-search-oldest-first)
 
 (defcustom notmuch-poll-script nil
   "[Deprecated] Command to run to incorporate new mail into the notmuch database.
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 35f825b9..464960e4 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -205,6 +205,12 @@ (defvar notmuch-search-mode-map
     map)
   "Keymap for \"notmuch search\" buffers.")
 
+;;; Internal Variables
+
+(defvar-local notmuch-search-query-string nil)
+(defvar-local notmuch-search-target-thread nil)
+(defvar-local notmuch-search-target-line nil)
+
 ;;; Stashing
 
 (defvar notmuch-search-stash-map
@@ -226,12 +232,6 @@ (defun notmuch-stash-query ()
   (interactive)
   (notmuch-common-do-stash (notmuch-search-get-query)))
 
-;;; Variables
-
-(defvar notmuch-search-query-string)
-(defvar notmuch-search-target-thread)
-(defvar notmuch-search-target-line)
-
 ;;; Movement
 
 (defun notmuch-search-scroll-up ()
@@ -404,10 +404,6 @@ (define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
 Complete list of currently available key bindings:
 
 \\{notmuch-search-mode-map}"
-  (make-local-variable 'notmuch-search-query-string)
-  (make-local-variable 'notmuch-search-oldest-first)
-  (make-local-variable 'notmuch-search-target-thread)
-  (make-local-variable 'notmuch-search-target-line)
   (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
   (setq-local scroll-preserve-screen-position t)
   (add-to-invisibility-spec (cons 'ellipsis t))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 28/32] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (26 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 27/32] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 29/32] emacs: reorder notmuch.el a bit Jonas Bernoulli
                   ` (5 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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: f47eeac0b0186c3559eb559c4f0bee0e1fac1961
   emacs: set default in notmuch-read-query
---
 emacs/notmuch.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 464960e4..0fb9874b 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -230,7 +230,7 @@ (defun notmuch-search-stash-thread-id ()
 (defun notmuch-stash-query ()
   "Copy current query to kill-ring."
   (interactive)
-  (notmuch-common-do-stash (notmuch-search-get-query)))
+  (notmuch-common-do-stash notmuch-search-query-string))
 
 ;;; Movement
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 29/32] emacs: reorder notmuch.el a bit
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (27 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 28/32] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:23 ` [PATCH 30/32] emacs: avoid unnecessary let-bindings Jonas Bernoulli
                   ` (4 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch.el | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 0fb9874b..24b930bf 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -70,6 +70,8 @@ (eval-when-compile (require 'cl-lib))
 (require 'mm-view)
 (require 'message)
 
+(require 'hl-line)
+
 (require 'notmuch-lib)
 (require 'notmuch-tag)
 (require 'notmuch-show)
@@ -114,8 +116,12 @@ (defcustom notmuch-init-file (locate-user-emacs-file "notmuch-config")
   :type 'file
   :group 'notmuch)
 
-(defvar notmuch-query-history nil
-  "Variable to store minibuffer history for notmuch queries.")
+(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
+  "List of functions to call when notmuch displays the search results."
+  :type 'hook
+  :options '(notmuch-hl-line-mode)
+  :group 'notmuch-search
+  :group 'notmuch-hooks)
 
 ;;; Mime Utilities
 
@@ -155,24 +161,6 @@ (defun notmuch-save-attachments (mm-handle &optional queryp)
 	    (mm-save-part p))))
    mm-handle))
 
-;;; Integrations
-
-(require 'hl-line)
-
-(defun notmuch-hl-line-mode ()
-  (prog1 (hl-line-mode)
-    (when hl-line-overlay
-      (overlay-put hl-line-overlay 'priority 1))))
-
-;;; Options
-
-(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
-  "List of functions to call when notmuch displays the search results."
-  :type 'hook
-  :options '(notmuch-hl-line-mode)
-  :group 'notmuch-search
-  :group 'notmuch-hooks)
-
 ;;; Keymap
 
 (defvar notmuch-search-mode-map
@@ -207,6 +195,9 @@ (defvar notmuch-search-mode-map
 
 ;;; Internal Variables
 
+(defvar notmuch-query-history nil
+  "Variable to store minibuffer history for notmuch queries.")
+
 (defvar-local notmuch-search-query-string nil)
 (defvar-local notmuch-search-target-thread nil)
 (defvar-local notmuch-search-target-line nil)
@@ -1154,7 +1145,15 @@ (defun notmuch-cycle-notmuch-buffers ()
 	  (pop-to-buffer-same-window first))
       (notmuch))))
 
-;;; Imenu Support
+;;; Integrations
+;;;; Hl-line Support
+
+(defun notmuch-hl-line-mode ()
+  (prog1 (hl-line-mode)
+    (when hl-line-overlay
+      (overlay-put hl-line-overlay 'priority 1))))
+
+;;;; Imenu Support
 
 (defun notmuch-search-imenu-prev-index-position-function ()
   "Move point to previous message in notmuch-search buffer.
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 30/32] emacs: avoid unnecessary let-bindings
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (28 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 29/32] emacs: reorder notmuch.el a bit Jonas Bernoulli
@ 2020-12-14 16:23 ` Jonas Bernoulli
  2020-12-14 16:24 ` [PATCH 31/32] emacs: use string-empty-p Jonas Bernoulli
                   ` (3 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:23 UTC (permalink / raw)
  To: notmuch

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)?
---
 emacs/notmuch-address.el     |  4 +--
 emacs/notmuch-lib.el         |  6 ++---
 emacs/notmuch-maildir-fcc.el | 10 ++++----
 emacs/notmuch-show.el        | 14 +++++-----
 emacs/notmuch-tag.el         | 10 ++++----
 emacs/notmuch-tree.el        |  5 ++--
 emacs/notmuch.el             | 50 +++++++++++++++++-------------------
 7 files changed, 48 insertions(+), 51 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1f22e377..f313c415 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -260,8 +260,8 @@ (defun notmuch-address-expand-name ()
 ;;; Harvest
 
 (defun notmuch-address-harvest-addr (result)
-  (let ((name-addr (plist-get result :name-addr)))
-    (puthash name-addr t notmuch-address-completions)))
+  (puthash (plist-get result :name-addr)
+	   t notmuch-address-completions))
 
 (defun notmuch-address-harvest-filter (proc string)
   (when (buffer-live-p (process-buffer proc))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2fd9a27d..cbac8859 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -416,9 +416,9 @@ (defun notmuch-help ()
 its prefixed behavior by setting the 'notmuch-prefix-doc property
 of its command symbol."
   (interactive)
-  (let* ((mode major-mode)
-	 (doc (substitute-command-keys
-	       (notmuch-substitute-command-keys (documentation mode t)))))
+  (let ((doc (substitute-command-keys
+	      (notmuch-substitute-command-keys
+	       (documentation major-mode t)))))
     (with-current-buffer (generate-new-buffer "*notmuch-help*")
       (insert doc)
       (goto-char (point-min))
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 0000863d..8a5c5640 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -207,11 +207,11 @@ (defun notmuch-maildir-notmuch-insert-current-buffer (folder &optional create ta
 database in folder FOLDER. If CREATE is non-nil it will supply
 the --create-folder flag to create the folder if necessary. TAGS
 should be a list of tag changes to apply to the inserted message."
-  (let* ((args (append (and create (list "--create-folder"))
-		       (list (concat "--folder=" folder))
-		       tags)))
-    (apply 'notmuch-call-notmuch-process
-	   :stdin-string (buffer-string) "insert" args)))
+  (apply 'notmuch-call-notmuch-process
+	 :stdin-string (buffer-string) "insert"
+	 (append (and create (list "--create-folder"))
+		 (list (concat "--folder=" folder))
+		 tags)))
 
 (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
   "Store message with notmuch insert.
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 48374b38..27925669 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1666,13 +1666,13 @@ (defun notmuch-show-get-prop (prop &optional props)
 message in either tree or show. This means that several utility
 functions in notmuch-show can be used directly by notmuch-tree as
 they just need the correct message properties."
-  (let ((props (or props
-		   (cond ((eq major-mode 'notmuch-show-mode)
-			  (notmuch-show-get-message-properties))
-			 ((eq major-mode 'notmuch-tree-mode)
-			  (notmuch-tree-get-message-properties))
-			 (t nil)))))
-    (plist-get props prop)))
+  (plist-get (or props
+		 (cond ((eq major-mode 'notmuch-show-mode)
+			(notmuch-show-get-message-properties))
+		       ((eq major-mode 'notmuch-tree-mode)
+			(notmuch-tree-get-message-properties))
+		       (t nil)))
+	     prop))
 
 (defun notmuch-show-get-message-id (&optional bare)
   "Return an id: query for the Message-Id of the current message.
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index c006026c..3c958dd4 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -406,8 +406,9 @@ (defun notmuch-tag-completions (&rest search-terms)
    "\n+" t))
 
 (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
-  (let ((tag-list (apply #'notmuch-tag-completions search-terms)))
-    (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
+  (completing-read prompt
+		   (apply #'notmuch-tag-completions search-terms)
+		   nil nil nil 'notmuch-select-tag-history))
 
 (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
   "Prompt for tag changes in the minibuffer.
@@ -455,10 +456,9 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((op (aref tag-change 0))
-	    (tag (and (not (string= tag-change ""))
+      (let ((tag (and (not (string= tag-change ""))
 		      (substring tag-change 1))))
-	(cl-case op
+	(cl-case (aref tag-change 0)
 	  (?+ (unless (member tag result-tags)
 		(push tag result-tags)))
 	  (?- (setq result-tags (delete tag result-tags)))
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index a06afc2d..51a43edd 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -401,9 +401,8 @@ (defun notmuch-tree-set-prop (prop val &optional props)
     (notmuch-tree-set-message-properties props)))
 
 (defun notmuch-tree-get-prop (prop &optional props)
-  (let ((props (or props
-		   (notmuch-tree-get-message-properties))))
-    (plist-get props prop)))
+  (plist-get (or props (notmuch-tree-get-message-properties))
+	     prop))
 
 (defun notmuch-tree-set-tags (tags)
   "Set the tags of the current message."
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 24b930bf..6553893b 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -521,17 +521,16 @@ (defun notmuch-search-show-thread (&optional elide-toggle)
 `notmuch-show-only-matching-messages' when displaying the
 thread."
   (interactive "P")
-  (let ((thread-id (notmuch-search-find-thread-id))
-	(subject (notmuch-search-find-subject)))
-    (if (> (length thread-id) 0)
+  (let ((thread-id (notmuch-search-find-thread-id)))
+    (if thread-id
 	(notmuch-show thread-id
 		      elide-toggle
 		      (current-buffer)
 		      notmuch-search-query-string
 		      ;; Name the buffer based on the subject.
-		      (concat "*"
-			      (truncate-string-to-width subject 30 nil nil t)
-			      "*"))
+		      (format "*%s*" (truncate-string-to-width
+				      (notmuch-search-find-subject)
+				      30 nil nil t)))
       (message "End of search results."))))
 
 (defun notmuch-tree-from-search-current-query ()
@@ -556,20 +555,21 @@ (defun notmuch-tree-from-search-thread ()
 (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
   "Begin composing a reply-all to the entire current thread in a new buffer."
   (interactive "P")
-  (let ((message-id (notmuch-search-find-thread-id)))
-    (notmuch-mua-new-reply message-id prompt-for-sender t)))
+  (notmuch-mua-new-reply (notmuch-search-find-thread-id)
+			 prompt-for-sender t))
 
 (defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
   "Begin composing a reply to the entire current thread in a new buffer."
   (interactive "P")
-  (let ((message-id (notmuch-search-find-thread-id)))
-    (notmuch-mua-new-reply message-id prompt-for-sender nil)))
+  (notmuch-mua-new-reply (notmuch-search-find-thread-id)
+			 prompt-for-sender nil))
 
 ;;; Tags
 
 (defun notmuch-search-set-tags (tags &optional pos)
-  (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))
-    (notmuch-search-update-result new-result pos)))
+  (notmuch-search-update-result
+   (plist-put (notmuch-search-get-result pos) :tags tags)
+   pos))
 
 (defun notmuch-search-get-tags (&optional pos)
   (plist-get (notmuch-search-get-result pos) :tags))
@@ -1017,10 +1017,9 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
     (setq notmuch-search-target-thread target-thread)
     (setq notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
-    (let ((proc (get-buffer-process (current-buffer)))
-	  (inhibit-read-only t))
-      (when proc
-	(error "notmuch search process already running for query `%s'" query))
+    (when (get-buffer-process buffer)
+      (error "notmuch search process already running for query `%s'" query))
+    (let ((inhibit-read-only t))
       (erase-buffer)
       (goto-char (point-min))
       (save-excursion
@@ -1049,13 +1048,12 @@ (defun notmuch-search-refresh-view ()
 thread. Otherwise, point will be moved to attempt to be in the
 same relative position within the new buffer."
   (interactive)
-  (let ((target-line (line-number-at-pos))
-	(oldest-first notmuch-search-oldest-first)
-	(target-thread (notmuch-search-find-thread-id 'bare))
-	(query notmuch-search-query-string))
-    ;; notmuch-search erases the current buffer.
-    (notmuch-search query oldest-first target-thread target-line t)
-    (goto-char (point-min))))
+  (notmuch-search notmuch-search-query-string
+		  notmuch-search-oldest-first
+		  (notmuch-search-find-thread-id 'bare)
+		  (line-number-at-pos)
+		  t)
+  (goto-char (point-min)))
 
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
@@ -1164,9 +1162,9 @@ (defun notmuch-search-imenu-extract-index-name-function ()
   "Return imenu name for line at point.
 Used as `imenu-extract-index-name-function' in notmuch buffers.
 Point should be at the beginning of the line."
-  (let ((subject (notmuch-search-find-subject))
-	(author (notmuch-search-find-authors)))
-    (format "%s (%s)" subject author)))
+  (format "%s (%s)"
+	  (notmuch-search-find-subject)
+	  (notmuch-search-find-authors)))
 
 ;;; _
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 31/32] emacs: use string-empty-p
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (29 preceding siblings ...)
  2020-12-14 16:23 ` [PATCH 30/32] emacs: avoid unnecessary let-bindings Jonas Bernoulli
@ 2020-12-14 16:24 ` Jonas Bernoulli
  2020-12-14 16:24 ` [PATCH 32/32] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
                   ` (2 subsequent siblings)
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:24 UTC (permalink / raw)
  To: notmuch

Unfortunately that means we have to explicitly require subr-x, which
arguably should always be loaded without packages having to require
it, but the Emacs developers decided otherwise.  Loading it explicitly
most likely comes without any additional cost because almost certainly
some other packages would load it anyway--the functions it defines are
that popular.  And we are likely to use other functions from subr-x in
the future.
---
 emacs/notmuch-lib.el  | 3 ++-
 emacs/notmuch-mua.el  | 3 ++-
 emacs/notmuch-show.el | 5 +++--
 emacs/notmuch-tag.el  | 3 ++-
 emacs/notmuch.el      | 5 +++--
 5 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index cbac8859..7a64e728 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'subr-x)
 
 (require 'mm-util)
 (require 'mm-view)
@@ -283,7 +284,7 @@ (defun notmuch-poll ()
   (interactive)
   (message "Polling mail...")
   (if (stringp notmuch-poll-script)
-      (unless (string= notmuch-poll-script "")
+      (unless (string-empty-p notmuch-poll-script)
 	(unless (equal (call-process notmuch-poll-script nil nil) 0)
 	  (error "Notmuch: poll script `%s' failed!" notmuch-poll-script)))
     (notmuch-call-notmuch-process "new"))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 2e4dc71a..a8643522 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib))
+(require 'subr-x)
 
 (require 'message)
 (require 'mm-view)
@@ -390,7 +391,7 @@ (defun notmuch-mua-mail (&optional to subject other-headers _continue
   (interactive)
   (when notmuch-mua-user-agent-function
     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
-      (unless (string= "" user-agent)
+      (unless (string-empty-p user-agent)
 	(push (cons 'User-Agent user-agent) other-headers))))
   (unless (assq 'From other-headers)
     (push (cons 'From (message-make-from
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 27925669..13d08b62 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (eval-when-compile
   (require 'cl-lib)
   (require 'pcase))
+(require 'subr-x)
 
 (require 'mm-view)
 (require 'message)
@@ -337,7 +338,7 @@ (defun notmuch-show-with-message-as-text (fn)
 	 (header (concat
 		  "Subject: " subject "\n"
 		  "To: " to "\n"
-		  (if (not (string= cc ""))
+		  (if (not (string-empty-p cc))
 		      (concat "Cc: " cc "\n")
 		    "")
 		  "From: " from "\n"
@@ -1794,7 +1795,7 @@ (defun notmuch-show-filter-thread (query)
 Reshows the current thread with matches defined by the new query-string."
   (interactive (list (notmuch-read-query "Filter thread: ")))
   (let ((msg-id (notmuch-show-get-message-id)))
-    (setq notmuch-show-query-context (if (string= query "") nil query))
+    (setq notmuch-show-query-context (if (string-empty-p query) nil query))
     (notmuch-show-refresh-view t)
     (notmuch-show-goto-message msg-id)))
 
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 3c958dd4..1e8f7d4d 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -26,6 +26,7 @@
 (require 'cl-lib)
 (eval-when-compile
   (require 'pcase))
+(require 'subr-x)
 
 (require 'crm)
 
@@ -456,7 +457,7 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((tag (and (not (string= tag-change ""))
+      (let ((tag (and (not (string-empty-p tag-change))
 		      (substring tag-change 1))))
 	(cl-case (aref tag-change 0)
 	  (?+ (unless (member tag result-tags)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6553893b..860b3d6a 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -66,6 +66,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib))
+(require 'subr-x)
 
 (require 'mm-view)
 (require 'message)
@@ -816,13 +817,13 @@ (defun notmuch-search-insert-authors (format-string authors)
 	(setq invisible-string (notmuch-search-author-propertize invisible-string)))
       ;; If there is any invisible text, add it as a tooltip to the
       ;; visible text.
-      (unless (string= invisible-string "")
+      (unless (string-empty-p invisible-string)
 	(setq visible-string
 	      (propertize visible-string
 			  'help-echo (concat "..." invisible-string))))
       ;; Insert the visible and, if present, invisible author strings.
       (insert visible-string)
-      (unless (string= invisible-string "")
+      (unless (string-empty-p invisible-string)
 	(let ((start (point))
 	      overlay)
 	  (insert invisible-string)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH 32/32] emacs: notmuch-tree-get-match: No longer define as command
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (30 preceding siblings ...)
  2020-12-14 16:24 ` [PATCH 31/32] emacs: use string-empty-p Jonas Bernoulli
@ 2020-12-14 16:24 ` Jonas Bernoulli
  2020-12-27 10:14 ` [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
  33 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-14 16:24 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-tree.el | 1 -
 1 file changed, 1 deletion(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 51a43edd..bd0e0945 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -423,7 +423,6 @@ (defun notmuch-tree-get-message-id (&optional bare)
 
 (defun notmuch-tree-get-match ()
   "Return whether the current message is a match."
-  (interactive)
   (notmuch-tree-get-prop :match))
 
 ;;; Update display
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* Re: [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (31 preceding siblings ...)
  2020-12-14 16:24 ` [PATCH 32/32] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
@ 2020-12-27 10:14 ` Tomi Ollila
  2020-12-28 14:08   ` Tomi Ollila
  2020-12-30 17:10   ` Jonas Bernoulli
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
  33 siblings, 2 replies; 79+ messages in thread
From: Tomi Ollila @ 2020-12-27 10:14 UTC (permalink / raw)
  To: Jonas Bernoulli, notmuch

On Mon, Dec 14 2020, Jonas Bernoulli wrote:

> Hello,
>
> This patch serious changes a number of things, including boring
> cleanup, but the big changes are the following.  The respective
> commits are also marked in the list below.  See these commits
> for longer descriptions.
>
> 1. Split all libraries into sections by adding new headings or
>    formatting existing headings properly to be compatible with
>    outline-minor-mode.
>
> 2. Use lexical-scope in all libraries.  This is potentially faster
>    and is recommended for all new code (and old code someone cares
>    about enough).  It also has the advantage that it can reveal
>    subtle bugs.

The patch series did not apply for me (fully) anymore. First had to
be skipped, then two of more of the last, therefore I did not put
this into use for now (as, if it fails I don't know whether the
reason is dropped changes or my way of building it...)

I like the series (on paper), 2 comments

In patch 23/32, line
 +	    (y-or-n-p (format "Fcc header %s is an absolute path%s%s" subdir
should be
 +	    (y-or-n-p (format "Fcc header %s is an absolute path %s %s" subdir

(I.e. spaces around %s's)

Then, I personally don't see enough point for requiring subr-x
just just for changing (string= foo "") to (string-empty-p). If
there were more features picked from subr-x then that would be
different...

> Among the many more commits that do not concern these two big
> changes, there are a few that might need special attention.
> (Again see the commits for details.)
>
> 3. No longer use Ido in notmuch-mua-prompt-for-sender.  Might be
>    controversial.
>
> 4. Stop using unnecessary let-bindings, though how "unnecessary"
>    these bindings are is somewhat subjective.

I like these two changes.

>
>      Cheers,
>      Jonas

Tomi

PS: I used the following code to drop cr's (\r) from base64-encoded
    text blobs; just enough to work in this particular case.

#!/usr/bin/perl
# -*- mode: cperl; cperl-indent-level: 4 -*-

use 5.8.1;
use strict;
use warnings;
use MIME::Base64;

while (<STDIN>) {
    print $_;
    if (/^Content-Transfer-Encoding: base64/) {
	while (<STDIN>) { print $_; last if /^\s*$/ }
	my @lines;
	while (<STDIN>) { last if /^\s*$/; push @lines, $_ }
	my $decoded = decode_base64 join('', @lines);
	$decoded =~ tr/\r//d;
	print(encode_base64 $decoded);
	print "\n"
    }
}

^ permalink raw reply	[flat|nested] 79+ messages in thread

* Re: [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope
  2020-12-27 10:14 ` [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
@ 2020-12-28 14:08   ` Tomi Ollila
  2020-12-30 17:10   ` Jonas Bernoulli
  1 sibling, 0 replies; 79+ messages in thread
From: Tomi Ollila @ 2020-12-28 14:08 UTC (permalink / raw)
  To: Jonas Bernoulli, notmuch

On Sun, Dec 27 2020, Tomi Ollila wrote:

> On Mon, Dec 14 2020, Jonas Bernoulli wrote:
>
>> Hello,
>>
>> This patch serious changes a number of things, including boring
>> cleanup, but the big changes are the following.  The respective
>> commits are also marked in the list below.  See these commits
>> for longer descriptions.
>>
>> 1. Split all libraries into sections by adding new headings or
>>    formatting existing headings properly to be compatible with
>>    outline-minor-mode.
>>
>> 2. Use lexical-scope in all libraries.  This is potentially faster
>>    and is recommended for all new code (and old code someone cares
>>    about enough).  It also has the advantage that it can reveal
>>    subtle bugs.
>
> The patch series did not apply for me (fully) anymore. First had to

Ok, applied when using `git am -3`

Sending this email to remind everyone the --3way option of git-am,
as it is forgotten so often (or then it is just me).

Now I have this series in use, which my User-Agent: may also reveal
(Notmuch/0.31.3+70~g95b022c (https://notmuchmail.org) Emacs/27.1).

Tomi

> be skipped, then two of more of the last, therefore I did not put
> this into use for now (as, if it fails I don't know whether the
> reason is dropped changes or my way of building it...)
>
> I like the series (on paper), 2 comments
>
> In patch 23/32, line
>  +	    (y-or-n-p (format "Fcc header %s is an absolute path%s%s" subdir
> should be
>  +	    (y-or-n-p (format "Fcc header %s is an absolute path %s %s" subdir
>
> (I.e. spaces around %s's)
>
> Then, I personally don't see enough point for requiring subr-x
> just just for changing (string= foo "") to (string-empty-p). If
> there were more features picked from subr-x then that would be
> different...
>
>> Among the many more commits that do not concern these two big
>> changes, there are a few that might need special attention.
>> (Again see the commits for details.)
>>
>> 3. No longer use Ido in notmuch-mua-prompt-for-sender.  Might be
>>    controversial.
>>
>> 4. Stop using unnecessary let-bindings, though how "unnecessary"
>>    these bindings are is somewhat subjective.
>
> I like these two changes.
>
>>
>>      Cheers,
>>      Jonas
>
> Tomi
>
> PS: I used the following code to drop cr's (\r) from base64-encoded
>     text blobs; just enough to work in this particular case.
>
> #!/usr/bin/perl
> # -*- mode: cperl; cperl-indent-level: 4 -*-
>
> use 5.8.1;
> use strict;
> use warnings;
> use MIME::Base64;
>
> while (<STDIN>) {
>     print $_;
>     if (/^Content-Transfer-Encoding: base64/) {
> 	while (<STDIN>) { print $_; last if /^\s*$/ }
> 	my @lines;
> 	while (<STDIN>) { last if /^\s*$/; push @lines, $_ }
> 	my $decoded = decode_base64 join('', @lines);
> 	$decoded =~ tr/\r//d;
> 	print(encode_base64 $decoded);
> 	print "\n"
>     }
> }

^ permalink raw reply	[flat|nested] 79+ messages in thread

* Re: [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope
  2020-12-27 10:14 ` [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
  2020-12-28 14:08   ` Tomi Ollila
@ 2020-12-30 17:10   ` Jonas Bernoulli
  1 sibling, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2020-12-30 17:10 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:

> The patch series did not apply for me (fully) anymore.

Since you got it applied now I am not sending a second iteration just
yet, or should I?

By the way, a regularly rebased version can be found in the "pending"
branch at https://github.com/tarsiiformes/notmuch.git.  Currently it
ends with two additional commits that are not from this patch series but
which I have submitted separately (their commit messages are prefixed
with "[copy]").

> I like the series (on paper), 2 comments

:D

> In patch 23/32, line

Fixed

> Then, I personally don't see enough point for requiring subr-x
> just just for changing (string= foo "") to (string-empty-p). If
> there were more features picked from subr-x then that would be
> different...

I was on the fence about that too.  I left it in for now but have
no problems removing it before merge.

     Thanks for taking a look,
     Jonas

^ permalink raw reply	[flat|nested] 79+ messages in thread

* [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope
  2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
                   ` (32 preceding siblings ...)
  2020-12-27 10:14 ` [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
@ 2021-01-10 14:00 ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 01/36] emacs: use setq instead of set Jonas Bernoulli
                     ` (37 more replies)
  33 siblings, 38 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

This fixes a minor whitespace bug that Tomi notices in (1).

This also adds for commits, two of them in response to a concern
raised by Tomi, who didn't "see enough point for requiring subr-x
just [for string-empty-p]", which I agree with:

2) Changes how `cl-lib' and `pcase' are required.  I did that first
   because I want to do it the same way as for `subr-x'.

3) Require `subr-x', so that we can use it without having to worry
   whether we have now reached the threshold where it becomes
   justified to require an additional library.

   Personally I consider this library to be part of core elisp
   libraries, and wish it were autoloaded like, say `subr'.  I am
   not the only one with that opinion and some other package is
   bound to load this very small library anyways, so we might as
   well benefit from the goodies that it provides too.

The remaining two new commits (4,5) I have already submitted earlier
in a separate thread.  Unfortunately they did not get merged or even
just discussed so far, so I am including them here again.

     Cheers,
     Jonas

Jonas Bernoulli (36):
  emacs: use setq instead of set
  emacs: sanitize dedicated widget action/notify functions
  emacs: define new notmuch-search-item widget type
  emacs: notmuch-start-notmuch: remove backward compatibility code
  emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive
  emacs: notmuch-start-notmuch-sentinel: assert buffer is alive
  emacs: notmuch-start-notmuch: avoid storing process buffer twice
  emacs: avoid passing around some redundant information
  emacs: avoid killing process buffer when process is still alive
  emacs: make headings outline-minor-mode compatible
  emacs: use lexical-bindings in all libraries
  emacs: deal with unused lexical arguments and variables
  emacs: notmuch-tag--get-formats: silence byte-compiler
  emacs: inline notmuch-sexp-eof into only caller
  emacs: notmuch-wash-region-to-button: remove unused MSG argument
  emacs: silence compiler wrt notmuch-show-insert-part-text/plain
  emacs: define notmuch-message-queued-tag-changes as buffer-local
  emacs: notmuch-message-apply-queued-tag-changes: cosmetics
  emacs: notmuch-wash.el: require diff-mode at beginning of code
  emacs: notmuch-mua-prompt-for-sender: don't force Ido on users
  emacs: notmuch-mua.el: move all options into "Options" section
  emacs: notmuch-crypto-status-button-type: fix potential bug
1 emacs: various cosmetic improvements
  emacs: various comment improvements
  emacs: various doc-string improvements
  emacs: remove variable notmuch-search-disjunctive-regexp
  emacs: define a few variables as automatically buffer-local
  emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string
  emacs: reorder notmuch.el a bit
  emacs: avoid unnecessary let-bindings
2 emacs: improve how cl-lib and pcase are required
3 emacs: make subr-x available in all libraries
  emacs: use string-empty-p
  emacs: notmuch-tree-get-match: No longer define as command
4 emacs: allow opting out of notmuch's address completion
5 emacs: notmuch-address-expand-name: use the actual initial-input

 emacs/coolj.el               |  14 +-
 emacs/make-deps.el           |   2 +-
 emacs/notmuch-address.el     | 103 +++++++-------
 emacs/notmuch-company.el     |   3 -
 emacs/notmuch-compat.el      |   4 +-
 emacs/notmuch-crypto.el      |  14 +-
 emacs/notmuch-draft.el       |  27 +++-
 emacs/notmuch-hello.el       | 229 +++++++++++++++---------------
 emacs/notmuch-jump.el        |  18 +--
 emacs/notmuch-lib.el         | 199 +++++++++++++-------------
 emacs/notmuch-maildir-fcc.el | 114 +++++++--------
 emacs/notmuch-message.el     |  25 ++--
 emacs/notmuch-mua.el         | 124 +++++++++--------
 emacs/notmuch-parser.el      |  22 ++-
 emacs/notmuch-print.el       |  16 ++-
 emacs/notmuch-query.el       |  21 ++-
 emacs/notmuch-show.el        | 130 ++++++++++-------
 emacs/notmuch-tag.el         | 103 ++++++++------
 emacs/notmuch-tree.el        |  61 ++++----
 emacs/notmuch-wash.el        |  54 ++++----
 emacs/notmuch.el             | 261 ++++++++++++++++++-----------------
 emacs/rstdoc.el              |   2 +-
 test/test-lib.el             |   4 +-
 23 files changed, 813 insertions(+), 737 deletions(-)

-- 
2.29.1

^ permalink raw reply	[flat|nested] 79+ messages in thread

* [PATCH v2 01/36] emacs: use setq instead of set
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 02/36] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
                     ` (36 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

Commonly `set' is only used if there is no way around it;
i.e. when the variable cannot be known until runtime.
---
 emacs/notmuch-tree.el |  2 +-
 emacs/notmuch.el      | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 57843e25..17863f6a 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1133,7 +1133,7 @@ (defun notmuch-tree (&optional query query-context target buffer-name open-targe
 	(inhibit-read-only t))
     (pop-to-buffer-same-window buffer))
   ;; Don't track undo information for this buffer
-  (set 'buffer-undo-list t)
+  (setq buffer-undo-list t)
   (notmuch-tree-worker query query-context target open-target unthreaded)
   (setq notmuch-tree-parent-buffer parent-buffer)
   (setq truncate-lines t))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 132e7724..bba4ca03 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -693,7 +693,7 @@ (defun notmuch-search-process-sentinel (proc msg)
 		    (throw 'return nil))
 		  (when (and atbob
 			     (not (string= notmuch-search-target-thread "found")))
-		    (set 'never-found-target-thread t)))))
+		    (setq never-found-target-thread t)))))
 	    (when (and never-found-target-thread
 		       notmuch-search-target-line)
 	      (goto-char (point-min))
@@ -996,11 +996,11 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
       (pop-to-buffer-same-window buffer))
     (notmuch-search-mode)
     ;; Don't track undo information for this buffer
-    (set 'buffer-undo-list t)
-    (set 'notmuch-search-query-string query)
-    (set 'notmuch-search-oldest-first oldest-first)
-    (set 'notmuch-search-target-thread target-thread)
-    (set 'notmuch-search-target-line target-line)
+    (setq buffer-undo-list t)
+    (setq notmuch-search-query-string query)
+    (setq notmuch-search-oldest-first oldest-first)
+    (setq notmuch-search-target-thread target-thread)
+    (setq notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
     (let ((proc (get-buffer-process (current-buffer)))
 	  (inhibit-read-only t))
@@ -1048,7 +1048,7 @@ (defun notmuch-search-toggle-order ()
 This command toggles the sort order for the current search. The
 default sort order is defined by `notmuch-search-oldest-first'."
   (interactive)
-  (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
+  (setq notmuch-search-oldest-first (not notmuch-search-oldest-first))
   (notmuch-search-refresh-view))
 
 (defun notmuch-group-disjunctive-query-string (query-string)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 02/36] emacs: sanitize dedicated widget action/notify functions
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 01/36] emacs: use setq instead of set Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 03/36] emacs: define new notmuch-search-item widget type Jonas Bernoulli
                     ` (35 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

These functions are used as action/notify functions.  That dictates
the appropriate function signatures but even though these functions
are not used for anything else they use incompatible signatures,
forcing the callers to use lambda expressions to deal with these
incompatibilities.

Fix that by adjusting the function signatures to the needs of the
only intended callers.

Two of these functions were defined as commands but because the
interactive form did not return the mandatory arguments, we know
that nobody (successfully) used these as commands.

In one case we move the location of a y-or-n-p prompt.
---
 emacs/notmuch-hello.el | 47 +++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index fa31694f..767c6874 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -385,18 +385,16 @@ (defun notmuch-hello-nice-number (n)
 		     (format "%s%03d" notmuch-hello-thousands-separator elem))
 		   (cdr result)))))
 
-(defun notmuch-hello-search (&optional search)
-  (unless (null search)
-    (setq search (string-trim search))
-    (let ((history-delete-duplicates t))
-      (add-to-history 'notmuch-search-history search)))
-  (notmuch-search search notmuch-search-oldest-first))
-
-(defun notmuch-hello-add-saved-search (widget)
-  (interactive)
-  (let ((search (widget-value
-		 (symbol-value
-		  (widget-get widget :notmuch-saved-search-widget))))
+(defun notmuch-hello-search (widget &rest _event)
+  (let ((search (widget-value widget)))
+    (when search
+      (setq search (string-trim search))
+      (let ((history-delete-duplicates t))
+	(add-to-history 'notmuch-search-history search)))
+    (notmuch-search search notmuch-search-oldest-first)))
+
+(defun notmuch-hello-add-saved-search (widget &rest _event)
+  (let ((search (widget-value (widget-get widget :parent)))
 	(name (completing-read "Name for saved search: "
 			       notmuch-saved-searches)))
     ;; If an existing saved search with this name exists, remove it.
@@ -412,13 +410,11 @@ (defun notmuch-hello-add-saved-search (widget)
     (message "Saved '%s' as '%s'." search name)
     (notmuch-hello-update)))
 
-(defun notmuch-hello-delete-search-from-history (widget)
-  (interactive)
-  (let ((search (widget-value
-		 (symbol-value
-		  (widget-get widget :notmuch-saved-search-widget)))))
-    (setq notmuch-search-history (delete search
-					 notmuch-search-history))
+(defun notmuch-hello-delete-search-from-history (widget &rest _event)
+  (when (y-or-n-p "Are you sure you want to delete this search? ")
+    (let ((search (widget-value (widget-get widget :parent))))
+      (setq notmuch-search-history
+	    (delete search notmuch-search-history)))
     (notmuch-hello-update)))
 
 (defun notmuch-hello-longest-label (searches-alist)
@@ -768,8 +764,7 @@ (defun notmuch-hello-insert-search ()
 		 ;; search boxes.
 		 :size (max 8 (- (window-width) notmuch-hello-indent
 				 (length "Search: ")))
-		 :action (lambda (widget &rest ignore)
-			   (notmuch-hello-search (widget-value widget))))
+		 :action #'notmuch-hello-search)
   ;; Add an invisible dot to make `widget-end-of-line' ignore
   ;; trailing spaces in the search widget field.  A dot is used
   ;; instead of a space to make `show-trailing-whitespace'
@@ -816,20 +811,16 @@ (defun notmuch-hello-insert-recent-searches ()
 						   ;; button. 5 for the
 						   ;; `[del]' button.
 						   1 5))
-				     :action (lambda (widget &rest ignore)
-					       (notmuch-hello-search (widget-value widget)))
+				     :action #'notmuch-hello-search
 				     search))
 		 (widget-insert " ")
 		 (widget-create 'push-button
-				:notify (lambda (widget &rest ignore)
-					  (notmuch-hello-add-saved-search widget))
+				:notify #'notmuch-hello-add-saved-search
 				:notmuch-saved-search-widget widget-symbol
 				"save")
 		 (widget-insert " ")
 		 (widget-create 'push-button
-				:notify (lambda (widget &rest ignore)
-					  (when (y-or-n-p "Are you sure you want to delete this search? ")
-					    (notmuch-hello-delete-search-from-history widget)))
+				:notify #'notmuch-hello-delete-search-from-history
 				:notmuch-saved-search-widget widget-symbol
 				"del"))
 	       (widget-insert "\n"))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 03/36] emacs: define new notmuch-search-item widget type
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 01/36] emacs: use setq instead of set Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 02/36] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 04/36] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
                     ` (34 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

This is complex enough to warrant a dedicated widget type,
which will make future improvements less messy to implement.
---
 emacs/notmuch-hello.el | 92 +++++++++++++++++++++---------------------
 1 file changed, 45 insertions(+), 47 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 767c6874..7bc713f3 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -385,6 +385,40 @@ (defun notmuch-hello-nice-number (n)
 		     (format "%s%03d" notmuch-hello-thousands-separator elem))
 		   (cdr result)))))
 
+(define-widget 'notmuch-search-item 'item
+  "A recent search."
+  :format "%v\n"
+  :value-create 'notmuch-search-item-value-create)
+
+(defun notmuch-search-item-value-create (widget)
+  (let ((value (widget-get widget :value)))
+    (widget-insert (make-string notmuch-hello-indent ?\s))
+    (widget-create 'editable-field
+		   :size (widget-get widget :size)
+		   :parent widget
+		   :action #'notmuch-hello-search
+		   value)
+    (widget-insert " ")
+    (widget-create 'push-button
+		   :parent widget
+		   :notify #'notmuch-hello-add-saved-search
+		   "save")
+    (widget-insert " ")
+    (widget-create 'push-button
+		   :parent widget
+		   :notify #'notmuch-hello-delete-search-from-history
+		   "del")))
+
+(defun notmuch-search-item-field-width ()
+  (max 8 ; Don't let the search boxes be less than 8 characters wide.
+       (- (window-width)
+	  notmuch-hello-indent ; space at bol
+	  notmuch-hello-indent ; space at eol
+	  1    ; for the space before the [save] button
+	  6    ; for the [save] button
+	  1    ; for the space before the [del] button
+	  5))) ; for the [del] button
+
 (defun notmuch-hello-search (widget &rest _event)
   (let ((search (widget-value widget)))
     (when search
@@ -778,54 +812,18 @@ (defun notmuch-hello-insert-recent-searches ()
   "Insert recent searches."
   (when notmuch-search-history
     (widget-insert "Recent searches: ")
-    (widget-create 'push-button
-		   :notify (lambda (&rest ignore)
-			     (when (y-or-n-p "Are you sure you want to clear the searches? ")
-			       (setq notmuch-search-history nil)
-			       (notmuch-hello-update)))
-		   "clear")
+    (widget-create
+     'push-button
+     :notify (lambda (&rest _ignore)
+	       (when (y-or-n-p "Are you sure you want to clear the searches? ")
+		 (setq notmuch-search-history nil)
+		 (notmuch-hello-update)))
+     "clear")
     (widget-insert "\n\n")
-    (let ((start (point)))
-      (cl-loop for i from 1 to notmuch-hello-recent-searches-max
-	       for search in notmuch-search-history do
-	       (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
-		 (set widget-symbol
-		      (widget-create 'editable-field
-				     ;; Don't let the search boxes be
-				     ;; less than 8 characters wide.
-				     :size (max 8
-						(- (window-width)
-						   ;; Leave some space
-						   ;; at the start and
-						   ;; end of the
-						   ;; boxes.
-						   (* 2 notmuch-hello-indent)
-						   ;; 1 for the space
-						   ;; before the
-						   ;; `[save]' button. 6
-						   ;; for the `[save]'
-						   ;; button.
-						   1 6
-						   ;; 1 for the space
-						   ;; before the `[del]'
-						   ;; button. 5 for the
-						   ;; `[del]' button.
-						   1 5))
-				     :action #'notmuch-hello-search
-				     search))
-		 (widget-insert " ")
-		 (widget-create 'push-button
-				:notify #'notmuch-hello-add-saved-search
-				:notmuch-saved-search-widget widget-symbol
-				"save")
-		 (widget-insert " ")
-		 (widget-create 'push-button
-				:notify #'notmuch-hello-delete-search-from-history
-				:notmuch-saved-search-widget widget-symbol
-				"del"))
-	       (widget-insert "\n"))
-      (indent-rigidly start (point) notmuch-hello-indent))
-    nil))
+    (let ((width (notmuch-search-item-field-width)))
+      (dolist (search (seq-take notmuch-search-history
+				notmuch-hello-recent-searches-max))
+	(widget-create 'notmuch-search-item :value search :size width)))))
 
 (defun notmuch-hello-insert-searches (title query-list &rest options)
   "Insert a section with TITLE showing a list of buttons made from QUERY-LIST.
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 04/36] emacs: notmuch-start-notmuch: remove backward compatibility code
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (2 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 03/36] emacs: define new notmuch-search-item widget type Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 05/36] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
                     ` (33 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 64 ++++++++++++--------------------------------
 1 file changed, 17 insertions(+), 47 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index e23999ad..76387779 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -896,42 +896,19 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 invoke `set-process-sentinel' directly on the returned process,
 as that will interfere with the handling of stderr and the exit
 status."
-  (let (err-file err-buffer proc err-proc
-		 ;; Find notmuch using Emacs' `exec-path'
-		 (command (or (executable-find notmuch-command)
-			      (error "Command not found: %s" notmuch-command))))
-    (if (fboundp 'make-process)
-	(progn
-	  (setq err-buffer (generate-new-buffer " *notmuch-stderr*"))
-	  ;; Emacs 25 and newer has `make-process', which allows
-	  ;; redirecting stderr independently from stdout to a
-	  ;; separate buffer. As this allows us to avoid using a
-	  ;; temporary file and shell invocation, use it when
-	  ;; available.
-	  (setq proc (make-process
-		      :name name
-		      :buffer buffer
-		      :command (cons command args)
-		      :connection-type 'pipe
-		      :stderr err-buffer))
-	  (setq err-proc (get-buffer-process err-buffer))
-	  (process-put proc 'err-buffer err-buffer)
-
-	  (process-put err-proc 'err-file err-file)
-	  (process-put err-proc 'err-buffer err-buffer)
-	  (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel))
-      ;; On Emacs versions before 25, there is no way to capture
-      ;; stdout and stderr separately for asynchronous processes, or
-      ;; even to redirect stderr to a file, so we use a trivial shell
-      ;; wrapper to send stderr to a temporary file and clean things
-      ;; up in the sentinel.
-      (setq err-file (make-temp-file "nmerr"))
-      (let ((process-connection-type nil)) ;; Use a pipe
-	(setq proc (apply #'start-process name buffer
-			  "/bin/sh" "-c"
-			  "exec 2>\"$1\"; shift; exec \"$0\" \"$@\""
-			  command err-file args)))
-      (process-put proc 'err-file err-file))
+  (let* ((command (or (executable-find notmuch-command)
+		      (error "Command not found: %s" notmuch-command)))
+	 (err-buffer (generate-new-buffer " *notmuch-stderr*"))
+	 (proc (make-process
+		:name name
+		:buffer buffer
+		:command (cons command args)
+		:connection-type 'pipe
+		:stderr err-buffer))
+	 (err-proc (get-buffer-process err-buffer)))
+    (process-put err-proc 'err-buffer err-buffer)
+    (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
+    (process-put proc 'err-buffer err-buffer)
     (process-put proc 'sub-sentinel sentinel)
     (process-put proc 'real-command (cons notmuch-command args))
     (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
@@ -939,9 +916,7 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 
 (defun notmuch-start-notmuch-sentinel (proc event)
   "Process sentinel function used by `notmuch-start-notmuch'."
-  (let* ((err-file (process-get proc 'err-file))
-	 (err-buffer (or (process-get proc 'err-buffer)
-			 (find-file-noselect err-file)))
+  (let* ((err-buffer (process-get proc 'err-buffer))
 	 (err (and (not (zerop (buffer-size err-buffer)))
 		   (with-current-buffer err-buffer (buffer-string))))
 	 (sub-sentinel (process-get proc 'sub-sentinel))
@@ -977,16 +952,11 @@ (defun notmuch-start-notmuch-sentinel (proc event)
       (error
        ;; Emacs behaves strangely if an error escapes from a sentinel,
        ;; so turn errors into messages.
-       (message "%s" (error-message-string err))))
-    (when err-file (ignore-errors (delete-file err-file)))))
+       (message "%s" (error-message-string err))))))
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
-  (let* ((err-file (process-get proc 'err-file))
-	 ;; When `make-process' is available, use the error buffer
-	 ;; associated with the process, otherwise the error file.
-	 (err-buffer (or (process-get proc 'err-buffer)
-			 (find-file-noselect err-file))))
-    (when err-buffer (kill-buffer err-buffer))))
+  (let ((buffer (process-get proc 'err-buffer)))
+    (kill-buffer buffer)))
 
 (defvar-local notmuch-show-process-crypto nil)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 05/36] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (3 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 04/36] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 06/36] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
                     ` (32 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-lib.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 76387779..21fa2582 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -956,7 +956,8 @@ (defun notmuch-start-notmuch-sentinel (proc event)
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
   (let ((buffer (process-get proc 'err-buffer)))
-    (kill-buffer buffer)))
+    (when (buffer-live-p buffer)
+      (kill-buffer buffer))))
 
 (defvar-local notmuch-show-process-crypto nil)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 06/36] emacs: notmuch-start-notmuch-sentinel: assert buffer is alive
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (4 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 05/36] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 07/36] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
                     ` (31 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-lib.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 21fa2582..06ca8cdc 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -917,7 +917,8 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 (defun notmuch-start-notmuch-sentinel (proc event)
   "Process sentinel function used by `notmuch-start-notmuch'."
   (let* ((err-buffer (process-get proc 'err-buffer))
-	 (err (and (not (zerop (buffer-size err-buffer)))
+	 (err (and (buffer-live-p err-buffer)
+		   (not (zerop (buffer-size err-buffer)))
 		   (with-current-buffer err-buffer (buffer-string))))
 	 (sub-sentinel (process-get proc 'sub-sentinel))
 	 (real-command (process-get proc 'real-command)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 07/36] emacs: notmuch-start-notmuch: avoid storing process buffer twice
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (5 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 06/36] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 08/36] emacs: avoid passing around some redundant information Jonas Bernoulli
                     ` (30 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 06ca8cdc..be15af5e 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -906,12 +906,11 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 		:connection-type 'pipe
 		:stderr err-buffer))
 	 (err-proc (get-buffer-process err-buffer)))
-    (process-put err-proc 'err-buffer err-buffer)
-    (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
     (process-put proc 'err-buffer err-buffer)
     (process-put proc 'sub-sentinel sentinel)
     (process-put proc 'real-command (cons notmuch-command args))
     (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
+    (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
     proc))
 
 (defun notmuch-start-notmuch-sentinel (proc event)
@@ -956,7 +955,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
        (message "%s" (error-message-string err))))))
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
-  (let ((buffer (process-get proc 'err-buffer)))
+  (let ((buffer (process-buffer proc)))
     (when (buffer-live-p buffer)
       (kill-buffer buffer))))
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 08/36] emacs: avoid passing around some redundant information
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (6 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 07/36] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 09/36] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
                     ` (29 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index be15af5e..e09912d3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -800,20 +800,27 @@ (defun notmuch-check-exit-status (exit-status command &optional output err)
 Emacs requested a newer output format than supported by the notmuch CLI.
 You may need to restart Emacs or upgrade your notmuch package."))
    (t
-    (let* ((command-string
-	    (mapconcat (lambda (arg)
-			 (shell-quote-argument
-			  (cond ((stringp arg) arg)
-				((symbolp arg) (symbol-name arg))
-				(t "*UNKNOWN ARGUMENT*"))))
-		       command " "))
-	   (extra
-	    (concat "command: " command-string "\n"
-		    (if (integerp exit-status)
-			(format "exit status: %s\n" exit-status)
-		      (format "exit signal: %s\n" exit-status))
-		    (and err    (concat "stderr:\n" err))
-		    (and output (concat "stdout:\n" output)))))
+    (pcase-let*
+	((`(,command . ,args) command)
+	 (command (if (equal (file-name-nondirectory command)
+			     notmuch-command)
+		      notmuch-command
+		    command))
+	 (command-string
+	  (mapconcat (lambda (arg)
+		       (shell-quote-argument
+			(cond ((stringp arg) arg)
+			      ((symbolp arg) (symbol-name arg))
+			      (t "*UNKNOWN ARGUMENT*"))))
+		     (cons command args)
+		     " "))
+	 (extra
+	  (concat "command: " command-string "\n"
+		  (if (integerp exit-status)
+		      (format "exit status: %s\n" exit-status)
+		    (format "exit signal: %s\n" exit-status))
+		  (and err    (concat "stderr:\n" err))
+		  (and output (concat "stdout:\n" output)))))
       (if err
 	  ;; We have an error message straight from the CLI.
 	  (notmuch-logged-error
@@ -821,7 +828,7 @@ (defun notmuch-check-exit-status (exit-status command &optional output err)
 	;; We only have combined output from the CLI; don't inundate
 	;; the user with it.  Mimic `process-lines'.
 	(notmuch-logged-error (format "%s exited with status %s"
-				      (car command) exit-status)
+				      command exit-status)
 			      extra))
       ;; `notmuch-logged-error' does not return.
       ))))
@@ -908,7 +915,6 @@ (defun notmuch-start-notmuch (name buffer sentinel &rest args)
 	 (err-proc (get-buffer-process err-buffer)))
     (process-put proc 'err-buffer err-buffer)
     (process-put proc 'sub-sentinel sentinel)
-    (process-put proc 'real-command (cons notmuch-command args))
     (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
     (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
     proc))
@@ -919,8 +925,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
 	 (err (and (buffer-live-p err-buffer)
 		   (not (zerop (buffer-size err-buffer)))
 		   (with-current-buffer err-buffer (buffer-string))))
-	 (sub-sentinel (process-get proc 'sub-sentinel))
-	 (real-command (process-get proc 'real-command)))
+	 (sub-sentinel (process-get proc 'sub-sentinel)))
     (condition-case err
 	(progn
 	  ;; Invoke the sub-sentinel, if any
@@ -932,7 +937,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
 	  ;; and there's no point in telling the user that (but we
 	  ;; still check for and report stderr output below).
 	  (when (buffer-live-p (process-buffer proc))
-	    (notmuch-check-async-exit-status proc event real-command err))
+	    (notmuch-check-async-exit-status proc event nil err))
 	  ;; If that didn't signal an error, then any error output was
 	  ;; really warning output.  Show warnings, if any.
 	  (let ((warnings
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 09/36] emacs: avoid killing process buffer when process is still alive
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (7 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 08/36] emacs: avoid passing around some redundant information Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 10/36] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
                     ` (28 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index e09912d3..0e235fa3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -960,9 +960,10 @@ (defun notmuch-start-notmuch-sentinel (proc event)
        (message "%s" (error-message-string err))))))
 
 (defun notmuch-start-notmuch-error-sentinel (proc event)
-  (let ((buffer (process-buffer proc)))
-    (when (buffer-live-p buffer)
-      (kill-buffer buffer))))
+  (unless (process-live-p proc)
+    (let ((buffer (process-buffer proc)))
+      (when (buffer-live-p buffer)
+	(kill-buffer buffer)))))
 
 (defvar-local notmuch-show-process-crypto nil)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 10/36] emacs: make headings outline-minor-mode compatible
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (8 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 09/36] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 11/36] emacs: use lexical-bindings in all libraries Jonas Bernoulli
                     ` (27 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

`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.
---
 emacs/coolj.el               | 12 +++----
 emacs/notmuch-address.el     | 28 +++++++++++-----
 emacs/notmuch-company.el     |  1 -
 emacs/notmuch-compat.el      |  2 --
 emacs/notmuch-crypto.el      |  8 ++++-
 emacs/notmuch-draft.el       |  9 ++++-
 emacs/notmuch-hello.el       | 47 ++++++++++++++++++--------
 emacs/notmuch-jump.el        |  2 --
 emacs/notmuch-lib.el         | 41 ++++++++++++++++++-----
 emacs/notmuch-maildir-fcc.el | 18 +++++-----
 emacs/notmuch-mua.el         | 18 +++++++---
 emacs/notmuch-print.el       |  8 +++--
 emacs/notmuch-query.el       |  8 ++---
 emacs/notmuch-show.el        | 64 ++++++++++++++++++++++++++----------
 emacs/notmuch-tag.el         | 16 ++++++++-
 emacs/notmuch-tree.el        | 25 +++++++++++---
 emacs/notmuch-wash.el        | 18 +++++-----
 emacs/notmuch.el             | 32 +++++++++++++++++-
 test/test-lib.el             |  4 ++-
 19 files changed, 263 insertions(+), 98 deletions(-)

diff --git a/emacs/coolj.el b/emacs/coolj.el
index 0385872f..b3e314f0 100644
--- a/emacs/coolj.el
+++ b/emacs/coolj.el
@@ -25,13 +25,13 @@
 
 ;;; Commentary:
 
-;;; This is a simple derivative of some functionality from
-;;; `longlines.el'. The key difference is that this version will
-;;; insert a prefix at the head of each wrapped line. The prefix is
-;;; calculated from the originating long line.
+;; This is a simple derivative of some functionality from
+;; `longlines.el'. The key difference is that this version will
+;; insert a prefix at the head of each wrapped line. The prefix is
+;; calculated from the originating long line.
 
-;;; No minor-mode is provided, the caller is expected to call
-;;; `coolj-wrap-region' to wrap the region of interest.
+;; No minor-mode is provided, the caller is expected to call
+;; `coolj-wrap-region' to wrap the region of interest.
 
 ;;; Code:
 
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 71985ed7..bf29c3a0 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -25,9 +25,11 @@ (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
 (require 'notmuch-company)
-;;
+
 (declare-function company-manual-begin "company")
 
+;;; Cache internals
+
 (defvar notmuch-address-last-harvest 0
   "Time of last address harvest.")
 
@@ -47,6 +49,8 @@ (defun notmuch-address--harvest-ready ()
   (or notmuch-address-full-harvest-finished
       (notmuch-address--load-address-hash)))
 
+;;; Options
+
 (defcustom notmuch-address-command 'internal
   "Determines how address completion candidates are generated.
 
@@ -133,6 +137,14 @@ (defcustom notmuch-address-post-completion-functions nil
   :group 'notmuch-address
   :group 'notmuch-hooks)
 
+(defcustom notmuch-address-use-company t
+  "If available, use company mode for address completion."
+  :type 'boolean
+  :group 'notmuch-send
+  :group 'notmuch-address)
+
+;;; Setup
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
       PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -147,12 +159,6 @@ (defvar notmuch-address-history nil)
 (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
-(defcustom notmuch-address-use-company t
-  "If available, use company mode for address completion."
-  :type 'boolean
-  :group 'notmuch-send
-  :group 'notmuch-address)
-
 (defun notmuch-address-setup ()
   (let* ((setup-company (and notmuch-address-use-company
 			     (require 'company nil t)))
@@ -178,6 +184,8 @@ (defun notmuch-address-toggle-internal-completion ()
 	(kill-local-variable 'company-idle-delay)
       (setq-local company-idle-delay nil))))
 
+;;; Completion
+
 (defun notmuch-address-matching (substring)
   "Returns a list of completion candidates matching SUBSTRING.
 The candidates are taken from `notmuch-address-completions'."
@@ -250,6 +258,8 @@ (defun notmuch-address-expand-name ()
 	(ding))))
    (t nil)))
 
+;;; Harvest
+
 (defun notmuch-address-harvest-addr (result)
   (let ((name-addr (plist-get result :name-addr)))
     (puthash name-addr t notmuch-address-completions)))
@@ -406,7 +416,7 @@ (defun notmuch-address-harvest-trigger ()
 	       (setq notmuch-address-full-harvest-finished t))
 	   (setq notmuch-address-last-harvest 0)))))))
 
-;;
+;;; Standalone completion
 
 (defun notmuch-address-from-minibuffer (prompt)
   (if (not notmuch-address-command)
@@ -425,7 +435,7 @@ (defun notmuch-address-from-minibuffer (prompt)
       (let ((minibuffer-local-map rmap))
 	(read-string prompt)))))
 
-;;
+;;; _
 
 (provide 'notmuch-address)
 
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index b50e73c8..4439cc15 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -102,7 +102,6 @@ (defun notmuch-company (command &optional arg &rest _ignore)
        (run-hook-with-args 'notmuch-address-post-completion-functions arg))
       (no-cache t))))
 
-
 (provide 'notmuch-company)
 
 ;;; notmuch-company.el ends here
diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el
index 2975f4c2..c4e07780 100644
--- a/emacs/notmuch-compat.el
+++ b/emacs/notmuch-compat.el
@@ -41,8 +41,6 @@ (defun notmuch-message--fold-long-headers ()
 (unless (fboundp 'message--fold-long-headers)
   (add-hook 'message-header-hook 'notmuch-message--fold-long-headers))
 
-;; End of compatibility functions
-
 (provide 'notmuch-compat)
 
 ;;; notmuch-compat.el ends here
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 9e6f3a9d..6d2d35a5 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -26,6 +26,8 @@ (require 'notmuch-lib)
 
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 
+;;; Options
+
 (defcustom notmuch-crypto-process-mime t
   "Whether to process cryptographic MIME parts.
 
@@ -55,6 +57,8 @@ (defcustom notmuch-crypto-gpg-program epg-gpg-program
   :type 'string
   :group 'notmuch-crypto)
 
+;;; Faces
+
 (defface notmuch-crypto-part-header
   '((((class color)
       (background dark))
@@ -96,6 +100,8 @@ (defface notmuch-crypto-decryption
   :group 'notmuch-crypto
   :group 'notmuch-faces)
 
+;;; Functions
+
 (define-button-type 'notmuch-crypto-status-button-type
   'action (lambda (button) (message (button-get button 'help-echo)))
   'follow-link t
@@ -259,7 +265,7 @@ (defun notmuch-crypto-insert-encstatus-button (encstatus)
    'mouse-face 'notmuch-crypto-decryption)
   (insert "\n"))
 
-;;
+;;; _
 
 (provide 'notmuch-crypto)
 
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index f928be87..9ce9e736 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -31,6 +31,8 @@ (require 'notmuch-tag)
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 (declare-function notmuch-message-mode "notmuch-mua")
 
+;;; Options
+
 (defgroup notmuch-draft nil
   "Saving and editing drafts in Notmuch."
   :group 'notmuch)
@@ -85,6 +87,8 @@ (i.e with an mml encryption tag in it)."
   :group 'notmuch-draft
   :group 'notmuch-crypto)
 
+;;; Internal
+
 (defvar notmuch-draft-encryption-tag-regex
   "<#\\(part encrypt\\|secure.*mode=.*encrypt>\\)"
   "Regular expression matching mml tags indicating encryption of part or message.")
@@ -169,6 +173,8 @@ (defun notmuch-draft--make-message-id ()
   ;; but notmuch doesn't want that form, so remove them.
   (concat "draft-" (substring (message-make-message-id) 1 -1)))
 
+;;; Commands
+
 (defun notmuch-draft-save ()
   "Save the current draft message in the notmuch database.
 
@@ -226,6 +232,7 @@ (defun notmuch-draft-postpone ()
 
 (defun notmuch-draft-resume (id)
   "Resume editing of message with id ID."
+  ;; Used by command `notmuch-show-resume-message'.
   (let* ((tags (process-lines notmuch-command "search" "--output=tags"
 			      "--exclude=false" id))
 	 (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
@@ -265,10 +272,10 @@ (defun notmuch-draft-resume (id)
       ;; message is resaved or sent.
       (setq notmuch-draft-id (and draft id)))))
 
+;;; _
 
 (add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
 
-
 (provide 'notmuch-draft)
 
 ;;; notmuch-draft.el ends here
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 7bc713f3..28ffedd9 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -37,6 +37,8 @@ (declare-function notmuch-unthreaded
 		  (&optional query query-context target buffer-name open-target))
 
 
+;;; Options
+
 (defun notmuch-saved-search-get (saved-search field)
   "Get FIELD from SAVED-SEARCH.
 
@@ -192,6 +194,8 @@ (defcustom notmuch-saved-search-sort-function nil
 (defvar notmuch-hello-indent 4
   "How much to indent non-headers.")
 
+(defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))
+
 (defcustom notmuch-show-logo t
   "Should the notmuch logo be shown?"
   :type 'boolean
@@ -367,23 +371,15 @@ (defcustom notmuch-hello-auto-refresh t
   :group 'notmuch-hello
   :type 'boolean)
 
+;;; Internal variables
+
 (defvar notmuch-hello-hidden-sections nil
   "List of sections titles whose contents are hidden.")
 
 (defvar notmuch-hello-first-run t
   "True if `notmuch-hello' is run for the first time, set to nil afterwards.")
 
-(defun notmuch-hello-nice-number (n)
-  (let (result)
-    (while (> n 0)
-      (push (% n 1000) result)
-      (setq n (/ n 1000)))
-    (setq result (or result '(0)))
-    (apply #'concat
-	   (number-to-string (car result))
-	   (mapcar (lambda (elem)
-		     (format "%s%03d" notmuch-hello-thousands-separator elem))
-		   (cdr result)))))
+;;; Widgets for inserters
 
 (define-widget 'notmuch-search-item 'item
   "A recent search."
@@ -419,6 +415,8 @@ (defun notmuch-search-item-field-width ()
 	  1    ; for the space before the [del] button
 	  5))) ; for the [del] button
 
+;;; Widget actions
+
 (defun notmuch-hello-search (widget &rest _event)
   (let ((search (widget-value widget)))
     (when search
@@ -451,6 +449,13 @@ (defun notmuch-hello-delete-search-from-history (widget &rest _event)
 	    (delete search notmuch-search-history)))
     (notmuch-hello-update)))
 
+;;; Button utilities
+
+;; `notmuch-hello-query-counts', `notmuch-hello-nice-number' and
+;; `notmuch-hello-insert-buttons' are used outside this section.
+;; All other functions that are defined in this section are only
+;; used by these two functions.
+
 (defun notmuch-hello-longest-label (searches-alist)
   (or (cl-loop for elem in searches-alist
 	       maximize (length (notmuch-saved-search-get elem :name)))
@@ -585,6 +590,18 @@ (defun notmuch-hello-query-counts (query-list &rest options)
 	   (list (plist-put elem-plist :count message-count)))))
      query-list)))
 
+(defun notmuch-hello-nice-number (n)
+  (let (result)
+    (while (> n 0)
+      (push (% n 1000) result)
+      (setq n (/ n 1000)))
+    (setq result (or result '(0)))
+    (apply #'concat
+	   (number-to-string (car result))
+	   (mapcar (lambda (elem)
+		     (format "%s%03d" notmuch-hello-thousands-separator elem))
+		   (cdr result)))))
+
 (defun notmuch-hello-insert-buttons (searches)
   "Insert buttons for SEARCHES.
 
@@ -639,7 +656,7 @@ (defun notmuch-hello-insert-buttons (searches)
     (unless (eq (% count tags-per-line) 0)
       (widget-insert "\n"))))
 
-(defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))
+;;; Mode
 
 (defun notmuch-hello-update ()
   "Update the notmuch-hello buffer."
@@ -723,6 +740,8 @@ (define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
   ;;(setq buffer-read-only t)
   )
 
+;;; Inserters
+
 (defun notmuch-hello-generate-tag-alist (&optional hide-tags)
   "Return an alist from tags to queries to display in the all-tags section."
   (cl-mapcan (lambda (tag)
@@ -922,6 +941,8 @@ (defun notmuch-hello-insert-footer ()
     (let ((fill-column (- (window-width) notmuch-hello-indent)))
       (center-region start (point)))))
 
+;;; Hello!
+
 ;;;###autoload
 (defun notmuch-hello (&optional no-display)
   "Run notmuch and display saved searches, known tags, etc."
@@ -973,7 +994,7 @@ (defun notmuch-hello (&optional no-display)
   (run-hooks 'notmuch-hello-refresh-hook)
   (setq notmuch-hello-first-run nil))
 
-;;
+;;; _
 
 (provide 'notmuch-hello)
 
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index ff622055..7a27b6b3 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -198,8 +198,6 @@ (defun notmuch-jump--make-keymap (action-map prompt)
 		 (exit-minibuffer)))))))
     map))
 
-;;
-
 (provide 'notmuch-jump)
 
 ;;; notmuch-jump.el ends here
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0e235fa3..0b698d59 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -33,6 +33,8 @@ (unless (require 'notmuch-version nil t)
   (defconst notmuch-emacs-version "unknown"
     "Placeholder variable when notmuch-version.el[c] is not available."))
 
+;;; Groups
+
 (defgroup notmuch nil
   "Notmuch mail reader for Emacs."
   :group 'mail)
@@ -78,6 +80,8 @@ (defgroup notmuch-faces nil
   "Graphical attributes for displaying text"
   :group 'notmuch)
 
+;;; Options
+
 (defcustom notmuch-command "notmuch"
   "Name of the notmuch binary.
 
@@ -125,11 +129,6 @@ (defcustom notmuch-poll-script nil
 		 (string :tag "Custom script"))
   :group 'notmuch-external)
 
-;;
-
-(defvar notmuch-search-history nil
-  "Variable to store notmuch searches history.")
-
 (defcustom notmuch-archive-tags '("-inbox")
   "List of tag changes to apply to a message or a thread when it is archived.
 
@@ -144,6 +143,11 @@ (defcustom notmuch-archive-tags '("-inbox")
   :group 'notmuch-search
   :group 'notmuch-show)
 
+;;; Variables
+
+(defvar notmuch-search-history nil
+  "Variable to store notmuch searches history.")
+
 (defvar notmuch-common-keymap
   (let ((map (make-sparse-keymap)))
     (define-key map "?" 'notmuch-help)
@@ -177,6 +181,8 @@ (define-button-type 'notmuch-button-type
 		  (select-window (posn-window (event-start last-input-event)))
 		  (button-activate button)))
 
+;;; CLI Utilities
+
 (defun notmuch-command-to-string (&rest args)
   "Synchronously invoke \"notmuch\" with the given list of arguments.
 
@@ -234,6 +240,8 @@ (defun notmuch-version ()
 	       (concat cli-version
 		       " (emacs mua version " notmuch-emacs-version ")")))))
 
+;;; Notmuch Configuration
+
 (defun notmuch-config-get (item)
   "Return a value from the notmuch configuration."
   (let* ((val (notmuch-command-to-string "config" "get" item))
@@ -263,6 +271,8 @@ (defun notmuch-user-other-email ()
 (defun notmuch-user-emails ()
   (cons (notmuch-user-primary-email) (notmuch-user-other-email)))
 
+;;; Commands
+
 (defun notmuch-poll ()
   "Run \"notmuch new\" or an external script to import mail.
 
@@ -287,6 +297,8 @@ (defun notmuch-bury-or-kill-this-buffer ()
       (bury-buffer)
     (kill-buffer)))
 
+;;; Describe Key Bindings
+
 (defun notmuch-prefix-key-description (key)
   "Given a prefix key code, return a human-readable string representation.
 
@@ -297,7 +309,6 @@ (defun notmuch-prefix-key-description (key)
 	"M-"
       (concat desc " "))))
 
-
 (defun notmuch-describe-key (actual-key binding prefix ua-keys tail)
   "Prepend cons cells describing prefix-arg ACTUAL-KEY and ACTUAL-KEY to TAIL.
 
@@ -435,6 +446,8 @@ (defun notmuch-subkeymap-help ()
 	  (insert desc)))
       (pop-to-buffer (help-buffer)))))
 
+;;; Refreshing Buffers
+
 (defvar-local notmuch-buffer-refresh-function nil
   "Function to call to refresh the current buffer.")
 
@@ -466,6 +479,8 @@ (defun notmuch-refresh-all-buffers ()
 	(with-current-buffer buffer
 	  (notmuch-refresh-this-buffer))))))
 
+;;; String Utilities
+
 (defun notmuch-prettify-subject (subject)
   ;; This function is used by `notmuch-search-process-filter' which
   ;; requires that we not disrupt its' matching state.
@@ -509,8 +524,6 @@ (defun notmuch-hex-encode (str)
   (replace-regexp-in-string
    "[ %\"]" (lambda (match) (format "%%%02x" (aref match 0))) str))
 
-;;
-
 (defun notmuch-common-do-stash (text)
   "Common function to stash text in kill ring, and display in minibuffer."
   (if text
@@ -522,7 +535,7 @@ (defun notmuch-common-do-stash (text)
     (kill-new "")
     (message "Nothing to stash!")))
 
-;;
+;;; Generic Utilities
 
 (defun notmuch-plist-delete (plist property)
   (let* ((xplist (cons nil plist))
@@ -533,6 +546,8 @@ (defun notmuch-plist-delete (plist property)
       (setq pred (cddr pred)))
     (cdr xplist)))
 
+;;; MML Utilities
+
 (defun notmuch-match-content-type (t1 t2)
   "Return t if t1 and t2 are matching content types, taking wildcards into account."
   (let ((st1 (split-string t1 "/"))
@@ -673,6 +688,8 @@ (defun notmuch-mm-display-part-inline (msg part content-type process-crypto)
 	    (mm-display-part handle)
 	    t))))))
 
+;;; Generic Utilities
+
 ;; Converts a plist of headers to an alist of headers. The input plist should
 ;; have symbols of the form :Header as keys, and the resulting alist will have
 ;; symbols of the form 'Header as keys.
@@ -739,6 +756,8 @@ (defun notmuch-map-text-property (start end prop func &optional object)
       (put-text-property start next prop (funcall func value) object)
       (setq start next))))
 
+;;; Running Notmuch
+
 (defun notmuch-logged-error (msg &optional extra)
   "Log MSG and EXTRA to *Notmuch errors* and signal MSG.
 
@@ -967,6 +986,8 @@ (defun notmuch-start-notmuch-error-sentinel (proc event)
 
 (defvar-local notmuch-show-process-crypto nil)
 
+;;; Generic Utilities
+
 (defun notmuch-interactive-region ()
   "Return the bounds of the current interactive region.
 
@@ -981,6 +1002,8 @@ (define-obsolete-function-alias
   'notmuch-interactive-region
   "notmuch 0.29")
 
+;;; _
+
 (provide 'notmuch-lib)
 
 ;;; notmuch-lib.el ends here
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 32b8100e..5de03cc2 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -29,6 +29,8 @@ (require 'notmuch-lib)
 
 (defvar notmuch-maildir-fcc-count 0)
 
+;;; Options
+
 (defcustom notmuch-fcc-dirs "sent"
   "Determines the Fcc Header which says where to save outgoing mail.
 
@@ -83,8 +85,7 @@ (defcustom notmuch-maildir-use-notmuch-insert t
 		 (const :tag "Use simple fcc" nil))
   :group 'notmuch-send)
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions which set up the fcc header in the message buffer.
+;;; Functions which set up the fcc header in the message buffer.
 
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
@@ -142,9 +143,7 @@ (defun notmuch-maildir-add-file-style-fcc-header (subdir)
 		subdir
 	      (concat (notmuch-database-path) "/" subdir))))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions for saving a message either using notmuch insert or file
-;; fcc. First functions common to the two cases.
+;;; Functions for saving a message using either method.
 
 (defmacro with-temporary-notmuch-message-buffer (&rest body)
   "Set-up a temporary copy of the current message-mode buffer."
@@ -204,8 +203,7 @@ (defun notmuch-fcc-handler (fcc-header)
       (notmuch-maildir-fcc-with-notmuch-insert fcc-header)
     (notmuch-maildir-fcc-file-fcc fcc-header)))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions for saving a message using notmuch insert.
+;;; Functions for saving a message using notmuch insert.
 
 (defun notmuch-maildir-notmuch-insert-current-buffer (folder &optional create tags)
   "Use notmuch insert to put the current buffer in the database.
@@ -251,9 +249,7 @@ (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
 	   (?e (notmuch-maildir-fcc-with-notmuch-insert
 		(read-from-minibuffer "Fcc header: " fcc-header)))))))))
 
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions for saving a message using file fcc.
+;;; Functions for saving a message using file fcc.
 
 (defun notmuch-maildir-fcc-host-fixer (hostname)
   (replace-regexp-in-string "/\\|:"
@@ -362,6 +358,8 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
 	  (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
+;;; _
+
 (provide 'notmuch-maildir-fcc)
 
 ;;; notmuch-maildir-fcc.el ends here
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index c38cb5aa..6fe5f6d0 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -38,7 +38,7 @@ (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
 (declare-function notmuch-draft-postpone "notmuch-draft" ())
 (declare-function notmuch-draft-save "notmuch-draft" ())
 
-;;
+;;; Options
 
 (defcustom notmuch-mua-send-hook nil
   "Hook run before sending messages."
@@ -120,7 +120,7 @@ (defcustom notmuch-mua-attachment-regexp
   :type 'regexp
   :group 'notmuch-send)
 
-;;
+;;; Various functions
 
 (defun notmuch-mua-attachment-check ()
   "Signal an error if the message text indicates that an
@@ -215,6 +215,8 @@ (defun notmuch-mua-insert-references (original-func header references)
   (funcall original-func header references)
   (unless (bolp) (insert "\n")))
 
+;;; Mua reply
+
 (defun notmuch-mua-reply (query-string &optional sender reply-all)
   (let ((args '("reply" "--format=sexp" "--format-version=4"))
 	(process-crypto notmuch-show-process-crypto)
@@ -318,6 +320,8 @@ (defun notmuch-mua-reply (query-string &optional sender reply-all)
   (message-goto-body)
   (set-buffer-modified-p nil))
 
+;;; Mode and keymap
+
 (defvar notmuch-message-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
@@ -333,6 +337,8 @@ (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
 
 (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
 
+;;; New messages
+
 (defun notmuch-mua-pop-to-buffer (name switch-function)
   "Pop to buffer NAME, and warn if it already exists and is modified.
 Like `message-pop-to-buffer' but enable `notmuch-message-mode'
@@ -528,6 +534,8 @@ (defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all
     (notmuch-mua-reply query-string sender reply-all)
     (deactivate-mark)))
 
+;;; Checks
+
 (defun notmuch-mua-check-no-misplaced-secure-tag ()
   "Query user if there is a misplaced secure mml tag.
 
@@ -570,6 +578,8 @@ (defun notmuch-mua-check-secure-tag-has-newline ()
 newline. It is likely that the message will be sent unsigned and
 unencrypted.  Really send? "))))
 
+;;; Finishing commands
+
 (defun notmuch-mua-send-common (arg &optional exit)
   (interactive "P")
   (run-hooks 'notmuch-mua-send-hook)
@@ -593,7 +603,7 @@ (defun notmuch-mua-kill-buffer ()
   (interactive)
   (message-kill-buffer))
 
-;;
+;;; _
 
 (define-mail-user-agent 'notmuch-user-agent
   'notmuch-mua-mail 'notmuch-mua-send-and-exit
@@ -603,8 +613,6 @@ (define-mail-user-agent 'notmuch-user-agent
 ;; composing a message.
 (notmuch-mua-add-more-hidden-headers)
 
-;;
-
 (provide 'notmuch-mua)
 
 ;;; notmuch-mua.el ends here
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 6dd9f775..d7b2fcce 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -25,6 +25,8 @@ (require 'notmuch-lib)
 
 (declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
 
+;;; Options
+
 (defcustom notmuch-print-mechanism 'notmuch-print-lpr
   "How should printing be done?"
   :group 'notmuch-show
@@ -36,7 +38,7 @@ (defcustom notmuch-print-mechanism 'notmuch-print-lpr
 	  (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
 	  (function :tag "Using a custom function")))
 
-;; Utility functions:
+;;; Utility functions
 
 (defun notmuch-print-run-evince (file)
   "View FILE using 'evince'."
@@ -54,7 +56,7 @@ (defun notmuch-print-run-muttprint (&optional output)
 	 "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
 	 output))
 
-;; User-visible functions:
+;;; User-visible functions
 
 (defun notmuch-print-lpr (msg)
   "Print a message buffer using lpr."
@@ -91,6 +93,8 @@ (defun notmuch-print-message (msg)
   (set-buffer-modified-p nil)
   (funcall notmuch-print-mechanism msg))
 
+;;; _
+
 (provide 'notmuch-print)
 
 ;;; notmuch-print.el ends here
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 3cfccbc3..72ddd2ce 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -23,6 +23,8 @@
 
 (require 'notmuch-lib)
 
+;;; Basic query function
+
 (defun notmuch-query-get-threads (search-terms)
   "Return a list of threads of messages matching SEARCH-TERMS.
 
@@ -35,8 +37,7 @@ (defun notmuch-query-get-threads (search-terms)
     (setq args (append args search-terms))
     (apply #'notmuch-call-notmuch-sexp args)))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Mapping functions across collections of messages.
+;;; Mapping functions across collections of messages
 
 (defun notmuch-query-map-aux  (mapper function seq)
   "Private function to do the actual mapping and flattening."
@@ -64,8 +65,7 @@ (defun notmuch-query-map-tree (fn tree)
 `notmuch-query-get-threads' for more information."
   (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Predefined queries
+;;; Predefined queries
 
 (defun notmuch-query-get-message-ids (&rest search-terms)
   "Return a list of message-ids of messages that match SEARCH-TERMS."
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 056c4e30..7dfbb327 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -59,6 +59,8 @@ (declare-function notmuch-unthreaded
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-draft-resume "notmuch-draft" (id))
 
+;;; Options
+
 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
   "Headers that should be shown in a message, in this order.
 
@@ -162,6 +164,8 @@ (defcustom notmuch-show-text/html-blocked-images "."
   :type '(choice (const nil) regexp)
   :group 'notmuch-show)
 
+;;; Variables
+
 (defvar-local notmuch-show-thread-id nil)
 
 (defvar-local notmuch-show-parent-buffer nil)
@@ -182,6 +186,8 @@ (defvar notmuch-show-attachment-debug nil
 each attachment handler is logged in buffers with names beginning
 \" *notmuch-part*\".")
 
+;;; Options
+
 (defcustom notmuch-show-stash-mlarchive-link-alist
   '(("Gmane" . "https://mid.gmane.org/")
     ("MARC" . "https://marc.info/?i=")
@@ -260,6 +266,8 @@ (defcustom notmuch-show-imenu-indent nil
   :type 'boolean
   :group 'notmuch-show)
 
+;;; Utilities
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message."
   `(save-excursion
@@ -275,6 +283,8 @@ (defun notmuch-show-turn-on-visual-line-mode ()
   "Enable Visual Line mode."
   (visual-line-mode t))
 
+;;; Commands
+
 ;; DEPRECATED in Notmuch 0.16 since we now have convenient part
 ;; commands.  We'll keep the command around for a version or two in
 ;; case people want to bind it themselves.
@@ -355,6 +365,8 @@ (defun notmuch-show-print-message ()
   (interactive)
   (notmuch-show-with-message-as-text 'notmuch-print-message))
 
+;;; Headers
+
 (defun notmuch-show-fontify-header ()
   (let ((face (cond
 	       ((looking-at "[Tt]o:")
@@ -493,6 +505,8 @@ (defun notmuch-show-insert-headers (headers)
 	(narrow-to-region start (point-max))
 	(run-hooks 'notmuch-show-markup-headers-hook)))))
 
+;;; Parts
+
 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
   'follow-link t
@@ -548,7 +562,7 @@ (defun notmuch-show-toggle-part-invisibility (&optional button)
 	      (overlay-put overlay 'invisible (not show))
 	      t)))))))
 
-;; Part content ID handling
+;;; Part content ID handling
 
 (defvar notmuch-show--cids nil
   "Alist from raw content ID to (MSG PART).")
@@ -811,7 +825,8 @@ (defun notmuch-show-insert-part-text/html (msg part content-type nth depth butto
 	  (gnus-blocked-images notmuch-show-text/html-blocked-images))
       (notmuch-show-insert-part-*/* msg part content-type nth depth button))))
 
-;; These functions are used by notmuch-show--insert-part-text/html-shr
+;;; Functions used by notmuch-show--insert-part-text/html-shr
+
 (declare-function libxml-parse-html-region "xml.c")
 (declare-function shr-insert-document "shr")
 
@@ -836,7 +851,7 @@ (defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)
   (notmuch-mm-display-part-inline msg part content-type notmuch-show-process-crypto)
   t)
 
-;; Functions for determining how to handle MIME parts.
+;;; Functions for determining how to handle MIME parts.
 
 (defun notmuch-show-handlers-for (content-type)
   "Return a list of content handlers for a part of type CONTENT-TYPE."
@@ -852,7 +867,7 @@ (defun notmuch-show-handlers-for (content-type)
 		(intern (concat "notmuch-show-insert-part-" content-type))))
     result))
 
-;; \f
+;;; Parts
 
 (defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button)
   ;; Run the handlers until one of them succeeds.
@@ -1098,6 +1113,8 @@ (defun notmuch-show-insert-msg (msg depth)
     (notmuch-show-message-visible msg (and (plist-get msg :match)
 					   (not (plist-get msg :excluded))))))
 
+;;; Toggle commands
+
 (defun notmuch-show-toggle-process-crypto ()
   "Toggle the processing of cryptographic MIME parts."
   (interactive)
@@ -1126,6 +1143,8 @@ (defun notmuch-show-toggle-thread-indentation ()
 	     "Content is not indented."))
   (notmuch-show-refresh-view))
 
+;;; Main insert functions
+
 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -1143,6 +1162,8 @@ (defun notmuch-show-insert-forest (forest)
   "Insert the forest of threads FOREST."
   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
 
+;;; Link buttons
+
 (defvar notmuch-id-regexp
   (concat
    ;; Match the id: prefix only if it begins a word (to disallow, for
@@ -1203,6 +1224,8 @@ (defun notmuch-show-buttonise-links (start end)
 			  'help-echo "Mouse-1, RET: search for this message"
 			  'face goto-address-mail-face)))))
 
+;;; Show command
+
 ;;;###autoload
 (defun notmuch-show (thread-id &optional elide-toggle parent-buffer query-context buffer-name)
   "Run \"notmuch show\" with the given thread ID and display results.
@@ -1325,6 +1348,8 @@ (defun notmuch-show--build-buffer (&optional state)
     ;; Report back to the caller whether any messages matched.
     forest))
 
+;;; Refresh command
+
 (defun notmuch-show-capture-state ()
   "Capture the state of the current buffer.
 
@@ -1399,6 +1424,8 @@ (defun notmuch-show-refresh-view (&optional reset-state)
       (ding)
       (message "Refreshing the buffer resulted in no messages!"))))
 
+;;; Keymaps
+
 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
     (define-key map "c" 'notmuch-show-stash-cc)
@@ -1479,6 +1506,8 @@ (defvar notmuch-show-mode-map
     map)
   "Keymap for \"notmuch show\" buffers.")
 
+;;; Mode
+
 (define-derived-mode notmuch-show-mode fundamental-mode "notmuch-show"
   "Major mode for viewing a thread with notmuch.
 
@@ -1515,6 +1544,8 @@ (define-derived-mode notmuch-show-mode fundamental-mode "notmuch-show"
   (setq imenu-extract-index-name-function
 	#'notmuch-show-imenu-extract-index-name-function))
 
+;;; Tree commands
+
 (defun notmuch-tree-from-show-current-query ()
   "Call notmuch tree with the current query."
   (interactive)
@@ -1529,17 +1560,14 @@ (defun notmuch-unthreaded-from-show-current-query ()
 		      notmuch-show-query-context
 		      (notmuch-show-get-message-id)))
 
+;;; Movement related functions.
+
 (defun notmuch-show-move-to-message-top ()
   (goto-char (notmuch-show-message-top)))
 
 (defun notmuch-show-move-to-message-bottom ()
   (goto-char (notmuch-show-message-bottom)))
 
-(defun notmuch-show-message-adjust ()
-  (recenter 0))
-
-;; Movement related functions.
-
 ;; There's some strangeness here where a text property applied to a
 ;; region a->b is not found when point is at b. We walk backwards
 ;; until finding the property.
@@ -1583,8 +1611,7 @@ (defun notmuch-show-mapc (function)
     (cl-loop do (funcall function)
 	     while (notmuch-show-goto-message-next))))
 
-;; Functions relating to the visibility of messages and their
-;; components.
+;;; Functions relating to the visibility of messages and their components.
 
 (defun notmuch-show-message-visible (props visible-p)
   (overlay-put (plist-get props :message-overlay) 'invisible (not visible-p))
@@ -1594,8 +1621,7 @@ (defun notmuch-show-headers-visible (props visible-p)
   (overlay-put (plist-get props :headers-overlay) 'invisible (not visible-p))
   (notmuch-show-set-prop :headers-visible visible-p props))
 
-;; Functions for setting and getting attributes of the current
-;; message.
+;;; Functions for setting and getting attributes of the current message.
 
 (defun notmuch-show-set-message-properties (props)
   (save-excursion
@@ -1768,8 +1794,7 @@ (defun notmuch-show-filter-thread (query)
     (notmuch-show-refresh-view t)
     (notmuch-show-goto-message msg-id)))
 
-;; Functions for getting attributes of several messages in the current
-;; thread.
+;;; Functions for getting attributes of several messages in the current thread.
 
 (defun notmuch-show-get-message-ids-for-open-messages ()
   "Return a list of all id: queries for open messages in the current thread."
@@ -1783,7 +1808,7 @@ (defun notmuch-show-get-message-ids-for-open-messages ()
 	(setq done (not (notmuch-show-goto-message-next))))
       message-ids)))
 
-;; Commands typically bound to keys.
+;;; Commands typically bound to keys.
 
 (defun notmuch-show-advance ()
   "Advance through thread.
@@ -1911,6 +1936,9 @@ (defun notmuch-show-resend-message (addresses)
     (message-resend addresses)
     (notmuch-bury-or-kill-this-buffer)))
 
+(defun notmuch-show-message-adjust ()
+  (recenter 0))
+
 (defun notmuch-show-next-message (&optional pop-at-end)
   "Show the next message.
 
@@ -2381,7 +2409,7 @@ (defun notmuch-show-stash-git-send-email (&optional no-in-reply-to)
 			  (list (notmuch-show-get-message-id t)) "--in-reply-to="))))
 	      " ")))
 
-;; Interactive part functions and their helpers
+;;; Interactive part functions and their helpers
 
 (defun notmuch-show-generate-part-buffer (msg part)
   "Return a temporary buffer containing the specified part's content."
@@ -2528,6 +2556,8 @@ (defun notmuch-show-browse-urls (&optional kill)
 	(funcall fn (completing-read prompt urls nil nil nil nil (car urls)))
       (message "No URLs found."))))
 
+;;; _
+
 (provide 'notmuch-show)
 
 ;;; notmuch-show.el ends here
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 925de78c..817ea99f 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -37,6 +37,8 @@ (declare-function notmuch-show-tag "notmuch-show" (tag-changes))
 (declare-function notmuch-tree-tag "notmuch-tree" (tag-changes))
 (declare-function notmuch-jump "notmuch-jump" (action-map prompt))
 
+;;; Keys
+
 (define-widget 'notmuch-tag-key-type 'list
   "A single key tagging binding."
   :format "%v"
@@ -84,6 +86,8 @@ (defcustom notmuch-tagging-keys
   :type '(repeat notmuch-tag-key-type)
   :group 'notmuch-tag)
 
+;;; Faces and Formats
+
 (define-widget 'notmuch-tag-format-type 'lazy
   "Customize widget for notmuch-tag-format and friends."
   :type '(alist :key-type (regexp :tag "Tag")
@@ -217,6 +221,8 @@ (defcustom notmuch-tag-added-formats
   :group 'notmuch-faces
   :type 'notmuch-tag-format-type)
 
+;;; Icons
+
 (defun notmuch-tag-format-image-data (tag data)
   "Replace TAG with image DATA, if available.
 
@@ -270,6 +276,8 @@ (defun notmuch-tag-tag-icon ()
   </g>
 </svg>")
 
+;;; Format Handling
+
 (defvar notmuch-tag--format-cache (make-hash-table :test 'equal)
   "Cache of tag format lookup.  Internal to `notmuch-tag-format-tag'.")
 
@@ -347,6 +355,8 @@ (defun notmuch-tag-format-tags (tags orig-tags &optional face)
      face
      t)))
 
+;;; Hooks
+
 (defcustom notmuch-before-tag-hook nil
   "Hooks that are run before tags of a message are modified.
 
@@ -369,6 +379,8 @@ (defcustom notmuch-after-tag-hook nil
   :options '(notmuch-hl-line-mode)
   :group 'notmuch-hooks)
 
+;;; User Input
+
 (defvar notmuch-select-tag-history nil
   "Variable to store minibuffer history for
 `notmuch-select-tag-with-completion' function.")
@@ -429,6 +441,8 @@ (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
 		nil nil initial-input
 		'notmuch-read-tag-changes-history))))
 
+;;; Tagging
+
 (defun notmuch-update-tags (tags tag-changes)
   "Return a copy of TAGS with additions and removals from TAG-CHANGES.
 
@@ -547,7 +561,7 @@ (defun notmuch-tag-jump (reverse)
     (setq action-map (nreverse action-map))
     (notmuch-jump action-map "Tag: ")))
 
-;;
+;;; _
 
 (provide 'notmuch-tag)
 
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 17863f6a..713b00da 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -54,6 +54,8 @@ (defvar notmuch-search-query-string)
 (defvar-local notmuch-tree-unthreaded nil
   "A buffer local copy of argument unthreaded to the function notmuch-tree.")
 
+;;; Options
+
 (defgroup notmuch-tree nil
   "Showing message and thread structure."
   :group 'notmuch)
@@ -118,7 +120,9 @@ (defun notmuch-tree-result-format ()
       notmuch-unthreaded-result-format
     notmuch-tree-result-format))
 
-;; Faces for messages that match the query.
+;;; Faces
+;;;; Faces for messages that match the query
+
 (defface notmuch-tree-match-face
   '((t :inherit default))
   "Default face used in tree mode face for matching messages"
@@ -169,7 +173,8 @@ (defface notmuch-tree-match-tag-face
   :group 'notmuch-tree
   :group 'notmuch-faces)
 
-;; Faces for messages that do not match the query.
+;;;; Faces for messages that do not match the query
+
 (defface notmuch-tree-no-match-face
   '((t (:foreground "gray")))
   "Default face used in tree mode face for non-matching messages."
@@ -206,6 +211,8 @@ (defface notmuch-tree-no-match-tag-face
   :group 'notmuch-tree
   :group 'notmuch-faces)
 
+;;; Variables
+
 (defvar-local notmuch-tree-previous-subject
   "The subject of the most recent result shown during the async display.")
 
@@ -238,6 +245,8 @@ (defvar-local notmuch-tree-message-buffer nil
 if the user has loaded a different buffer in that window.")
 (put 'notmuch-tree-message-buffer 'permanent-local t)
 
+;;; Tree wrapper commands
+
 (defmacro notmuch-tree--define-do-in-message-window (name cmd)
   "Define NAME as a command that calls CMD interactively in the message window.
 If the message pane is closed then this command does nothing.
@@ -305,6 +314,8 @@ (notmuch-tree--define-close-message-window-and
  notmuch-tree-view-raw-message
  notmuch-show-view-raw-message)
 
+;;; Keymap
+
 (defvar notmuch-tree-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
@@ -363,6 +374,8 @@ (defvar notmuch-tree-mode-map
     map)
   "Keymap for \"notmuch tree\" buffers.")
 
+;;; Message properties
+
 (defun notmuch-tree-get-message-properties ()
   "Return the properties of the current message as a plist.
 
@@ -414,6 +427,8 @@ (defun notmuch-tree-get-match ()
   (interactive)
   (notmuch-tree-get-prop :match))
 
+;;; Update display
+
 (defun notmuch-tree-refresh-result ()
   "Redisplay the current message line.
 
@@ -456,6 +471,8 @@ (defun notmuch-tree-tag-update-display (&optional tag-changes)
 	  (when (string= tree-msg-id (notmuch-show-get-message-id))
 	    (notmuch-show-update-tags new-tags)))))))
 
+;;; Commands (and some helper functions used by them)
+
 (defun notmuch-tree-tag (tag-changes)
   "Change tags for the current message."
   (interactive
@@ -835,7 +852,7 @@ (defun notmuch-tree-archive-thread (&optional unarchive)
     (notmuch-tree-tag-thread
      (notmuch-tag-change-list notmuch-archive-tags unarchive))))
 
-;; Functions below here display the tree buffer itself.
+;;; Functions for displaying the tree buffer itself
 
 (defun notmuch-tree-clean-address (address)
   "Try to clean a single email ADDRESS for display. Return
@@ -1142,7 +1159,7 @@ (defun notmuch-unthreaded (&optional query query-context target buffer-name open
   (interactive)
   (notmuch-tree query query-context target buffer-name open-target t))
 
-;;
+;;; _
 
 (provide 'notmuch-tree)
 
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index ce4b9637..f371cc4c 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -30,7 +30,7 @@ (declare-function notmuch-show-insert-bodypart "notmuch-show"
 		  (msg part depth &optional hide))
 (defvar notmuch-show-indent-messages-width)
 
-;;
+;;; Options
 
 (defgroup notmuch-wash nil
   "Cleaning up messages for display."
@@ -130,6 +130,8 @@ (defcustom notmuch-wash-wrap-lines-length nil
 		 (integer :tag "number of characters"))
   :group 'notmuch-wash)
 
+;;; Faces
+
 (defface notmuch-wash-toggle-button
   '((t (:inherit font-lock-comment-face)))
   "Face used for buttons toggling the visibility of washed away
@@ -143,6 +145,8 @@ (defface notmuch-wash-cited-text
   :group 'notmuch-wash
   :group 'notmuch-faces)
 
+;;; Buttons
+
 (defun notmuch-wash-toggle-invisible-action (cite-button)
   ;; Toggle overlay visibility
   (let ((overlay (button-get cite-button 'overlay)))
@@ -225,6 +229,8 @@ (defun notmuch-wash-region-to-button (msg beg end type &optional prefix)
 				   :type button-type)))
 	  (overlay-put overlay 'notmuch-wash-button button))))))
 
+;;; Hook functions
+
 (defun notmuch-wash-excerpt-citations (msg depth)
   "Excerpt citations and up to one signature."
   (goto-char (point-min))
@@ -270,8 +276,6 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	   msg sig-start-marker sig-end-marker
 	   "signature"))))))
 
-;;
-
 (defun notmuch-wash-elide-blank-lines (msg depth)
   "Elide leading, trailing and successive blank lines."
   ;; Algorithm derived from `article-strip-multiple-blank-lines' in
@@ -293,8 +297,6 @@ (defun notmuch-wash-elide-blank-lines (msg depth)
   (when (looking-at "\n")
     (delete-region (match-beginning 0) (match-end 0))))
 
-;;
-
 (defun notmuch-wash-tidy-citations (msg depth)
   "Improve the display of cited regions of a message.
 
@@ -319,8 +321,6 @@ (defun notmuch-wash-tidy-citations (msg depth)
   (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
     (replace-match "\\2")))
 
-;;
-
 (defun notmuch-wash-wrap-long-lines (msg depth)
   "Wrap long lines in the message.
 
@@ -342,7 +342,7 @@ (defun notmuch-wash-wrap-long-lines (msg depth)
 			 2)))
     (coolj-wrap-region (point-min) (point-max))))
 
-;;
+;;;; Convert Inline Patches
 
 (require 'diff-mode)
 
@@ -417,7 +417,7 @@ (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
 	(delete-region (point-min) (point-max))
 	(notmuch-show-insert-bodypart nil part depth)))))
 
-;;
+;;; _
 
 (provide 'notmuch-wash)
 
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index bba4ca03..6a09dd38 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -80,6 +80,8 @@ (require 'notmuch-maildir-fcc)
 (require 'notmuch-message)
 (require 'notmuch-parser)
 
+;;; Options
+
 (defcustom notmuch-search-result-format
   `(("date" . "%12s ")
     ("count" . "%-7s ")
@@ -115,6 +117,8 @@ (defcustom notmuch-init-file (locate-user-emacs-file "notmuch-config")
 (defvar notmuch-query-history nil
   "Variable to store minibuffer history for notmuch queries.")
 
+;;; Mime Utilities
+
 (defun notmuch-foreach-mime-part (function mm-handle)
   (cond ((stringp (car mm-handle))
 	 (dolist (part (cdr mm-handle))
@@ -151,6 +155,8 @@ (defun notmuch-save-attachments (mm-handle &optional queryp)
 	    (mm-save-part p))))
    mm-handle))
 
+;;; Integrations
+
 (require 'hl-line)
 
 (defun notmuch-hl-line-mode ()
@@ -158,6 +164,8 @@ (defun notmuch-hl-line-mode ()
     (when hl-line-overlay
       (overlay-put hl-line-overlay 'priority 1))))
 
+;;; Options
+
 (defcustom notmuch-search-hook '(notmuch-hl-line-mode)
   "List of functions to call when notmuch displays the search results."
   :type 'hook
@@ -165,6 +173,8 @@ (defcustom notmuch-search-hook '(notmuch-hl-line-mode)
   :group 'notmuch-search
   :group 'notmuch-hooks)
 
+;;; Keymap
+
 (defvar notmuch-search-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
@@ -195,6 +205,8 @@ (defvar notmuch-search-mode-map
     map)
   "Keymap for \"notmuch search\" buffers.")
 
+;;; Stashing
+
 (defvar notmuch-search-stash-map
   (let ((map (make-sparse-keymap)))
     (define-key map "i" 'notmuch-search-stash-thread-id)
@@ -214,12 +226,16 @@ (defun notmuch-stash-query ()
   (interactive)
   (notmuch-common-do-stash (notmuch-search-get-query)))
 
+;;; Variables
+
 (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
 (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")
 
+;;; Movement
+
 (defun notmuch-search-scroll-up ()
   "Move forward through search results by one window's worth."
   (interactive)
@@ -271,6 +287,8 @@ (defun notmuch-search-first-thread ()
   (interactive)
   (goto-char (point-min)))
 
+;;; Faces
+
 (defface notmuch-message-summary-face
   `((((class color) (background light))
      ,@(and (>= emacs-major-version 27) '(:extend t))
@@ -356,6 +374,8 @@ (defface notmuch-search-unread-face
   :group 'notmuch-search
   :group 'notmuch-faces)
 
+;;; Mode
+
 (define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
   "Major mode displaying results of a notmuch search.
 
@@ -400,6 +420,8 @@ (define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
   (setq imenu-extract-index-name-function
 	#'notmuch-search-imenu-extract-index-name-function))
 
+;;; Search Results
+
 (defun notmuch-search-get-result (&optional pos)
   "Return the result object for the thread at POS (or point).
 
@@ -558,6 +580,8 @@ (defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
   (let ((message-id (notmuch-search-find-thread-id)))
     (notmuch-mua-new-reply message-id prompt-for-sender nil)))
 
+;;; Tags
+
 (defun notmuch-search-set-tags (tags &optional pos)
   (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))
     (notmuch-search-update-result new-result pos)))
@@ -639,6 +663,8 @@ (defun notmuch-search-archive-thread (&optional unarchive beg end)
   (when (eq beg end)
     (notmuch-search-next-thread)))
 
+;;; Search Results
+
 (defun notmuch-search-update-result (result &optional pos)
   "Replace the result object of the thread at POS (or point) by
 RESULT and redraw it.
@@ -881,6 +907,8 @@ (defun notmuch-search-process-filter (proc string)
 	(notmuch-sexp-parse-partial-list 'notmuch-search-append-result
 					 results-buf)))))
 
+;;; Commands (and some helper functions used by them)
+
 (defun notmuch-search-tag-all (tag-changes)
   "Add/remove tags from all messages in current search buffer.
 
@@ -1132,7 +1160,7 @@ (defun notmuch-cycle-notmuch-buffers ()
 	  (pop-to-buffer-same-window first))
       (notmuch))))
 
-;;;; Imenu Support
+;;; Imenu Support
 
 (defun notmuch-search-imenu-prev-index-position-function ()
   "Move point to previous message in notmuch-search buffer.
@@ -1149,6 +1177,8 @@ (defun notmuch-search-imenu-extract-index-name-function ()
 	(author (notmuch-search-find-authors)))
     (format "%s (%s)" subject author)))
 
+;;; _
+
 (setq mail-user-agent 'notmuch-user-agent)
 
 (provide 'notmuch)
diff --git a/test/test-lib.el b/test/test-lib.el
index ec16c59c..4de5b292 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -1,4 +1,4 @@
-;; test-lib.el --- auxiliary stuff for Notmuch Emacs tests.
+;;; test-lib.el --- auxiliary stuff for Notmuch Emacs tests
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
@@ -20,6 +20,8 @@
 ;;
 ;; Authors: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
 
+;;; Code:
+
 (require 'cl-lib)
 
 ;; Ensure that the dynamic variables that are defined by this library
-- 
2.29.1\r

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 11/36] emacs: use lexical-bindings in all libraries
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (9 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 10/36] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 12/36] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
                     ` (26 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/coolj.el               |  2 +-
 emacs/make-deps.el           |  2 +-
 emacs/notmuch-address.el     |  2 +-
 emacs/notmuch-compat.el      |  2 +-
 emacs/notmuch-crypto.el      |  2 +-
 emacs/notmuch-draft.el       |  2 +-
 emacs/notmuch-hello.el       |  2 +-
 emacs/notmuch-jump.el        |  2 +-
 emacs/notmuch-lib.el         |  2 +-
 emacs/notmuch-maildir-fcc.el |  2 +-
 emacs/notmuch-message.el     |  2 +-
 emacs/notmuch-mua.el         |  7 ++++++-
 emacs/notmuch-parser.el      |  2 +-
 emacs/notmuch-print.el       |  2 +-
 emacs/notmuch-query.el       |  2 +-
 emacs/notmuch-show.el        |  6 +++++-
 emacs/notmuch-tag.el         | 18 ++++++++++--------
 emacs/notmuch-tree.el        |  2 +-
 emacs/notmuch-wash.el        |  2 +-
 emacs/notmuch.el             |  2 +-
 emacs/rstdoc.el              |  2 +-
 21 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/emacs/coolj.el b/emacs/coolj.el
index b3e314f0..d820525b 100644
--- a/emacs/coolj.el
+++ b/emacs/coolj.el
@@ -1,4 +1,4 @@
-;;; coolj.el --- automatically wrap long lines  -*- coding:utf-8 -*-
+;;; coolj.el --- automatically wrap long lines  -*- lexical-binding: t; coding: utf-8 -*-
 
 ;; Copyright (C) 2000, 2001, 2004-2009 Free Software Foundation, Inc.
 
diff --git a/emacs/make-deps.el b/emacs/make-deps.el
index a7699fb1..8c9e0a27 100644
--- a/emacs/make-deps.el
+++ b/emacs/make-deps.el
@@ -1,4 +1,4 @@
-;;; make-deps.el --- compute make dependencies for Elisp sources
+;;; make-deps.el --- compute make dependencies for Elisp sources  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Austin Clements
 ;;
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index bf29c3a0..6b117458 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -1,4 +1,4 @@
-;;; notmuch-address.el --- address completion with notmuch
+;;; notmuch-address.el --- address completion with notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el
index c4e07780..ad134dfe 100644
--- a/emacs/notmuch-compat.el
+++ b/emacs/notmuch-compat.el
@@ -1,4 +1,4 @@
-;;; notmuch-compat.el --- compatibility functions for earlier versions of emacs
+;;; notmuch-compat.el --- compatibility functions for earlier versions of emacs  -*- lexical-binding: t -*-
 ;;
 ;; The functions in this file are copied from more modern versions of
 ;; emacs and are Copyright (C) 1985-1986, 1992, 1994-1995, 1999-2017
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 6d2d35a5..ee5231e5 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -1,4 +1,4 @@
-;;; notmuch-crypto.el --- functions for handling display of cryptographic metadata
+;;; notmuch-crypto.el --- functions for handling display of cryptographic metadata  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Jameson Rollins
 ;;
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 9ce9e736..8af04598 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -1,4 +1,4 @@
-;;; notmuch-draft.el --- functions for postponing and editing drafts
+;;; notmuch-draft.el --- functions for postponing and editing drafts  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Mark Walters
 ;; Copyright © David Bremner
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 28ffedd9..586a2848 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -1,4 +1,4 @@
-;;; notmuch-hello.el --- welcome to notmuch, a frontend
+;;; notmuch-hello.el --- welcome to notmuch, a frontend  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 7a27b6b3..5dcec970 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -1,4 +1,4 @@
-;;; notmuch-jump.el --- User-friendly shortcut keys
+;;; notmuch-jump.el --- User-friendly shortcut keys  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Austin Clements
 ;;
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0b698d59..7595bbe1 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -1,4 +1,4 @@
-;;; notmuch-lib.el --- common variables, functions and function declarations
+;;; notmuch-lib.el --- common variables, functions and function declarations  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;;
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 5de03cc2..e880653c 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -1,4 +1,4 @@
-;;; notmuch-maildir-fcc.el --- inserting using a fcc handler
+;;; notmuch-maildir-fcc.el --- inserting using a fcc handler  -*- lexical-binding: t -*-
 
 ;; Copyright © Jesse Rosenthal
 ;;
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index c2242070..f0e9ffcc 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -1,4 +1,4 @@
-;;; notmuch-message.el --- message-mode functions specific to notmuch
+;;; notmuch-message.el --- message-mode functions specific to notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Jesse Rosenthal
 ;;
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 6fe5f6d0..d50fdb26 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -1,4 +1,4 @@
-;;; notmuch-mua.el --- emacs style mail-user-agent
+;;; notmuch-mua.el --- emacs style mail-user-agent  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
@@ -38,6 +38,11 @@ (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
 (declare-function notmuch-draft-postpone "notmuch-draft" ())
 (declare-function notmuch-draft-save "notmuch-draft" ())
 
+(defvar notmuch-show-indent-multipart)
+(defvar notmuch-show-insert-header-p-function)
+(defvar notmuch-show-max-text-part-size)
+(defvar notmuch-show-insert-text/plain-hook)
+
 ;;; Options
 
 (defcustom notmuch-mua-send-hook nil
diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index 4a437016..b8c3fd2c 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -1,4 +1,4 @@
-;;; notmuch-parser.el --- streaming S-expression parser
+;;; notmuch-parser.el --- streaming S-expression parser  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Austin Clements
 ;;
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index d7b2fcce..8da9a091 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -1,4 +1,4 @@
-;;; notmuch-print.el --- printing messages from notmuch
+;;; notmuch-print.el --- printing messages from notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Edmondson
 ;;
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 72ddd2ce..ffce8814 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -1,4 +1,4 @@
-;;; notmuch-query.el --- provide an emacs api to query notmuch
+;;; notmuch-query.el --- provide an emacs api to query notmuch  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © David Bremner
 ;;
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7dfbb327..72e21d94 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1,4 +1,4 @@
-;;; notmuch-show.el --- displaying notmuch forests
+;;; notmuch-show.el --- displaying notmuch forests  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
@@ -59,6 +59,10 @@ (declare-function notmuch-unthreaded
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-draft-resume "notmuch-draft" (id))
 
+(defvar shr-blocked-images)
+(defvar gnus-blocked-images)
+(defvar shr-content-function)
+
 ;;; Options
 
 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 817ea99f..fa376b02 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -1,4 +1,4 @@
-;;; notmuch-tag.el --- tag messages within emacs
+;;; notmuch-tag.el --- tag messages within emacs  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Damien Cassou
 ;; Copyright © Carl Worth
@@ -295,22 +295,24 @@ (defun notmuch-tag--get-formats (tag format-alist)
 		      (and (eq (string-match key tag) 0)
 			   (= (match-end 0) (length tag)))))))
 
-(defun notmuch-tag--do-format (tag formatted-tag formats)
+(defun notmuch-tag--do-format (bare-tag tag formats)
   "Apply a tag-formats entry to TAG."
   (cond ((null formats)		;; - Tag not in `formats',
-	 formatted-tag)	       	;;   the format is the tag itself.
+	 tag)			;;   the format is the tag itself.
 	((null (cdr formats))	;; - Tag was deliberately hidden,
 	 nil)			;;   no format must be returned
 	(t
 	 ;; Tag was found and has formats, we must apply all the
 	 ;; formats.  TAG may be null so treat that as a special case.
-	 (let ((bare-tag tag)
-	       (tag (copy-sequence (or formatted-tag ""))))
+	 (let ((return-tag (copy-sequence (or tag ""))))
 	   (dolist (format (cdr formats))
-	     (setq tag (eval format)))
-	   (if (and (null formatted-tag) (equal tag ""))
+	     (setq return-tag
+		   (eval format
+			 `((bare-tag . ,bare-tag)
+			   (tag . ,return-tag)))))
+	   (if (and (null tag) (equal return-tag ""))
 	       nil
-	     tag)))))
+	     return-tag)))))
 
 (defun notmuch-tag-format-tag (tags orig-tags tag)
   "Format TAG according to `notmuch-tag-formats'.
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 713b00da..1ed34801 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1,4 +1,4 @@
-;;; notmuch-tree.el --- displaying notmuch forests
+;;; notmuch-tree.el --- displaying notmuch forests  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index f371cc4c..70eff637 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -1,4 +1,4 @@
-;;; notmuch-wash.el --- cleaning up message bodies
+;;; notmuch-wash.el --- cleaning up message bodies  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;; Copyright © David Edmondson
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6a09dd38..ba9488ca 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -1,4 +1,4 @@
-;;; notmuch.el --- run notmuch within emacs
+;;; notmuch.el --- run notmuch within emacs  -*- lexical-binding: t -*-
 ;;
 ;; Copyright © Carl Worth
 ;;
diff --git a/emacs/rstdoc.el b/emacs/rstdoc.el
index 4221f142..c7c13015 100644
--- a/emacs/rstdoc.el
+++ b/emacs/rstdoc.el
@@ -1,4 +1,4 @@
-;;; rstdoc.el --- help generate documentation from docstrings -*-lexical-binding: t-*-
+;;; rstdoc.el --- help generate documentation from docstrings  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2018 David Bremner
 
-- 
2.29.1\r

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 12/36] emacs: deal with unused lexical arguments and variables
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (10 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 11/36] emacs: use lexical-bindings in all libraries Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 13/36] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
                     ` (25 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-address.el     |  4 ++--
 emacs/notmuch-crypto.el      |  2 +-
 emacs/notmuch-hello.el       | 16 +++++++--------
 emacs/notmuch-jump.el        |  6 +++---
 emacs/notmuch-lib.el         |  2 +-
 emacs/notmuch-maildir-fcc.el |  4 ++--
 emacs/notmuch-mua.el         |  2 +-
 emacs/notmuch-print.el       |  6 +++---
 emacs/notmuch-show.el        | 38 ++++++++++++++++++------------------
 emacs/notmuch-tree.el        | 14 +++++--------
 emacs/notmuch-wash.el        | 16 +++++++--------
 emacs/notmuch.el             |  5 ++---
 12 files changed, 54 insertions(+), 61 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 6b117458..1017c3ce 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -191,7 +191,7 @@ (defun notmuch-address-matching (substring)
 The candidates are taken from `notmuch-address-completions'."
   (let ((candidates)
 	(re (regexp-quote substring)))
-    (maphash (lambda (key val)
+    (maphash (lambda (key _val)
 	       (when (string-match re key)
 		 (push key candidates)))
 	     notmuch-address-completions)
@@ -406,7 +406,7 @@ (defun notmuch-address-harvest-trigger ()
       (setq notmuch-address-last-harvest now)
       (notmuch-address-harvest
        nil nil
-       (lambda (proc event)
+       (lambda (_proc event)
 	 ;; If harvest fails, we want to try
 	 ;; again when the trigger is next
 	 ;; called
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index ee5231e5..50a3de46 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -171,7 +171,7 @@ (defun notmuch-crypto-sigstatus-good-callback (button)
 (declare-function notmuch-show-refresh-view "notmuch-show" (&optional reset-state))
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 
-(defun notmuch-crypto--async-key-sentinel (process event)
+(defun notmuch-crypto--async-key-sentinel (process _event)
   "When the user asks for a GPG key to be retrieved
 asynchronously, handle completion of that task.
 
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 586a2848..a134eb07 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -480,7 +480,7 @@ (defun notmuch-hello-reflect (list ncols)
     (cl-loop for row from 0 to (- nrows 1)
 	     append (notmuch-hello-reflect-generate-row ncols nrows row list))))
 
-(defun notmuch-hello-widget-search (widget &rest ignore)
+(defun notmuch-hello-widget-search (widget &rest _ignore)
   (cond
    ((eq (widget-get widget :notmuch-search-type) 'tree)
     (notmuch-tree (widget-get widget
@@ -775,14 +775,14 @@ (defun notmuch-hello-insert-header ()
   (let ((widget-link-prefix "")
 	(widget-link-suffix ""))
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (browse-url notmuch-hello-url))
 		   :help-echo "Visit the notmuch website."
 		   "notmuch")
     (widget-insert ". ")
     (widget-insert "You have ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (notmuch-hello-update))
 		   :help-echo "Refresh"
 		   (notmuch-hello-nice-number
@@ -801,7 +801,7 @@ (defun notmuch-hello-insert-saved-searches ()
     (when searches
       (widget-insert "Saved searches: ")
       (widget-create 'push-button
-		     :notify (lambda (&rest ignore)
+		     :notify (lambda (&rest _ignore)
 			       (customize-variable 'notmuch-saved-searches))
 		     "edit")
       (widget-insert "\n\n")
@@ -873,13 +873,13 @@ (defun notmuch-hello-insert-searches (title query-list &rest options)
 	(start (point)))
     (if is-hidden
 	(widget-create 'push-button
-		       :notify `(lambda (widget &rest ignore)
+		       :notify `(lambda (widget &rest _ignore)
 				  (setq notmuch-hello-hidden-sections
 					(delete ,title notmuch-hello-hidden-sections))
 				  (notmuch-hello-update))
 		       "show")
       (widget-create 'push-button
-		     :notify `(lambda (widget &rest ignore)
+		     :notify `(lambda (widget &rest _ignore)
 				(add-to-list 'notmuch-hello-hidden-sections
 					     ,title)
 				(notmuch-hello-update))
@@ -928,13 +928,13 @@ (defun notmuch-hello-insert-footer ()
     (widget-insert "Hit `?' for context-sensitive help in any Notmuch screen.\n")
     (widget-insert "Customize ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (customize-group 'notmuch))
 		   :button-prefix "" :button-suffix ""
 		   "Notmuch")
     (widget-insert " or ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 			     (customize-variable 'notmuch-hello-sections))
 		   :button-prefix "" :button-suffix ""
 		   "this page.")
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 5dcec970..51bc4e31 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -120,7 +120,7 @@ (defun notmuch-jump--format-actions (action-map)
 buffer."
   ;; Compute the maximum key description width
   (let ((key-width 1))
-    (pcase-dolist (`(,key ,desc) action-map)
+    (pcase-dolist (`(,key ,_desc) action-map)
       (setq key-width
 	    (max key-width
 		 (string-width (format-kbd-macro key)))))
@@ -164,7 +164,7 @@ (defun notmuch-jump--make-keymap (action-map prompt)
   "Translate ACTION-MAP into a minibuffer keymap."
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-jump-minibuffer-map)
-    (pcase-dolist (`(,key ,name ,fn) action-map)
+    (pcase-dolist (`(,key ,_name ,fn) action-map)
       (when (= (length key) 1)
 	(define-key map key
 	  `(lambda () (interactive)
@@ -173,7 +173,7 @@ (defun notmuch-jump--make-keymap (action-map prompt)
     ;; By doing this in two passes (and checking if we already have a
     ;; binding) we avoid problems if the user specifies a binding which
     ;; is a prefix of another binding.
-    (pcase-dolist (`(,key ,name ,fn) action-map)
+    (pcase-dolist (`(,key ,_name ,_fn) action-map)
       (when (> (length key) 1)
 	(let* ((key (elt key 0))
 	       (keystr (string key))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 7595bbe1..1bdfc2b9 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -978,7 +978,7 @@ (defun notmuch-start-notmuch-sentinel (proc event)
        ;; so turn errors into messages.
        (message "%s" (error-message-string err))))))
 
-(defun notmuch-start-notmuch-error-sentinel (proc event)
+(defun notmuch-start-notmuch-error-sentinel (proc _event)
   (unless (process-live-p proc)
     (let ((buffer (process-buffer proc)))
       (when (buffer-live-p buffer)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index e880653c..9f09129d 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -346,12 +346,12 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
 	(let ((msg-id (notmuch-maildir-fcc-save-buffer-to-tmp destdir)))
 	  (when msg-id
 	    (cond (mark-seen
-		   (condition-case err
+		   (condition-case nil
 		       (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
 		     (file-already-exists
 		      (throw 'link-error nil))))
 		  (t
-		   (condition-case err
+		   (condition-case nil
 		       (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id)
 		     (file-already-exists
 		      (throw 'link-error nil))))))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index d50fdb26..b2930051 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -370,7 +370,7 @@ (defun notmuch-mua-pop-to-buffer (name switch-function)
     (erase-buffer)
     (notmuch-message-mode)))
 
-(defun notmuch-mua-mail (&optional to subject other-headers continue
+(defun notmuch-mua-mail (&optional to subject other-headers _continue
 				   switch-function yank-action send-actions
 				   return-action &rest ignored)
   "Invoke the notmuch mail composition window."
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 8da9a091..d0061499 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -58,7 +58,7 @@ (defun notmuch-print-run-muttprint (&optional output)
 
 ;;; User-visible functions
 
-(defun notmuch-print-lpr (msg)
+(defun notmuch-print-lpr (_msg)
   "Print a message buffer using lpr."
   (lpr-buffer))
 
@@ -78,11 +78,11 @@ (defun notmuch-print-ps-print/evince (msg)
     (ps-print-buffer ps-file)
     (notmuch-print-run-evince ps-file)))
 
-(defun notmuch-print-muttprint (msg)
+(defun notmuch-print-muttprint (_msg)
   "Print a message using muttprint."
   (notmuch-print-run-muttprint))
 
-(defun notmuch-print-muttprint/evince (msg)
+(defun notmuch-print-muttprint/evince (_msg)
   "Preview a message buffer using muttprint and evince."
   (let ((ps-file (make-temp-file "notmuch" nil ".ps")))
     (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 72e21d94..48374b38 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -517,7 +517,7 @@ (define-button-type 'notmuch-show-part-button-type
   'face 'message-mml
   :supertype 'notmuch-button-type)
 
-(defun notmuch-show-insert-part-header (nth content-type declared-type
+(defun notmuch-show-insert-part-header (_nth content-type declared-type
 					    &optional name comment)
   (let ((base-label (concat (and name (concat name ": "))
 			    declared-type
@@ -624,7 +624,7 @@ (defun notmuch-show-setup-w3m ()
   (setq mm-html-inhibit-images nil))
 
 (defvar w3m-current-buffer) ;; From `w3m.el'.
-(defun notmuch-show--cid-w3m-retrieve (url &rest args)
+(defun notmuch-show--cid-w3m-retrieve (url &rest _args)
   ;; url includes the cid: prefix and is URL encoded (see RFC 2392).
   (let* ((cid (url-unhex-string (substring url 4)))
 	 (content-and-type
@@ -640,7 +640,7 @@ (defun notmuch-show-multipart/*-to-list (part)
   (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
 	  (plist-get part :content)))
 
-(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/alternative (msg part _content-type _nth depth _button)
   (let ((chosen-type (car (notmuch-multipart/alternative-choose
 			   msg (notmuch-show-multipart/*-to-list part))))
 	(inner-parts (plist-get part :content))
@@ -659,7 +659,7 @@ (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/related (msg part _content-type _nth depth _button)
   (let ((inner-parts (plist-get part :content))
 	(start (point)))
     ;; Render the primary part.  FIXME: Support RFC 2387 Start header.
@@ -672,7 +672,7 @@ (defun notmuch-show-insert-part-multipart/related (msg part content-type nth dep
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/signed (msg part _content-type _nth depth button)
   (when button
     (button-put button 'face 'notmuch-crypto-part-header))
   ;; Insert a button detailing the signature status.
@@ -688,7 +688,7 @@ (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth dept
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/encrypted (msg part _content-type _nth depth button)
   (when button
     (button-put button 'face 'notmuch-crypto-part-header))
   ;; Insert a button detailing the encryption status.
@@ -706,10 +706,10 @@ (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth d
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-application/pgp-encrypted (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-application/pgp-encrypted (_msg _part _content-type _nth _depth _button)
   t)
 
-(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-multipart/* (msg part _content-type _nth depth _button)
   (let ((inner-parts (plist-get part :content))
 	(start (point)))
     ;; Show all of the parts.
@@ -720,7 +720,7 @@ (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth but
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-message/rfc822 (msg part _content-type _nth depth _button)
   (let* ((message (car (plist-get part :content)))
 	 (body (car (plist-get message :body)))
 	 (start (point)))
@@ -737,7 +737,7 @@ (defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth
       (indent-rigidly start (point) 1)))
   t)
 
-(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-text/plain (msg part _content-type _nth depth button)
   ;; For backward compatibility we want to apply the text/plain hook
   ;; to the whole of the part including the part button if there is
   ;; one.
@@ -751,7 +751,7 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt
 	(run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))
   t)
 
-(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-text/calendar (msg part _content-type _nth _depth _button)
   (insert (with-temp-buffer
 	    (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto))
 	    ;; notmuch-get-bodypart-text does no newline conversion.
@@ -775,8 +775,8 @@ (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth b
   t)
 
 ;; For backwards compatibility.
-(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth button)
-  (notmuch-show-insert-part-text/calendar msg part content-type nth depth button))
+(defun notmuch-show-insert-part-text/x-vcalendar (msg part _content-type _nth depth _button)
+  (notmuch-show-insert-part-text/calendar msg part nil nil depth nil))
 
 (when (version< emacs-version "25.3")
   ;; https://bugs.gnu.org/28350
@@ -792,7 +792,7 @@ (when (version< emacs-version "25.3")
     ;; the first time).
     (require 'enriched)
     (cl-letf (((symbol-function 'enriched-decode-display-prop)
-	       (lambda (start end &optional param) (list start end))))
+	       (lambda (start end &optional _param) (list start end))))
       (notmuch-show-insert-part-*/* msg part content-type nth depth button))))
 
 (defun notmuch-show-get-mime-type-of-application/octet-stream (part)
@@ -850,7 +850,7 @@ (defun notmuch-show--insert-part-text/html-shr (msg part)
     (shr-insert-document dom)
     t))
 
-(defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)
+(defun notmuch-show-insert-part-*/* (msg part content-type _nth _depth _button)
   ;; This handler _must_ succeed - it is the handler of last resort.
   (notmuch-mm-display-part-inline msg part content-type notmuch-show-process-crypto)
   t)
@@ -970,13 +970,13 @@ (defvar notmuch-show-insert-header-p-function 'notmuch-show-insert-header-p
 should return non-NIL if a header button should be inserted for
 this part.")
 
-(defun notmuch-show-insert-header-p (part hide)
+(defun notmuch-show-insert-header-p (part _hide)
   ;; Show all part buttons except for the first part if it is text/plain.
   (let ((mime-type (notmuch-show-mime-type part)))
     (not (and (string= mime-type "text/plain")
 	      (<= (plist-get part :id) 1)))))
 
-(defun notmuch-show-reply-insert-header-p-never (part hide)
+(defun notmuch-show-reply-insert-header-p-never (_part _hide)
   nil)
 
 (defun notmuch-show-reply-insert-header-p-trimmed (part hide)
@@ -1759,7 +1759,7 @@ (defun notmuch-show-mark-read (&optional unread)
     (apply 'notmuch-show-tag-message
 	   (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
 
-(defun notmuch-show-seen-current-message (start end)
+(defun notmuch-show-seen-current-message (_start _end)
   "Mark the current message read if it is open.
 
 We only mark it read once: if it is changed back then that is a
@@ -1777,7 +1777,7 @@ (defun notmuch-show-command-hook ()
     ;; We need to redisplay to get window-start and window-end correct.
     (redisplay)
     (save-excursion
-      (condition-case err
+      (condition-case nil
 	  (funcall notmuch-show-mark-read-function (window-start) (window-end))
 	((debug error)
 	 (unless notmuch-show--seen-has-errored
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 1ed34801..e254593f 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -598,8 +598,7 @@ (defun notmuch-tree-show-message-out ()
   "Show the current message (in whole window)."
   (interactive)
   (let ((id (notmuch-tree-get-message-id))
-	(inhibit-read-only t)
-	buffer)
+	(inhibit-read-only t))
     (when id
       ;; We close the window to kill off un-needed buffers.
       (notmuch-tree-close-message-window)
@@ -1033,19 +1032,17 @@ (define-derived-mode notmuch-tree-mode fundamental-mode "notmuch-tree"
   (setq buffer-read-only t)
   (setq truncate-lines t))
 
-(defun notmuch-tree-process-sentinel (proc msg)
+(defun notmuch-tree-process-sentinel (proc _msg)
   "Add a message to let user know when \"notmuch tree\" exits."
   (let ((buffer (process-buffer proc))
 	(status (process-status proc))
-	(exit-status (process-exit-status proc))
-	(never-found-target-thread nil))
+	(exit-status (process-exit-status proc)))
     (when (memq status '(exit signal))
       (kill-buffer (process-get proc 'parse-buf))
       (when (buffer-live-p buffer)
 	(with-current-buffer buffer
 	  (save-excursion
-	    (let ((inhibit-read-only t)
-		  (atbob (bobp)))
+	    (let ((inhibit-read-only t))
 	      (goto-char (point-max))
 	      (when (eq status 'signal)
 		(insert "Incomplete search results (tree view process was killed).\n"))
@@ -1059,8 +1056,7 @@ (defun notmuch-tree-process-filter (proc string)
   "Process and filter the output of \"notmuch show\" for tree view."
   (let ((results-buf (process-buffer proc))
 	(parse-buf (process-get proc 'parse-buf))
-	(inhibit-read-only t)
-	done)
+	(inhibit-read-only t))
     (if (not (buffer-live-p results-buf))
 	(delete-process proc)
       (with-current-buffer parse-buf
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 70eff637..36041904 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -237,11 +237,10 @@ (defun notmuch-wash-excerpt-citations (msg depth)
   (beginning-of-line)
   (when (and (< (point) (point-max))
 	     (re-search-forward notmuch-wash-original-regexp nil t))
-    (let* ((msg-start (match-beginning 0))
-	   (msg-end (point-max))
-	   (msg-lines (count-lines msg-start msg-end)))
-      (notmuch-wash-region-to-button
-       msg msg-start msg-end "original")))
+    (notmuch-wash-region-to-button msg
+				   (match-beginning 0)
+				   (point-max)
+				   "original"))
   (while (and (< (point) (point-max))
 	      (re-search-forward notmuch-wash-citation-regexp nil t))
     (let* ((cite-start (match-beginning 0))
@@ -262,10 +261,9 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	   "citation")))))
   (when (and (not (eobp))
 	     (re-search-forward notmuch-wash-signature-regexp nil t))
-    (let* ((sig-start (match-beginning 0))
-	   (sig-end (match-end 0))
-	   (sig-lines (count-lines sig-start (point-max))))
-      (when (<= sig-lines notmuch-wash-signature-lines-max)
+    (let ((sig-start (match-beginning 0)))
+      (when (<= (count-lines sig-start (point-max))
+		notmuch-wash-signature-lines-max)
 	(let ((sig-start-marker (make-marker))
 	      (sig-end-marker (make-marker)))
 	  (set-marker sig-start-marker sig-start)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index ba9488ca..3928cd65 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -693,7 +693,7 @@ (defun notmuch-search-update-result (result &optional pos)
 			  (min init-point (- new-end 1)))))
 	(goto-char new-point)))))
 
-(defun notmuch-search-process-sentinel (proc msg)
+(defun notmuch-search-process-sentinel (proc _msg)
   "Add a message to let user know when \"notmuch search\" exits."
   (let ((buffer (process-buffer proc))
 	(status (process-status proc))
@@ -896,8 +896,7 @@ (defun notmuch-search-process-filter (proc string)
   "Process and filter the output of \"notmuch search\"."
   (let ((results-buf (process-buffer proc))
 	(parse-buf (process-get proc 'parse-buf))
-	(inhibit-read-only t)
-	done)
+	(inhibit-read-only t))
     (when (buffer-live-p results-buf)
       (with-current-buffer parse-buf
 	;; Insert new data
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 13/36] emacs: notmuch-tag--get-formats: silence byte-compiler
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (11 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 12/36] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 14/36] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
                     ` (24 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

`format-alist' is a global variable and the byte-compiler is unhappy
when a lexical function argument shadows a global (dynamic) binding.
---
 emacs/notmuch-tag.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index fa376b02..a553dfd9 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -285,12 +285,12 @@ (defun notmuch-tag-clear-cache ()
   "Clear the internal cache of tag formats."
   (clrhash notmuch-tag--format-cache))
 
-(defun notmuch-tag--get-formats (tag format-alist)
+(defun notmuch-tag--get-formats (tag alist)
   "Find the first item whose car regexp-matches TAG."
   (save-match-data
     ;; Don't use assoc-default since there's no way to distinguish a
     ;; missing key from a present key with a null cdr.
-    (cl-assoc tag format-alist
+    (cl-assoc tag alist
 	      :test (lambda (tag key)
 		      (and (eq (string-match key tag) 0)
 			   (= (match-end 0) (length tag)))))))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 14/36] emacs: inline notmuch-sexp-eof into only caller
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (12 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 13/36] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 15/36] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
                     ` (23 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

This function had a few issues.
- Neither its name nor the old comment before it is called made it
  clear what it does.
- It took one argument but didn't do anything with it.
- It's doc-string made a few claims, which are untrue and generally
  focused on details instead of that its purpose is.
---
 emacs/notmuch-parser.el | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index b8c3fd2c..294e0544 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -140,15 +140,6 @@ (defun notmuch-sexp-begin-list (sp)
 	 (forward-char)
 	 (signal 'invalid-read-syntax (list (string (char-before)))))))
 
-(defun notmuch-sexp-eof (sp)
-  "Signal an error if there is more data in SP's buffer.
-
-Moves point to the beginning of any trailing data or to the end
-of the buffer if there is only trailing whitespace."
-  (skip-chars-forward " \n\r\t")
-  (unless (eobp)
-    (error "Trailing garbage following expression")))
-
 (defvar notmuch-sexp--parser nil
   "The buffer-local notmuch-sexp-parser instance.
 
@@ -187,8 +178,11 @@ (defun notmuch-sexp-parse-partial-list (result-function result-buffer)
 	     (t     (with-current-buffer result-buffer
 		      (funcall result-function result))))))
 	(end
-	 ;; Any trailing data is unexpected
-	 (notmuch-sexp-eof notmuch-sexp--parser)
+	 ;; Skip over trailing whitespace.
+	 (skip-chars-forward " \n\r\t")
+	 ;; Any trailing data is unexpected.
+	 (unless (eobp)
+	   (error "Trailing garbage following expression"))
 	 (setq done t)))))
   ;; Clear out what we've parsed
   (delete-region (point-min) (point)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 15/36] emacs: notmuch-wash-region-to-button: remove unused MSG argument
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (13 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 14/36] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 16/36] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
                     ` (22 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-wash.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 36041904..4fbb4e12 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -200,7 +200,7 @@ (defun notmuch-wash-button-label (overlay)
 				   (overlay-end overlay))))
     (format label-format lines-count)))
 
-(defun notmuch-wash-region-to-button (msg beg end type &optional prefix)
+(defun notmuch-wash-region-to-button (beg end type &optional prefix)
   "Auxiliary function to do the actual making of overlays and buttons.
 
 BEG and END are buffer locations. TYPE should a string, either
@@ -237,8 +237,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
   (beginning-of-line)
   (when (and (< (point) (point-max))
 	     (re-search-forward notmuch-wash-original-regexp nil t))
-    (notmuch-wash-region-to-button msg
-				   (match-beginning 0)
+    (notmuch-wash-region-to-button (match-beginning 0)
 				   (point-max)
 				   "original"))
   (while (and (< (point) (point-max))
@@ -257,7 +256,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	  (goto-char cite-end)
 	  (forward-line (- notmuch-wash-citation-lines-suffix))
 	  (notmuch-wash-region-to-button
-	   msg hidden-start (point-marker)
+	   hidden-start (point-marker)
 	   "citation")))))
   (when (and (not (eobp))
 	     (re-search-forward notmuch-wash-signature-regexp nil t))
@@ -271,7 +270,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	  (overlay-put (make-overlay sig-start-marker sig-end-marker)
 		       'face 'message-cited-text)
 	  (notmuch-wash-region-to-button
-	   msg sig-start-marker sig-end-marker
+	   sig-start-marker sig-end-marker
 	   "signature"))))))
 
 (defun notmuch-wash-elide-blank-lines (msg depth)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 16/36] emacs: silence compiler wrt notmuch-show-insert-part-text/plain
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (14 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 15/36] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 17/36] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
                     ` (21 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

`notmuch-show-insert-part-text/plain' calls
`notmuch-show-insert-text/plain-hook' with two arguments
MSG and DEPTH. Currently all hook functions ignore MSG but
third-party functions may not.  One hook function uses DEPTH.
---
 emacs/notmuch-wash.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 4fbb4e12..d613e04c 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -231,7 +231,7 @@ (defun notmuch-wash-region-to-button (beg end type &optional prefix)
 
 ;;; Hook functions
 
-(defun notmuch-wash-excerpt-citations (msg depth)
+(defun notmuch-wash-excerpt-citations (_msg _depth)
   "Excerpt citations and up to one signature."
   (goto-char (point-min))
   (beginning-of-line)
@@ -273,7 +273,7 @@ (defun notmuch-wash-excerpt-citations (msg depth)
 	   sig-start-marker sig-end-marker
 	   "signature"))))))
 
-(defun notmuch-wash-elide-blank-lines (msg depth)
+(defun notmuch-wash-elide-blank-lines (_msg _depth)
   "Elide leading, trailing and successive blank lines."
   ;; Algorithm derived from `article-strip-multiple-blank-lines' in
   ;; `gnus-art.el'.
@@ -294,7 +294,7 @@ (defun notmuch-wash-elide-blank-lines (msg depth)
   (when (looking-at "\n")
     (delete-region (match-beginning 0) (match-end 0))))
 
-(defun notmuch-wash-tidy-citations (msg depth)
+(defun notmuch-wash-tidy-citations (_msg _depth)
   "Improve the display of cited regions of a message.
 
 Perform several transformations on the message body:
@@ -318,7 +318,7 @@ (defun notmuch-wash-tidy-citations (msg depth)
   (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
     (replace-match "\\2")))
 
-(defun notmuch-wash-wrap-long-lines (msg depth)
+(defun notmuch-wash-wrap-long-lines (_msg depth)
   "Wrap long lines in the message.
 
 If `notmuch-wash-wrap-lines-length' is a number, this will wrap
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 17/36] emacs: define notmuch-message-queued-tag-changes as buffer-local
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (15 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 16/36] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 18/36] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
                     ` (20 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

Also improve the doc-string.
---
 emacs/notmuch-message.el | 14 +++++++-------
 emacs/notmuch-mua.el     | 12 ++++++------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index f0e9ffcc..9dc8d056 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -50,14 +50,14 @@ (defcustom notmuch-message-forwarded-tags '("+forwarded")
   :type '(repeat string)
   :group 'notmuch-send)
 
-(defconst notmuch-message-queued-tag-changes nil
-  "List of messages and corresponding tag-changes to be applied when sending a message.
+(defvar-local notmuch-message-queued-tag-changes nil
+  "List of tag changes to be applied when sending a message.
 
-This variable is overridden by buffer-local versions in message
-buffers where tag changes should be triggered when sending off
-the message.  Each item in this list is a list of strings, where
-the first is a notmuch query and the rest are the tag changes to
-be applied to the matching messages.")
+A list of queries and tag changes that are to be applied to them
+when the message that was composed in the current buffer is being
+send.  Each item in this list is a list of strings, where the
+first is a notmuch query and the rest are the tag changes to be
+applied to the matching messages.")
 
 (defun notmuch-message-apply-queued-tag-changes ()
   ;; Apply the tag changes queued in the buffer-local variable
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index b2930051..95d1965b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -266,8 +266,8 @@ (defun notmuch-mua-reply (query-string &optional sender reply-all)
       ;; Create a buffer-local queue for tag changes triggered when
       ;; sending the reply.
       (when notmuch-message-replied-tags
-	(setq-local notmuch-message-queued-tag-changes
-		    (list (cons query-string notmuch-message-replied-tags))))
+	(setq notmuch-message-queued-tag-changes
+	      (list (cons query-string notmuch-message-replied-tags))))
       ;; Insert the message body - but put it in front of the signature
       ;; if one is present, and after any other content
       ;; message*setup-hooks may have added to the message body already.
@@ -507,10 +507,10 @@ (defun notmuch-mua-new-forward-messages (messages &optional prompt-for-sender)
       ;; Create a buffer-local queue for tag changes triggered when
       ;; sending the message.
       (when notmuch-message-forwarded-tags
-	(setq-local notmuch-message-queued-tag-changes
-		    (cl-loop for id in forward-queries
-			     collect
-			     (cons id notmuch-message-forwarded-tags))))
+	(setq notmuch-message-queued-tag-changes
+	      (cl-loop for id in forward-queries
+		       collect
+		       (cons id notmuch-message-forwarded-tags))))
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
       (message-hide-headers)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 18/36] emacs: notmuch-message-apply-queued-tag-changes: cosmetics
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (16 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 17/36] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 19/36] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
                     ` (19 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-message.el | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 9dc8d056..abeff53a 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -62,9 +62,8 @@ (defvar-local notmuch-message-queued-tag-changes nil
 (defun notmuch-message-apply-queued-tag-changes ()
   ;; Apply the tag changes queued in the buffer-local variable
   ;; notmuch-message-queued-tag-changes.
-  (dolist (query-and-tags notmuch-message-queued-tag-changes)
-    (notmuch-tag (car query-and-tags)
-		 (cdr query-and-tags))))
+  (pcase-dolist (`(,query . ,tags) notmuch-message-queued-tag-changes)
+    (notmuch-tag query tags)))
 
 (add-hook 'message-send-hook 'notmuch-message-apply-queued-tag-changes)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 19/36] emacs: notmuch-wash.el: require diff-mode at beginning of code
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (17 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 18/36] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 20/36] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
                     ` (18 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

That's what we usually do.  Also do not declare variable
`diff-file-header-re' because it is defined in `diff-mode.el',
which we always require.
---
 emacs/notmuch-wash.el | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index d613e04c..653ecc2a 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -24,6 +24,7 @@
 ;;; Code:
 
 (require 'coolj)
+(require 'diff-mode)
 (require 'notmuch-lib)
 
 (declare-function notmuch-show-insert-bodypart "notmuch-show"
@@ -341,10 +342,6 @@ (defun notmuch-wash-wrap-long-lines (_msg depth)
 
 ;;;; Convert Inline Patches
 
-(require 'diff-mode)
-
-(defvar diff-file-header-re) ; From `diff-mode.el'.
-
 (defun notmuch-wash-subject-to-filename (subject &optional maxlen)
   "Convert a mail SUBJECT into a filename.
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 20/36] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (18 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 19/36] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 21/36] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
                     ` (17 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

We shouldn't force `ido-completion-read' on users who do not otherwise
use Ido.  Unfortunately simply turning on `ido-mode' does not change
every `completing-read' into a `ido-completing-read', instead it only
changes file and buffer completion.

I do realize that existing Ido users will initially dislike this
change, but I would like to encourage them to see this as an
opportunity to learn about Fido.

Unlike `ido-mode', build-in `fido-mode' confirms to the standard
completion API, so turning it on causes every `completing-read' to
use the Fido completion mechanism and which is similar to the Ido
mechanism:

> An enhanced `icomplete-mode' that emulates `ido-mode'.  This global
> minor mode makes minibuffer completion behave more like `ido-mode'
> than regular `icomplete-mode'."
---
 emacs/notmuch-mua.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 95d1965b..2d0b7169 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -431,16 +431,16 @@ (defvar notmuch-mua-sender-history nil)
 (defun notmuch-mua-prompt-for-sender ()
   "Prompt for a sender from the user's configured identities."
   (if notmuch-identities
-      (ido-completing-read "Send mail from: " notmuch-identities
-			   nil nil nil 'notmuch-mua-sender-history
-			   (car notmuch-identities))
+      (completing-read "Send mail from: " notmuch-identities
+		       nil nil nil 'notmuch-mua-sender-history
+		       (car notmuch-identities))
     (let* ((name (notmuch-user-name))
 	   (addrs (cons (notmuch-user-primary-email)
 			(notmuch-user-other-email)))
 	   (address
-	    (ido-completing-read (concat "Sender address for " name ": ") addrs
-				 nil nil nil 'notmuch-mua-sender-history
-				 (car addrs))))
+	    (completing-read (concat "Sender address for " name ": ") addrs
+			     nil nil nil 'notmuch-mua-sender-history
+			     (car addrs))))
       (message-make-from name address))))
 
 (put 'notmuch-mua-new-mail 'notmuch-prefix-doc "... and prompt for sender")
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 21/36] emacs: notmuch-mua.el: move all options into "Options" section
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (19 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 20/36] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 22/36] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
                     ` (16 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

This is how we do it in other libraries.
---
 emacs/notmuch-mua.el | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 2d0b7169..74ffd8f2 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -82,6 +82,22 @@ (defcustom notmuch-mua-hidden-headers nil
   :type '(repeat string)
   :group 'notmuch-send)
 
+(defcustom notmuch-identities nil
+  "Identities that can be used as the From: address when composing a new message.
+
+If this variable is left unset, then a list will be constructed from the
+name and addresses configured in the notmuch configuration file."
+  :type '(repeat string)
+  :group 'notmuch-send)
+
+(defcustom notmuch-always-prompt-for-sender nil
+  "Always prompt for the From: address when composing or forwarding a message.
+
+This is not taken into account when replying to a message, because in that case
+the From: header is already filled in by notmuch."
+  :type 'boolean
+  :group 'notmuch-send)
+
 (defgroup notmuch-reply nil
   "Replying to messages in notmuch"
   :group 'notmuch)
@@ -410,22 +426,6 @@ (defun notmuch-mua-mail (&optional to subject other-headers _continue
   (notmuch-mua-maybe-set-window-dedicated)
   (message-goto-to))
 
-(defcustom notmuch-identities nil
-  "Identities that can be used as the From: address when composing a new message.
-
-If this variable is left unset, then a list will be constructed from the
-name and addresses configured in the notmuch configuration file."
-  :type '(repeat string)
-  :group 'notmuch-send)
-
-(defcustom notmuch-always-prompt-for-sender nil
-  "Always prompt for the From: address when composing or forwarding a message.
-
-This is not taken into account when replying to a message, because in that case
-the From: header is already filled in by notmuch."
-  :type 'boolean
-  :group 'notmuch-send)
-
 (defvar notmuch-mua-sender-history nil)
 
 (defun notmuch-mua-prompt-for-sender ()
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 22/36] emacs: notmuch-crypto-status-button-type: fix potential bug
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (20 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 21/36] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-10 14:00   ` [PATCH v2 23/36] emacs: various cosmetic improvements Jonas Bernoulli
                     ` (15 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

The "help-echo" can potentially contain an unintended %-spec
so we have to make sure it would not be treated as such.
---
 emacs/notmuch-crypto.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 50a3de46..db7cb75d 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -103,7 +103,7 @@ (defface notmuch-crypto-decryption
 ;;; Functions
 
 (define-button-type 'notmuch-crypto-status-button-type
-  'action (lambda (button) (message (button-get button 'help-echo)))
+  'action (lambda (button) (message "%s" (button-get button 'help-echo)))
   'follow-link t
   'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."
   :supertype 'notmuch-button-type)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 23/36] emacs: various cosmetic improvements
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (21 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 22/36] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
@ 2021-01-10 14:00   ` Jonas Bernoulli
  2021-01-13 17:37     ` [PATCH v3 " Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 24/36] emacs: various comment improvements Jonas Bernoulli
                     ` (14 subsequent siblings)
  37 siblings, 1 reply; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:00 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-address.el     | 22 ++++------
 emacs/notmuch-hello.el       | 24 ++++-------
 emacs/notmuch-jump.el        |  4 +-
 emacs/notmuch-lib.el         | 26 +++++------
 emacs/notmuch-maildir-fcc.el | 61 +++++++++++---------------
 emacs/notmuch-mua.el         | 28 ++++++------
 emacs/notmuch-query.el       | 11 +++--
 emacs/notmuch-tag.el         | 14 +++---
 emacs/notmuch.el             | 83 ++++++++++++++++++------------------
 9 files changed, 125 insertions(+), 148 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1017c3ce..2f0ec9b3 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -21,6 +21,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
@@ -160,15 +162,12 @@ (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (let* ((setup-company (and notmuch-address-use-company
-			     (require 'company nil t)))
-	 (pair (cons notmuch-address-completion-headers-regexp
-		     #'notmuch-address-expand-name)))
-    (when setup-company
-      (notmuch-company-setup))
-    (unless (member pair message-completion-alist)
-      (setq message-completion-alist
-	    (push pair message-completion-alist)))))
+  (when (and notmuch-address-use-company
+	     (require 'company nil t))
+    (notmuch-company-setup))
+  (cl-pushnew (cons notmuch-address-completion-headers-regexp
+		    #'notmuch-address-expand-name)
+	      message-completion-alist :test #'equal))
 
 (defun notmuch-address-toggle-internal-completion ()
   "Toggle use of internal completion for current buffer.
@@ -264,9 +263,6 @@ (defun notmuch-address-harvest-addr (result)
   (let ((name-addr (plist-get result :name-addr)))
     (puthash name-addr t notmuch-address-completions)))
 
-(defun notmuch-address-harvest-handle-result (obj)
-  (notmuch-address-harvest-addr obj))
-
 (defun notmuch-address-harvest-filter (proc string)
   (when (buffer-live-p (process-buffer proc))
     (with-current-buffer (process-buffer proc)
@@ -274,7 +270,7 @@ (defun notmuch-address-harvest-filter (proc string)
 	(goto-char (point-max))
 	(insert string))
       (notmuch-sexp-parse-partial-list
-       'notmuch-address-harvest-handle-result (process-buffer proc)))))
+       'notmuch-address-harvest-addr (process-buffer proc)))))
 
 (defvar notmuch-address-harvest-procs '(nil . nil)
   "The currently running harvests.
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index a134eb07..ffd3d799 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -432,8 +432,7 @@ (defun notmuch-hello-add-saved-search (widget &rest _event)
     ;; If an existing saved search with this name exists, remove it.
     (setq notmuch-saved-searches
 	  (cl-loop for elem in notmuch-saved-searches
-		   if (not (equal name
-				  (notmuch-saved-search-get elem :name)))
+		   unless (equal name (notmuch-saved-search-get elem :name))
 		   collect elem))
     ;; Add the new one.
     (customize-save-variable 'notmuch-saved-searches
@@ -481,18 +480,14 @@ (defun notmuch-hello-reflect (list ncols)
 	     append (notmuch-hello-reflect-generate-row ncols nrows row list))))
 
 (defun notmuch-hello-widget-search (widget &rest _ignore)
-  (cond
-   ((eq (widget-get widget :notmuch-search-type) 'tree)
-    (notmuch-tree (widget-get widget
-			      :notmuch-search-terms)))
-   ((eq (widget-get widget :notmuch-search-type) 'unthreaded)
-    (notmuch-unthreaded (widget-get widget
-				    :notmuch-search-terms)))
+  (cl-case (widget-get widget :notmuch-search-type)
+   (tree
+    (notmuch-tree (widget-get widget :notmuch-search-terms)))
+   (unthreaded
+    (notmuch-unthreaded (widget-get widget :notmuch-search-terms)))
    (t
-    (notmuch-search (widget-get widget
-				:notmuch-search-terms)
-		    (widget-get widget
-				:notmuch-search-oldest-first)))))
+    (notmuch-search (widget-get widget :notmuch-search-terms)
+		    (widget-get widget :notmuch-search-oldest-first)))))
 
 (defun notmuch-saved-search-count (search)
   (car (process-lines notmuch-command "count" search)))
@@ -823,8 +818,7 @@ (defun notmuch-hello-insert-search ()
   ;; instead of a space to make `show-trailing-whitespace'
   ;; happy, i.e. avoid it marking the whole line as trailing
   ;; spaces.
-  (widget-insert ".")
-  (put-text-property (1- (point)) (point) 'invisible t)
+  (widget-insert (propertize "." 'invisible t))
   (widget-insert "\n"))
 
 (defun notmuch-hello-insert-recent-searches ()
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 51bc4e31..34d6c796 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -63,8 +63,8 @@ (defun notmuch-jump-search ()
     (setq action-map (nreverse action-map))
     (if action-map
 	(notmuch-jump action-map "Search: ")
-      (error "To use notmuch-jump, \
-please customize shortcut keys in notmuch-saved-searches."))))
+      (error "To use notmuch-jump, %s"
+	     "please customize shortcut keys in notmuch-saved-searches."))))
 
 (defvar notmuch-jump--action nil)
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 1bdfc2b9..3add992b 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -192,8 +192,8 @@ (defun notmuch-command-to-string (&rest args)
 
 Otherwise the output will be returned."
   (with-temp-buffer
-    (let* ((status (apply #'call-process notmuch-command nil t nil args))
-	   (output (buffer-string)))
+    (let ((status (apply #'call-process notmuch-command nil t nil args))
+	  (output (buffer-string)))
       (notmuch-check-exit-status status (cons notmuch-command args) output)
       output)))
 
@@ -248,7 +248,8 @@ (defun notmuch-config-get (item)
 	 (len (length val)))
     ;; Trim off the trailing newline (if the value is empty or not
     ;; configured, there will be no newline)
-    (if (and (> len 0) (= (aref val (- len 1)) ?\n))
+    (if (and (> len 0)
+	     (= (aref val (- len 1)) ?\n))
 	(substring val 0 -1)
       val)))
 
@@ -538,13 +539,12 @@ (defun notmuch-common-do-stash (text)
 ;;; Generic Utilities
 
 (defun notmuch-plist-delete (plist property)
-  (let* ((xplist (cons nil plist))
-	 (pred xplist))
-    (while (cdr pred)
-      (when (eq (cadr pred) property)
-	(setcdr pred (cdddr pred)))
-      (setq pred (cddr pred)))
-    (cdr xplist)))
+  (let (p)
+    (while plist
+      (unless (eq property (car plist))
+	(setq p (plist-put p (car plist) (cadr plist))))
+      (setq plist (cddr plist)))
+    p))
 
 ;;; MML Utilities
 
@@ -555,8 +555,10 @@ (defun notmuch-match-content-type (t1 t2)
     (if (or (string= (cadr st1) "*")
 	    (string= (cadr st2) "*"))
 	;; Comparison of content types should be case insensitive.
-	(string= (downcase (car st1)) (downcase (car st2)))
-      (string= (downcase t1) (downcase t2)))))
+	(string= (downcase (car st1))
+		 (downcase (car st2)))
+      (string= (downcase t1)
+	       (downcase t2)))))
 
 (defvar notmuch-multipart/alternative-discouraged
   '(;; Avoid HTML parts.
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 9f09129d..b3c2570e 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -107,16 +107,13 @@ (defun notmuch-fcc-header-setup ()
 	   ;; Old style - no longer works.
 	   (error "Invalid `notmuch-fcc-dirs' setting (old style)"))
 	  ((listp notmuch-fcc-dirs)
-	   (let* ((from (message-field-value "From"))
-		  (match
-		   (catch 'first-match
-		     (dolist (re-folder notmuch-fcc-dirs)
-		       (when (string-match-p (car re-folder) from)
-			 (throw 'first-match re-folder))))))
-	     (if match
-		 (cdr match)
-	       (message "No Fcc header added.")
-	       nil)))
+	   (or (seq-some (let ((from (message-field-value "From")))
+			   (pcase-lambda (`(,regexp ,folder))
+			     (and (string-match-p regexp from)
+				  folder)))
+			 notmuch-fcc-dirs)
+	       (progn (message "No Fcc header added.")
+		      nil)))
 	  (t
 	   (error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))
     (when subdir
@@ -128,9 +125,9 @@ (defun notmuch-maildir-add-notmuch-insert-style-fcc-header (subdir)
   ;; Notmuch insert does not accept absolute paths, so check the user
   ;; really want this header inserted.
   (when (or (not (= (elt subdir 0) ?/))
-	    (y-or-n-p
-	     (format "Fcc header %s is an absolute path and notmuch insert is requested.
-Insert header anyway? " subdir)))
+	    (y-or-n-p (format "Fcc header %s is an absolute path %s %s" subdir
+			      "and notmuch insert is requested."
+			      "Insert header anyway? ")))
     (message-add-header (concat "Fcc: " subdir))))
 
 (defun notmuch-maildir-add-file-style-fcc-header (subdir)
@@ -173,7 +170,7 @@ (defun notmuch-maildir-message-do-fcc ()
   "Process Fcc headers in the current buffer.
 
 This is a rearranged version of message mode's message-do-fcc."
-  (let (list file)
+  (let (files file)
     (save-excursion
       (save-restriction
 	(message-narrow-to-headers)
@@ -183,13 +180,11 @@ (defun notmuch-maildir-message-do-fcc ()
 	 (save-restriction
 	   (message-narrow-to-headers)
 	   (while (setq file (message-fetch-field "fcc" t))
-	     (push file list)
+	     (push file files)
 	     (message-remove-header "fcc" nil t)))
 	 (notmuch-maildir-setup-message-for-saving)
 	 ;; Process FCC operations.
-	 (while list
-	   (setq file (pop list))
-	   (notmuch-fcc-handler file))
+	 (mapc #'notmuch-fcc-handler files)
 	 (kill-buffer (current-buffer)))))))
 
 (defun notmuch-fcc-handler (fcc-header)
@@ -201,7 +196,8 @@ (defun notmuch-fcc-handler (fcc-header)
   (message "Doing Fcc...")
   (if notmuch-maildir-use-notmuch-insert
       (notmuch-maildir-fcc-with-notmuch-insert fcc-header)
-    (notmuch-maildir-fcc-file-fcc fcc-header)))
+    (notmuch-maildir-fcc-file-fcc fcc-header))
+  (message "Doing Fcc...done"))
 
 ;;; Functions for saving a message using notmuch insert.
 
@@ -230,9 +226,8 @@ (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
 or surrounding the entire folder name in double quotes.
 
 If CREATE is non-nil then create the folder if necessary."
-  (let* ((args (split-string-and-unquote fcc-header))
-	 (folder (car args))
-	 (tags (cdr args)))
+  (pcase-let ((`(,folder . ,tags)
+	       (split-string-and-unquote fcc-header)))
     (condition-case nil
 	(notmuch-maildir-notmuch-insert-current-buffer folder create tags)
       ;; Since there are many reasons notmuch insert could fail, e.g.,
@@ -265,7 +260,7 @@ (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
   (let* ((ftime (float-time))
 	 (microseconds (mod (* 1000000 ftime) 1000000))
 	 (hostname (notmuch-maildir-fcc-host-fixer (system-name))))
-    (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
+    (cl-incf notmuch-maildir-fcc-count)
     (format "%d.%d_%d_%d.%s"
 	    ftime
 	    (emacs-pid)
@@ -298,9 +293,7 @@ (defun notmuch-maildir-fcc-save-buffer-to-tmp (destdir)
 	   (write-file (concat destdir "/tmp/" msg-id))
 	   msg-id)
 	  (t
-	   (error (format "Can't write to %s. Not a maildir."
-			  destdir))
-	   nil))))
+	   (error "Can't write to %s. Not a maildir." destdir)))))
 
 (defun notmuch-maildir-fcc-move-tmp-to-new (destdir msg-id)
   (add-name-to-file
@@ -345,16 +338,12 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
       (catch 'link-error
 	(let ((msg-id (notmuch-maildir-fcc-save-buffer-to-tmp destdir)))
 	  (when msg-id
-	    (cond (mark-seen
-		   (condition-case nil
-		       (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
-		     (file-already-exists
-		      (throw 'link-error nil))))
-		  (t
-		   (condition-case nil
-		       (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id)
-		     (file-already-exists
-		      (throw 'link-error nil))))))
+	    (condition-case nil
+		(if mark-seen
+		    (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
+		  (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id))
+	      (file-already-exists
+	       (throw 'link-error nil))))
 	  (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 74ffd8f2..4a08e8a7 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -179,13 +179,11 @@ (defun notmuch-mua-attachment-check ()
 
 (defun notmuch-mua-get-switch-function ()
   "Get a switch function according to `notmuch-mua-compose-in'."
-  (cond ((eq notmuch-mua-compose-in 'current-window)
-	 'switch-to-buffer)
-	((eq notmuch-mua-compose-in 'new-window)
-	 'switch-to-buffer-other-window)
-	((eq notmuch-mua-compose-in 'new-frame)
-	 'switch-to-buffer-other-frame)
-	(t (error "Invalid value for `notmuch-mua-compose-in'"))))
+  (pcase notmuch-mua-compose-in
+    ('current-window 'switch-to-buffer)
+    ('new-window     'switch-to-buffer-other-window)
+    ('new-frame      'switch-to-buffer-other-frame)
+    (_ (error "Invalid value for `notmuch-mua-compose-in'"))))
 
 (defun notmuch-mua-maybe-set-window-dedicated ()
   "Set the selected window as dedicated according to `notmuch-mua-compose-in'."
@@ -375,12 +373,10 @@ (defun notmuch-mua-pop-to-buffer (name switch-function)
 		(select-window window))
 	    (funcall switch-function buffer)
 	    (set-buffer buffer))
-	  (when (and (buffer-modified-p)
-		     (not (prog1
-			      (y-or-n-p
-			       "Message already being composed; erase? ")
-			    (message nil))))
-	    (error "Message being composed")))
+	  (when (buffer-modified-p)
+	    (if (y-or-n-p "Message already being composed; erase? ")
+		(message nil)
+	      (error "Message being composed"))))
       (funcall switch-function name)
       (set-buffer name))
     (erase-buffer)
@@ -611,8 +607,10 @@ (defun notmuch-mua-kill-buffer ()
 ;;; _
 
 (define-mail-user-agent 'notmuch-user-agent
-  'notmuch-mua-mail 'notmuch-mua-send-and-exit
-  'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
+  'notmuch-mua-mail
+  'notmuch-mua-send-and-exit
+  'notmuch-mua-kill-buffer
+  'notmuch-mua-send-hook)
 
 ;; Add some more headers to the list that `message-mode' hides when
 ;; composing a message.
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index ffce8814..d7349b77 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -41,11 +41,9 @@ (defun notmuch-query-get-threads (search-terms)
 
 (defun notmuch-query-map-aux  (mapper function seq)
   "Private function to do the actual mapping and flattening."
-  (apply 'append
-	 (mapcar
-	  (lambda (tree)
-	    (funcall mapper function tree))
-	  seq)))
+  (cl-mapcan (lambda (tree)
+	       (funcall mapper function tree))
+	     seq))
 
 (defun notmuch-query-map-threads (fn threads)
   "Apply function FN to every thread in THREADS.
@@ -63,7 +61,8 @@ (defun notmuch-query-map-tree (fn tree)
   "Apply function FN to every message in TREE.
 Flatten results to a list.  See the function
 `notmuch-query-get-threads' for more information."
-  (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
+  (cons (funcall fn (car tree))
+	(notmuch-query-map-forest fn (cadr tree))))
 
 ;;; Predefined queries
 
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index a553dfd9..0c9a32ac 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -454,8 +454,9 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((op (string-to-char tag-change))
-	    (tag (unless (string= tag-change "") (substring tag-change 1))))
+      (let ((op (aref tag-change 0))
+	    (tag (and (not (string= tag-change ""))
+		      (substring tag-change 1))))
 	(cl-case op
 	  (?+ (unless (member tag result-tags)
 		(push tag result-tags)))
@@ -482,13 +483,12 @@ (defun notmuch-tag (query tag-changes)
 directly, so that hooks specified in notmuch-before-tag-hook and
 notmuch-after-tag-hook will be run."
   ;; Perform some validation
-  (mapc (lambda (tag-change)
-	  (unless (string-match-p "^[-+]\\S-+$" tag-change)
-	    (error "Tag must be of the form `+this_tag' or `-that_tag'")))
-	tag-changes)
+  (dolist (tag-change tag-changes)
+    (unless (string-match-p "^[-+]\\S-+$" tag-change)
+      (error "Tag must be of the form `+this_tag' or `-that_tag'")))
   (unless query
     (error "Nothing to tag!"))
-  (unless (null tag-changes)
+  (when tag-changes
     (run-hooks 'notmuch-before-tag-hook)
     (if (<= (length query) notmuch-tag-argument-limit)
 	(apply 'notmuch-call-notmuch-process "tag"
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3928cd65..c4ee9e63 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -179,7 +179,7 @@ (defvar notmuch-search-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
     (define-key map "x" 'notmuch-bury-or-kill-this-buffer)
-    (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
+    (define-key map (kbd "DEL") 'notmuch-search-scroll-down)
     (define-key map "b" 'notmuch-search-scroll-down)
     (define-key map " " 'notmuch-search-scroll-up)
     (define-key map "<" 'notmuch-search-first-thread)
@@ -232,7 +232,7 @@ (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
-(defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")
+(defvar notmuch-search-disjunctive-regexp "\\<[oO][rR]\\>")
 
 ;;; Movement
 
@@ -950,40 +950,39 @@ (defun notmuch-read-query (prompt)
   "Read a notmuch-query from the minibuffer with completion.
 
 PROMPT is the string to prompt with."
-  (let*
-      ((all-tags
-	(mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
-		(process-lines notmuch-command "search" "--output=tags" "*")))
-       (completions
-	(append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
-		      "subject:" "attachment:")
-		(mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
-		(mapcar (lambda (tag) (concat "is:" tag)) all-tags)
-		(mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
-			(mailcap-mime-types)))))
-    (let ((keymap (copy-keymap minibuffer-local-map))
-	  (current-query (cl-case major-mode
-			   (notmuch-search-mode (notmuch-search-get-query))
-			   (notmuch-show-mode (notmuch-show-get-query))
-			   (notmuch-tree-mode (notmuch-tree-get-query))))
-	  (minibuffer-completion-table
-	   (completion-table-dynamic
-	    (lambda (string)
-	      ;; generate a list of possible completions for the current input
-	      (cond
-	       ;; this ugly regexp is used to get the last word of the input
-	       ;; possibly preceded by a '('
-	       ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
-		(mapcar (lambda (compl)
-			  (concat (match-string-no-properties 1 string) compl))
-			(all-completions (match-string-no-properties 2 string)
-					 completions)))
-	       (t (list string)))))))
-      ;; this was simpler than convincing completing-read to accept spaces:
-      (define-key keymap (kbd "TAB") 'minibuffer-complete)
-      (let ((history-delete-duplicates t))
-	(read-from-minibuffer prompt nil keymap nil
-			      'notmuch-search-history current-query nil)))))
+  (let* ((all-tags
+	  (mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
+		  (process-lines notmuch-command "search" "--output=tags" "*")))
+	 (completions
+	  (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
+			"subject:" "attachment:")
+		  (mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
+		  (mapcar (lambda (tag) (concat "is:" tag)) all-tags)
+		  (mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
+			  (mailcap-mime-types))))
+	 (keymap (copy-keymap minibuffer-local-map))
+	 (current-query (cl-case major-mode
+			  (notmuch-search-mode (notmuch-search-get-query))
+			  (notmuch-show-mode (notmuch-show-get-query))
+			  (notmuch-tree-mode (notmuch-tree-get-query))))
+	 (minibuffer-completion-table
+	  (completion-table-dynamic
+	   (lambda (string)
+	     ;; Generate a list of possible completions for the current input.
+	     (cond
+	      ;; This ugly regexp is used to get the last word of the input
+	      ;; possibly preceded by a '('.
+	      ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
+	       (mapcar (lambda (compl)
+			 (concat (match-string-no-properties 1 string) compl))
+		       (all-completions (match-string-no-properties 2 string)
+					completions)))
+	      (t (list string)))))))
+    ;; This was simpler than convincing completing-read to accept spaces:
+    (define-key keymap (kbd "TAB") 'minibuffer-complete)
+    (let ((history-delete-duplicates t))
+      (read-from-minibuffer prompt nil keymap nil
+			    'notmuch-search-history current-query nil))))
 
 (defun notmuch-search-get-query ()
   "Return the current query in this search buffer."
@@ -1042,12 +1041,12 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
 		     (if oldest-first
 			 "--sort=oldest-first"
 		       "--sort=newest-first")
-		     query))
-	      ;; Use a scratch buffer to accumulate partial output.
-	      ;; This buffer will be killed by the sentinel, which
-	      ;; should be called no matter how the process dies.
-	      (parse-buf (generate-new-buffer " *notmuch search parse*")))
-	  (process-put proc 'parse-buf parse-buf)
+		     query)))
+	  ;; Use a scratch buffer to accumulate partial output.
+	  ;; This buffer will be killed by the sentinel, which
+	  ;; should be called no matter how the process dies.
+	  (process-put proc 'parse-buf
+		       (generate-new-buffer " *notmuch search parse*"))
 	  (set-process-filter proc 'notmuch-search-process-filter)
 	  (set-process-query-on-exit-flag proc nil))))
     (run-hooks 'notmuch-search-hook)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 24/36] emacs: various comment improvements
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (22 preceding siblings ...)
  2021-01-10 14:00   ` [PATCH v2 23/36] emacs: various cosmetic improvements Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 25/36] emacs: various doc-string improvements Jonas Bernoulli
                     ` (13 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-address.el | 5 ++---
 emacs/notmuch-hello.el   | 4 +---
 emacs/notmuch-lib.el     | 6 +++---
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 2f0ec9b3..1f22e377 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -381,7 +381,7 @@ (defun notmuch-address--load-address-hash ()
 (defun notmuch-address--save-address-hash ()
   (when notmuch-address-save-filename
     (if (or (not (file-exists-p notmuch-address-save-filename))
-	    ;; The file exists, check it is a file we saved
+	    ;; The file exists, check it is a file we saved.
 	    (notmuch-address--get-address-hash))
 	(with-temp-file notmuch-address-save-filename
 	  (let ((save-plist
@@ -404,8 +404,7 @@ (defun notmuch-address-harvest-trigger ()
        nil nil
        (lambda (_proc event)
 	 ;; If harvest fails, we want to try
-	 ;; again when the trigger is next
-	 ;; called
+	 ;; again when the trigger is next called.
 	 (if (string= event "finished\n")
 	     (progn
 	       (notmuch-address--save-address-hash)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index ffd3d799..186ac172 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -731,9 +731,7 @@ (define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
 Complete list of currently available key bindings:
 
 \\{notmuch-hello-mode-map}"
-  (setq notmuch-buffer-refresh-function #'notmuch-hello-update)
-  ;;(setq buffer-read-only t)
-  )
+  (setq notmuch-buffer-refresh-function #'notmuch-hello-update))
 
 ;;; Inserters
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 3add992b..72549a98 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -247,7 +247,7 @@ (defun notmuch-config-get (item)
   (let* ((val (notmuch-command-to-string "config" "get" item))
 	 (len (length val)))
     ;; Trim off the trailing newline (if the value is empty or not
-    ;; configured, there will be no newline)
+    ;; configured, there will be no newline).
     (if (and (> len 0)
 	     (= (aref val (- len 1)) ?\n))
 	(substring val 0 -1)
@@ -483,8 +483,8 @@ (defun notmuch-refresh-all-buffers ()
 ;;; String Utilities
 
 (defun notmuch-prettify-subject (subject)
-  ;; This function is used by `notmuch-search-process-filter' which
-  ;; requires that we not disrupt its' matching state.
+  ;; This function is used by `notmuch-search-process-filter',
+  ;; which requires that we not disrupt its matching state.
   (save-match-data
     (if (and subject
 	     (string-match "^[ \t]*$" subject))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 25/36] emacs: various doc-string improvements
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (23 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 24/36] emacs: various comment improvements Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 26/36] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
                     ` (12 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-draft.el       | 12 ++++++-----
 emacs/notmuch-maildir-fcc.el | 21 +++++++++---------
 emacs/notmuch-mua.el         |  9 ++++----
 emacs/notmuch-tag.el         | 41 ++++++++++++++++++------------------
 emacs/notmuch-tree.el        | 10 ++++-----
 emacs/notmuch.el             | 24 ++++++++++-----------
 6 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 8af04598..bc688434 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -77,9 +77,11 @@ (defcustom notmuch-draft-quoted-tags '()
   :group 'notmuch-send)
 
 (defcustom notmuch-draft-save-plaintext 'ask
-  "Should notmuch save/postpone in plaintext messages that seem
-like they are intended to be sent encrypted
-(i.e with an mml encryption tag in it)."
+  "Whether to allow saving plaintext when it seems encryption is intended.
+When a message contains mml tags, then that suggest it is
+intended to be encrypted.  If the user requests that such a
+message is saved locally, then this option controls whether
+that is allowed.  Beside a boolean, this can also be `ask'."
   :type '(radio
 	  (const :tag "Never" nil)
 	  (const :tag "Ask every time" ask)
@@ -146,13 +148,13 @@ (defun notmuch-draft-unquote-some-mml ()
 	(insert secure-tag "\n")))))
 
 (defun notmuch-draft--has-encryption-tag ()
-  "Returns t if there is an mml secure tag."
+  "Return non-nil if there is an mml secure tag."
   (save-excursion
     (message-goto-body)
     (re-search-forward notmuch-draft-encryption-tag-regex nil t)))
 
 (defun notmuch-draft--query-encryption ()
-  "Checks if we should save a message that should be encrypted.
+  "Return non-nil if we should save a message that should be encrypted.
 
 `notmuch-draft-save-plaintext' controls the behaviour."
   (cl-case notmuch-draft-save-plaintext
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index b3c2570e..efbb37f1 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -90,10 +90,8 @@ (defcustom notmuch-maildir-use-notmuch-insert t
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
 
-Sets the Fcc header based on the values of `notmuch-fcc-dirs'.
-
-Originally intended to be use a hook function, but now called directly
-by notmuch-mua-mail."
+If the Fcc header is already set, then keep it as-is.
+Otherwise set it according to `notmuch-fcc-dirs'."
   (let ((subdir
 	 (cond
 	  ((or (not notmuch-fcc-dirs)
@@ -153,8 +151,9 @@ (defmacro with-temporary-notmuch-message-buffer (&rest body)
        ,@body)))
 
 (defun notmuch-maildir-setup-message-for-saving ()
-  "Setup message for saving. Should be called on a temporary copy.
+  "Setup message for saving.
 
+This should be called on a temporary copy.
 This is taken from the function message-do-fcc."
   (message-encode-message-body)
   (save-restriction
@@ -308,8 +307,8 @@ (defun notmuch-maildir-fcc-move-tmp-to-cur (destdir msg-id &optional mark-seen)
 (defun notmuch-maildir-fcc-file-fcc (fcc-header)
   "Write the message to the file specified by FCC-HEADER.
 
-It offers the user a chance to correct the header, or filesystem,
-if needed."
+If that fails, then offer the user a chance to correct the header
+or filesystem."
   (if (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)
       (notmuch-maildir-fcc-write-buffer-to-maildir fcc-header t)
     ;; The fcc-header is not a valid maildir see if the user wants to
@@ -329,9 +328,11 @@ (defun notmuch-maildir-fcc-file-fcc (fcc-header)
 	     (read-from-minibuffer "Fcc header: " fcc-header)))))))
 
 (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
-  "Writes the current buffer to maildir destdir. If mark-seen is
-non-nil, it will write it to cur/, and mark it as read. It should
-return t if successful, and nil otherwise."
+  "Write the current buffer to maildir destdir.
+
+If mark-seen is non-nil, then write it to \"cur/\", and mark it
+as read, otherwise write it to \"new/\". Return t if successful,
+and nil otherwise."
   (let ((orig-buffer (buffer-name)))
     (with-temp-buffer
       (insert-buffer-substring orig-buffer)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 4a08e8a7..2e4dc71a 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -99,7 +99,7 @@ (defcustom notmuch-always-prompt-for-sender nil
   :group 'notmuch-send)
 
 (defgroup notmuch-reply nil
-  "Replying to messages in notmuch"
+  "Replying to messages in notmuch."
   :group 'notmuch)
 
 (defcustom notmuch-mua-cite-function 'message-cite-original
@@ -144,9 +144,10 @@ (defcustom notmuch-mua-attachment-regexp
 ;;; Various functions
 
 (defun notmuch-mua-attachment-check ()
-  "Signal an error if the message text indicates that an
-attachment is expected but no MML referencing an attachment is
-found.
+  "Signal an error an attachement is expected but missing.
+
+Signal an error if the message text indicates that an attachment
+is expected but no MML referencing an attachment is found.
 
 Typically this is added to `notmuch-mua-send-hook'."
   (when (and
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 0c9a32ac..c006026c 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -141,20 +141,23 @@ (defcustom notmuch-tag-formats
      (notmuch-tag-format-image-data tag (notmuch-tag-star-icon))))
   "Custom formats for individual tags.
 
-This is an association list that maps from tag name regexps to
-lists of formatting expressions.  The first entry whose car
-regexp-matches a tag will be used to format that tag.  The regexp
-is implicitly anchored, so to match a literal tag name, just use
-that tag name (if it contains special regexp characters like
-\".\" or \"*\", these have to be escaped).  The cdr of the
-matching entry gives a list of Elisp expressions that modify the
-tag.  If the list is empty, the tag will simply be hidden.
-Otherwise, each expression will be evaluated in order: for the
-first expression, the variable `tag' will be bound to the tag
-name; for each later expression, the variable `tag' will be bound
-to the result of the previous expression.  In this way, each
+This is an association list of the form ((MATCH EXPR...)...),
+mapping tag name regexps to lists of formatting expressions.
+
+The first entry whose MATCH regexp-matches a tag is used to
+format that tag.  The regexp is implicitly anchored, so to match
+a literal tag name, just use that tag name (if it contains
+special regexp characters like \".\" or \"*\", these have to be
+escaped).
+
+The cdr of the matching entry gives a list of Elisp expressions
+that modify the tag.  If the list is empty, the tag is simply
+hidden.  Otherwise, each expression EXPR is evaluated in order:
+for the first expression, the variable `tag' is bound to the tag
+name; for each later expression, the variable `tag' is bound to
+the result of the previous expression.  In this way, each
 expression can build on the formatting performed by the previous
-expression.  The result of the last expression will displayed in
+expression.  The result of the last expression is displayed in
 place of the tag.
 
 For example, to replace a tag with another string, simply use
@@ -384,17 +387,15 @@ (defcustom notmuch-after-tag-hook nil
 ;;; User Input
 
 (defvar notmuch-select-tag-history nil
-  "Variable to store minibuffer history for
-`notmuch-select-tag-with-completion' function.")
+  "Minibuffer history of `notmuch-select-tag-with-completion' function.")
 
 (defvar notmuch-read-tag-changes-history nil
-  "Variable to store minibuffer history for
-`notmuch-read-tag-changes' function.")
+  "Minibuffer history of `notmuch-read-tag-changes' function.")
 
 (defun notmuch-tag-completions (&rest search-terms)
   "Return a list of tags for messages matching SEARCH-TERMS.
 
-Returns all tags if no search terms are given."
+Return all tags if no search terms are given."
   (unless search-terms
     (setq search-terms (list "*")))
   (split-string
@@ -411,8 +412,8 @@ (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
 (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
   "Prompt for tag changes in the minibuffer.
 
-CURRENT-TAGS is a list of tags that are present on the message or
-messages to be changed.  These are offered as tag removal
+CURRENT-TAGS is a list of tags that are present on the message
+or messages to be changed.  These are offered as tag removal
 completions.  CURRENT-TAGS may contain duplicates.  PROMPT, if
 non-nil, is the query string to present in the minibuffer.  It
 defaults to \"Tags\".  INITIAL-INPUT, if non-nil, will be the
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index e254593f..a06afc2d 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -791,8 +791,7 @@ (defun notmuch-tree-next-thread-from-search (&optional previous)
       (notmuch-tree-from-search-thread))))
 
 (defun notmuch-tree-next-thread (&optional previous)
-  "Move to the next thread in the current tree or parent search
-results
+  "Move to the next thread in the current tree or parent search results.
 
 If PREVIOUS is non-nil, move to the previous thread in the tree or
 search results instead."
@@ -802,14 +801,13 @@ (defun notmuch-tree-next-thread (&optional previous)
     (notmuch-tree-next-thread-from-search previous)))
 
 (defun notmuch-tree-prev-thread ()
-  "Move to the previous thread in the current tree or parent search
-results"
+  "Move to the previous thread in the current tree or parent search results."
   (interactive)
   (notmuch-tree-next-thread t))
 
 (defun notmuch-tree-thread-mapcar (function)
-  "Iterate through all messages in the current thread
- and call FUNCTION for side effects."
+  "Call FUNCTION for each message in the current thread.
+FUNCTION is called for side effects only."
   (save-excursion
     (notmuch-tree-thread-top)
     (cl-loop collect (funcall function)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index c4ee9e63..f8c97c5d 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -494,7 +494,7 @@ (defun notmuch-search-find-thread-id (&optional bare)
 (defun notmuch-search-find-stable-query ()
   "Return the stable queries for the current thread.
 
-This returns a list (MATCHED-QUERY UNMATCHED-QUERY) for the
+Return a list (MATCHED-QUERY UNMATCHED-QUERY) for the
 matched and unmatched messages in the current thread."
   (plist-get (notmuch-search-get-result) :query))
 
@@ -599,7 +599,7 @@ (defun notmuch-search-get-tags-region (beg end)
 (defun notmuch-search-interactive-tag-changes (&optional initial-input)
   "Prompt for tag changes for the current thread or region.
 
-Returns (TAG-CHANGES REGION-BEGIN REGION-END)."
+Return (TAG-CHANGES REGION-BEGIN REGION-END)."
   (pcase-let ((`(,beg ,end) (notmuch-interactive-region)))
     (list (notmuch-read-tag-changes (notmuch-search-get-tags-region beg end)
 				    (if (= beg end) "Tag thread" "Tag region")
@@ -1101,10 +1101,10 @@ (defun notmuch-search-filter (query)
 		    notmuch-search-oldest-first)))
 
 (defun notmuch-search-filter-by-tag (tag)
-  "Filter the current search results based on a single tag.
+  "Filter the current search results based on a single TAG.
 
-Runs a new search matching only messages that match both the
-current search results AND that are tagged with the given tag."
+Run a new search matching only messages that match the current
+search results and that are also tagged with the given TAG."
   (interactive
    (list (notmuch-select-tag-with-completion "Filter by tag: "
 					     notmuch-search-query-string)))
@@ -1124,7 +1124,7 @@ (defun notmuch ()
   (notmuch-hello))
 
 (defun notmuch-interesting-buffer (b)
-  "Is the current buffer of interest to a notmuch user?"
+  "Whether the current buffer's major-mode is a notmuch mode."
   (with-current-buffer b
     (memq major-mode '(notmuch-show-mode
 		       notmuch-search-mode
@@ -1136,8 +1136,8 @@ (defun notmuch-interesting-buffer (b)
 (defun notmuch-cycle-notmuch-buffers ()
   "Cycle through any existing notmuch buffers (search, show or hello).
 
-If the current buffer is the only notmuch buffer, bury it. If no
-notmuch buffers exist, run `notmuch'."
+If the current buffer is the only notmuch buffer, bury it.
+If no notmuch buffers exist, run `notmuch'."
   (interactive)
   (let (start first)
     ;; If the current buffer is a notmuch buffer, remember it and then
@@ -1162,15 +1162,13 @@ (defun notmuch-cycle-notmuch-buffers ()
 
 (defun notmuch-search-imenu-prev-index-position-function ()
   "Move point to previous message in notmuch-search buffer.
-This function is used as a value for
-`imenu-prev-index-position-function'."
+Used as`imenu-prev-index-position-function' in notmuch buffers."
   (notmuch-search-previous-thread))
 
 (defun notmuch-search-imenu-extract-index-name-function ()
   "Return imenu name for line at point.
-This function is used as a value for
-`imenu-extract-index-name-function'.  Point should be at the
-beginning of the line."
+Used as `imenu-extract-index-name-function' in notmuch buffers.
+Point should be at the beginning of the line."
   (let ((subject (notmuch-search-find-subject))
 	(author (notmuch-search-find-authors)))
     (format "%s (%s)" subject author)))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 26/36] emacs: remove variable notmuch-search-disjunctive-regexp
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (24 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 25/36] emacs: various doc-string improvements Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 27/36] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
                     ` (11 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch.el | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index f8c97c5d..ccece811 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -232,8 +232,6 @@ (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
-(defvar notmuch-search-disjunctive-regexp "\\<[oO][rR]\\>")
-
 ;;; Movement
 
 (defun notmuch-search-scroll-up ()
@@ -1079,10 +1077,8 @@ (defun notmuch-search-toggle-order ()
 
 (defun notmuch-group-disjunctive-query-string (query-string)
   "Group query if it contains a complex expression.
-
-Enclose QUERY-STRING in parentheses if it matches
-`notmuch-search-disjunctive-regexp'."
-  (if (string-match-p notmuch-search-disjunctive-regexp query-string)
+Enclose QUERY-STRING in parentheses if contains \"OR\" operators."
+  (if (string-match-p "\\<[oO][rR]\\>" query-string)
       (concat "( " query-string " )")
     query-string))
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 27/36] emacs: define a few variables as automatically buffer-local
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (25 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 26/36] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 28/36] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
                     ` (10 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-lib.el |  1 +
 emacs/notmuch.el     | 16 ++++++----------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 72549a98..2fd9a27d 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -101,6 +101,7 @@ (defcustom notmuch-search-oldest-first t
 search."
   :type 'boolean
   :group 'notmuch-search)
+(make-variable-buffer-local 'notmuch-search-oldest-first)
 
 (defcustom notmuch-poll-script nil
   "[Deprecated] Command to run to incorporate new mail into the notmuch database.
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index ccece811..027c5cfa 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -205,6 +205,12 @@ (defvar notmuch-search-mode-map
     map)
   "Keymap for \"notmuch search\" buffers.")
 
+;;; Internal Variables
+
+(defvar-local notmuch-search-query-string nil)
+(defvar-local notmuch-search-target-thread nil)
+(defvar-local notmuch-search-target-line nil)
+
 ;;; Stashing
 
 (defvar notmuch-search-stash-map
@@ -226,12 +232,6 @@ (defun notmuch-stash-query ()
   (interactive)
   (notmuch-common-do-stash (notmuch-search-get-query)))
 
-;;; Variables
-
-(defvar notmuch-search-query-string)
-(defvar notmuch-search-target-thread)
-(defvar notmuch-search-target-line)
-
 ;;; Movement
 
 (defun notmuch-search-scroll-up ()
@@ -404,10 +404,6 @@ (define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
 Complete list of currently available key bindings:
 
 \\{notmuch-search-mode-map}"
-  (make-local-variable 'notmuch-search-query-string)
-  (make-local-variable 'notmuch-search-oldest-first)
-  (make-local-variable 'notmuch-search-target-thread)
-  (make-local-variable 'notmuch-search-target-line)
   (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
   (setq-local scroll-preserve-screen-position t)
   (add-to-invisibility-spec (cons 'ellipsis t))
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 28/36] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (26 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 27/36] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 29/36] emacs: reorder notmuch.el a bit Jonas Bernoulli
                     ` (9 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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: f47eeac0b0186c3559eb559c4f0bee0e1fac1961
   emacs: set default in notmuch-read-query
---
 emacs/notmuch.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 027c5cfa..481a0e0a 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -230,7 +230,7 @@ (defun notmuch-search-stash-thread-id ()
 (defun notmuch-stash-query ()
   "Copy current query to kill-ring."
   (interactive)
-  (notmuch-common-do-stash (notmuch-search-get-query)))
+  (notmuch-common-do-stash notmuch-search-query-string))
 
 ;;; Movement
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 29/36] emacs: reorder notmuch.el a bit
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (27 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 28/36] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 30/36] emacs: avoid unnecessary let-bindings Jonas Bernoulli
                     ` (8 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch.el | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 481a0e0a..40b730df 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -70,6 +70,8 @@ (eval-when-compile (require 'cl-lib))
 (require 'mm-view)
 (require 'message)
 
+(require 'hl-line)
+
 (require 'notmuch-lib)
 (require 'notmuch-tag)
 (require 'notmuch-show)
@@ -114,8 +116,12 @@ (defcustom notmuch-init-file (locate-user-emacs-file "notmuch-config")
   :type 'file
   :group 'notmuch)
 
-(defvar notmuch-query-history nil
-  "Variable to store minibuffer history for notmuch queries.")
+(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
+  "List of functions to call when notmuch displays the search results."
+  :type 'hook
+  :options '(notmuch-hl-line-mode)
+  :group 'notmuch-search
+  :group 'notmuch-hooks)
 
 ;;; Mime Utilities
 
@@ -155,24 +161,6 @@ (defun notmuch-save-attachments (mm-handle &optional queryp)
 	    (mm-save-part p))))
    mm-handle))
 
-;;; Integrations
-
-(require 'hl-line)
-
-(defun notmuch-hl-line-mode ()
-  (prog1 (hl-line-mode)
-    (when hl-line-overlay
-      (overlay-put hl-line-overlay 'priority 1))))
-
-;;; Options
-
-(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
-  "List of functions to call when notmuch displays the search results."
-  :type 'hook
-  :options '(notmuch-hl-line-mode)
-  :group 'notmuch-search
-  :group 'notmuch-hooks)
-
 ;;; Keymap
 
 (defvar notmuch-search-mode-map
@@ -207,6 +195,9 @@ (defvar notmuch-search-mode-map
 
 ;;; Internal Variables
 
+(defvar notmuch-query-history nil
+  "Variable to store minibuffer history for notmuch queries.")
+
 (defvar-local notmuch-search-query-string nil)
 (defvar-local notmuch-search-target-thread nil)
 (defvar-local notmuch-search-target-line nil)
@@ -1150,7 +1141,15 @@ (defun notmuch-cycle-notmuch-buffers ()
 	  (pop-to-buffer-same-window first))
       (notmuch))))
 
-;;; Imenu Support
+;;; Integrations
+;;;; Hl-line Support
+
+(defun notmuch-hl-line-mode ()
+  (prog1 (hl-line-mode)
+    (when hl-line-overlay
+      (overlay-put hl-line-overlay 'priority 1))))
+
+;;;; Imenu Support
 
 (defun notmuch-search-imenu-prev-index-position-function ()
   "Move point to previous message in notmuch-search buffer.
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 30/36] emacs: avoid unnecessary let-bindings
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (28 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 29/36] emacs: reorder notmuch.el a bit Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 31/36] emacs: improve how cl-lib and pcase are required Jonas Bernoulli
                     ` (7 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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)?
---
 emacs/notmuch-address.el     |  4 +--
 emacs/notmuch-lib.el         |  6 ++---
 emacs/notmuch-maildir-fcc.el | 10 ++++----
 emacs/notmuch-show.el        | 14 +++++-----
 emacs/notmuch-tag.el         | 10 ++++----
 emacs/notmuch-tree.el        |  5 ++--
 emacs/notmuch.el             | 50 +++++++++++++++++-------------------
 7 files changed, 48 insertions(+), 51 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1f22e377..f313c415 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -260,8 +260,8 @@ (defun notmuch-address-expand-name ()
 ;;; Harvest
 
 (defun notmuch-address-harvest-addr (result)
-  (let ((name-addr (plist-get result :name-addr)))
-    (puthash name-addr t notmuch-address-completions)))
+  (puthash (plist-get result :name-addr)
+	   t notmuch-address-completions))
 
 (defun notmuch-address-harvest-filter (proc string)
   (when (buffer-live-p (process-buffer proc))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2fd9a27d..cbac8859 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -416,9 +416,9 @@ (defun notmuch-help ()
 its prefixed behavior by setting the 'notmuch-prefix-doc property
 of its command symbol."
   (interactive)
-  (let* ((mode major-mode)
-	 (doc (substitute-command-keys
-	       (notmuch-substitute-command-keys (documentation mode t)))))
+  (let ((doc (substitute-command-keys
+	      (notmuch-substitute-command-keys
+	       (documentation major-mode t)))))
     (with-current-buffer (generate-new-buffer "*notmuch-help*")
       (insert doc)
       (goto-char (point-min))
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index efbb37f1..63e5514c 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -207,11 +207,11 @@ (defun notmuch-maildir-notmuch-insert-current-buffer (folder &optional create ta
 database in folder FOLDER. If CREATE is non-nil it will supply
 the --create-folder flag to create the folder if necessary. TAGS
 should be a list of tag changes to apply to the inserted message."
-  (let* ((args (append (and create (list "--create-folder"))
-		       (list (concat "--folder=" folder))
-		       tags)))
-    (apply 'notmuch-call-notmuch-process
-	   :stdin-string (buffer-string) "insert" args)))
+  (apply 'notmuch-call-notmuch-process
+	 :stdin-string (buffer-string) "insert"
+	 (append (and create (list "--create-folder"))
+		 (list (concat "--folder=" folder))
+		 tags)))
 
 (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
   "Store message with notmuch insert.
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 48374b38..27925669 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1666,13 +1666,13 @@ (defun notmuch-show-get-prop (prop &optional props)
 message in either tree or show. This means that several utility
 functions in notmuch-show can be used directly by notmuch-tree as
 they just need the correct message properties."
-  (let ((props (or props
-		   (cond ((eq major-mode 'notmuch-show-mode)
-			  (notmuch-show-get-message-properties))
-			 ((eq major-mode 'notmuch-tree-mode)
-			  (notmuch-tree-get-message-properties))
-			 (t nil)))))
-    (plist-get props prop)))
+  (plist-get (or props
+		 (cond ((eq major-mode 'notmuch-show-mode)
+			(notmuch-show-get-message-properties))
+		       ((eq major-mode 'notmuch-tree-mode)
+			(notmuch-tree-get-message-properties))
+		       (t nil)))
+	     prop))
 
 (defun notmuch-show-get-message-id (&optional bare)
   "Return an id: query for the Message-Id of the current message.
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index c006026c..3c958dd4 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -406,8 +406,9 @@ (defun notmuch-tag-completions (&rest search-terms)
    "\n+" t))
 
 (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
-  (let ((tag-list (apply #'notmuch-tag-completions search-terms)))
-    (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
+  (completing-read prompt
+		   (apply #'notmuch-tag-completions search-terms)
+		   nil nil nil 'notmuch-select-tag-history))
 
 (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
   "Prompt for tag changes in the minibuffer.
@@ -455,10 +456,9 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((op (aref tag-change 0))
-	    (tag (and (not (string= tag-change ""))
+      (let ((tag (and (not (string= tag-change ""))
 		      (substring tag-change 1))))
-	(cl-case op
+	(cl-case (aref tag-change 0)
 	  (?+ (unless (member tag result-tags)
 		(push tag result-tags)))
 	  (?- (setq result-tags (delete tag result-tags)))
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index a06afc2d..51a43edd 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -401,9 +401,8 @@ (defun notmuch-tree-set-prop (prop val &optional props)
     (notmuch-tree-set-message-properties props)))
 
 (defun notmuch-tree-get-prop (prop &optional props)
-  (let ((props (or props
-		   (notmuch-tree-get-message-properties))))
-    (plist-get props prop)))
+  (plist-get (or props (notmuch-tree-get-message-properties))
+	     prop))
 
 (defun notmuch-tree-set-tags (tags)
   "Set the tags of the current message."
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 40b730df..3436e1fc 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -521,17 +521,16 @@ (defun notmuch-search-show-thread (&optional elide-toggle)
 `notmuch-show-only-matching-messages' when displaying the
 thread."
   (interactive "P")
-  (let ((thread-id (notmuch-search-find-thread-id))
-	(subject (notmuch-search-find-subject)))
-    (if (> (length thread-id) 0)
+  (let ((thread-id (notmuch-search-find-thread-id)))
+    (if thread-id
 	(notmuch-show thread-id
 		      elide-toggle
 		      (current-buffer)
 		      notmuch-search-query-string
 		      ;; Name the buffer based on the subject.
-		      (concat "*"
-			      (truncate-string-to-width subject 30 nil nil t)
-			      "*"))
+		      (format "*%s*" (truncate-string-to-width
+				      (notmuch-search-find-subject)
+				      30 nil nil t)))
       (message "End of search results."))))
 
 (defun notmuch-tree-from-search-current-query ()
@@ -556,20 +555,21 @@ (defun notmuch-tree-from-search-thread ()
 (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
   "Begin composing a reply-all to the entire current thread in a new buffer."
   (interactive "P")
-  (let ((message-id (notmuch-search-find-thread-id)))
-    (notmuch-mua-new-reply message-id prompt-for-sender t)))
+  (notmuch-mua-new-reply (notmuch-search-find-thread-id)
+			 prompt-for-sender t))
 
 (defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
   "Begin composing a reply to the entire current thread in a new buffer."
   (interactive "P")
-  (let ((message-id (notmuch-search-find-thread-id)))
-    (notmuch-mua-new-reply message-id prompt-for-sender nil)))
+  (notmuch-mua-new-reply (notmuch-search-find-thread-id)
+			 prompt-for-sender nil))
 
 ;;; Tags
 
 (defun notmuch-search-set-tags (tags &optional pos)
-  (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))
-    (notmuch-search-update-result new-result pos)))
+  (notmuch-search-update-result
+   (plist-put (notmuch-search-get-result pos) :tags tags)
+   pos))
 
 (defun notmuch-search-get-tags (&optional pos)
   (plist-get (notmuch-search-get-result pos) :tags))
@@ -1013,10 +1013,9 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
     (setq notmuch-search-target-thread target-thread)
     (setq notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
-    (let ((proc (get-buffer-process (current-buffer)))
-	  (inhibit-read-only t))
-      (when proc
-	(error "notmuch search process already running for query `%s'" query))
+    (when (get-buffer-process buffer)
+      (error "notmuch search process already running for query `%s'" query))
+    (let ((inhibit-read-only t))
       (erase-buffer)
       (goto-char (point-min))
       (save-excursion
@@ -1045,13 +1044,12 @@ (defun notmuch-search-refresh-view ()
 thread. Otherwise, point will be moved to attempt to be in the
 same relative position within the new buffer."
   (interactive)
-  (let ((target-line (line-number-at-pos))
-	(oldest-first notmuch-search-oldest-first)
-	(target-thread (notmuch-search-find-thread-id 'bare))
-	(query notmuch-search-query-string))
-    ;; notmuch-search erases the current buffer.
-    (notmuch-search query oldest-first target-thread target-line t)
-    (goto-char (point-min))))
+  (notmuch-search notmuch-search-query-string
+		  notmuch-search-oldest-first
+		  (notmuch-search-find-thread-id 'bare)
+		  (line-number-at-pos)
+		  t)
+  (goto-char (point-min)))
 
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
@@ -1160,9 +1158,9 @@ (defun notmuch-search-imenu-extract-index-name-function ()
   "Return imenu name for line at point.
 Used as `imenu-extract-index-name-function' in notmuch buffers.
 Point should be at the beginning of the line."
-  (let ((subject (notmuch-search-find-subject))
-	(author (notmuch-search-find-authors)))
-    (format "%s (%s)" subject author)))
+  (format "%s (%s)"
+	  (notmuch-search-find-subject)
+	  (notmuch-search-find-authors)))
 
 ;;; _
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 31/36] emacs: improve how cl-lib and pcase are required
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (29 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 30/36] emacs: avoid unnecessary let-bindings Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 32/36] emacs: make subr-x available in all libraries Jonas Bernoulli
                     ` (6 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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.)
---
 emacs/notmuch-address.el     | 2 --
 emacs/notmuch-company.el     | 2 --
 emacs/notmuch-draft.el       | 3 +++
 emacs/notmuch-hello.el       | 1 -
 emacs/notmuch-jump.el        | 4 ----
 emacs/notmuch-lib.el         | 1 +
 emacs/notmuch-maildir-fcc.el | 2 --
 emacs/notmuch-message.el     | 3 +++
 emacs/notmuch-mua.el         | 2 --
 emacs/notmuch-parser.el      | 3 ++-
 emacs/notmuch-show.el        | 4 ----
 emacs/notmuch-tag.el         | 4 ----
 emacs/notmuch-tree.el        | 2 --
 emacs/notmuch.el             | 2 --
 14 files changed, 9 insertions(+), 26 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index f313c415..ca24c744 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -21,8 +21,6 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
-
 (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index 4439cc15..c6a004ae 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -32,8 +32,6 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
-
 (require 'notmuch-lib)
 
 (defvar-local notmuch-company-last-prefix nil)
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index bc688434..2939da55 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -25,6 +25,9 @@
 
 ;;; Code:
 
+(require 'cl-lib)
+(require 'pcase)
+
 (require 'notmuch-maildir-fcc)
 (require 'notmuch-tag)
 
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 186ac172..24d2d19e 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -21,7 +21,6 @@
 
 ;;; Code:
 
-(require 'cl-lib)
 (require 'widget)
 (require 'wid-edit) ; For `widget-forward'.
 
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 34d6c796..6fab5a79 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -22,10 +22,6 @@
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'cl-lib)
-  (require 'pcase))
-
 (require 'notmuch-lib)
 (require 'notmuch-hello)
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index cbac8859..6130309a 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'pcase)
 
 (require 'mm-util)
 (require 'mm-view)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 63e5514c..374765b7 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -21,8 +21,6 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
-
 (require 'message)
 
 (require 'notmuch-lib)
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index abeff53a..b90c934a 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -21,6 +21,9 @@
 
 ;;; Code:
 
+(require 'cl-lib)
+(require 'pcase)
+
 (require 'message)
 (require 'notmuch-tag)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 2e4dc71a..c5b1b482 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -21,8 +21,6 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
-
 (require 'message)
 (require 'mm-view)
 (require 'format-spec)
diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index 294e0544..9749a6be 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -21,7 +21,8 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
+(require 'cl-lib)
+(require 'pcase)
 
 (defun notmuch-sexp-create-parser ()
   "Return a new streaming S-expression parser.
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 27925669..ea4444e5 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -23,10 +23,6 @@
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'cl-lib)
-  (require 'pcase))
-
 (require 'mm-view)
 (require 'message)
 (require 'mm-decode)
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 3c958dd4..982b372c 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -23,10 +23,6 @@
 
 ;;; Code:
 
-(require 'cl-lib)
-(eval-when-compile
-  (require 'pcase))
-
 (require 'crm)
 
 (require 'notmuch-lib)
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 51a43edd..95d5f642 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -24,8 +24,6 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
-
 (require 'mail-parse)
 
 (require 'notmuch-lib)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3436e1fc..d2e87b1b 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -65,8 +65,6 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl-lib))
-
 (require 'mm-view)
 (require 'message)
 
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 32/36] emacs: make subr-x available in all libraries
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (30 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 31/36] emacs: improve how cl-lib and pcase are required Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 33/36] emacs: use string-empty-p Jonas Bernoulli
                     ` (5 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-draft.el   | 1 +
 emacs/notmuch-lib.el     | 1 +
 emacs/notmuch-message.el | 1 +
 emacs/notmuch-parser.el  | 1 +
 4 files changed, 4 insertions(+)

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 2939da55..a68b7d8d 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -27,6 +27,7 @@
 
 (require 'cl-lib)
 (require 'pcase)
+(require 'subr-x)
 
 (require 'notmuch-maildir-fcc)
 (require 'notmuch-tag)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 6130309a..05d3be10 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -23,6 +23,7 @@
 
 (require 'cl-lib)
 (require 'pcase)
+(require 'subr-x)
 
 (require 'mm-util)
 (require 'mm-view)
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index b90c934a..0856a2e9 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -23,6 +23,7 @@
 
 (require 'cl-lib)
 (require 'pcase)
+(require 'subr-x)
 
 (require 'message)
 (require 'notmuch-tag)
diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index 9749a6be..f04b07c2 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -23,6 +23,7 @@
 
 (require 'cl-lib)
 (require 'pcase)
+(require 'subr-x)
 
 (defun notmuch-sexp-create-parser ()
   "Return a new streaming S-expression parser.
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 33/36] emacs: use string-empty-p
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (31 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 32/36] emacs: make subr-x available in all libraries Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 34/36] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
                     ` (4 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-lib.el  | 2 +-
 emacs/notmuch-mua.el  | 2 +-
 emacs/notmuch-show.el | 4 ++--
 emacs/notmuch-tag.el  | 2 +-
 emacs/notmuch.el      | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 05d3be10..bc550dc2 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -285,7 +285,7 @@ (defun notmuch-poll ()
   (interactive)
   (message "Polling mail...")
   (if (stringp notmuch-poll-script)
-      (unless (string= notmuch-poll-script "")
+      (unless (string-empty-p notmuch-poll-script)
 	(unless (equal (call-process notmuch-poll-script nil nil) 0)
 	  (error "Notmuch: poll script `%s' failed!" notmuch-poll-script)))
     (notmuch-call-notmuch-process "new"))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index c5b1b482..08c73c16 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -388,7 +388,7 @@ (defun notmuch-mua-mail (&optional to subject other-headers _continue
   (interactive)
   (when notmuch-mua-user-agent-function
     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
-      (unless (string= "" user-agent)
+      (unless (string-empty-p user-agent)
 	(push (cons 'User-Agent user-agent) other-headers))))
   (unless (assq 'From other-headers)
     (push (cons 'From (message-make-from
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index ea4444e5..fdf4ab3c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -333,7 +333,7 @@ (defun notmuch-show-with-message-as-text (fn)
 	 (header (concat
 		  "Subject: " subject "\n"
 		  "To: " to "\n"
-		  (if (not (string= cc ""))
+		  (if (not (string-empty-p cc))
 		      (concat "Cc: " cc "\n")
 		    "")
 		  "From: " from "\n"
@@ -1790,7 +1790,7 @@ (defun notmuch-show-filter-thread (query)
 Reshows the current thread with matches defined by the new query-string."
   (interactive (list (notmuch-read-query "Filter thread: ")))
   (let ((msg-id (notmuch-show-get-message-id)))
-    (setq notmuch-show-query-context (if (string= query "") nil query))
+    (setq notmuch-show-query-context (if (string-empty-p query) nil query))
     (notmuch-show-refresh-view t)
     (notmuch-show-goto-message msg-id)))
 
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 982b372c..f348d4ae 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -452,7 +452,7 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((tag (and (not (string= tag-change ""))
+      (let ((tag (and (not (string-empty-p tag-change))
 		      (substring tag-change 1))))
 	(cl-case (aref tag-change 0)
 	  (?+ (unless (member tag result-tags)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index d2e87b1b..26efcccd 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -814,13 +814,13 @@ (defun notmuch-search-insert-authors (format-string authors)
 	(setq invisible-string (notmuch-search-author-propertize invisible-string)))
       ;; If there is any invisible text, add it as a tooltip to the
       ;; visible text.
-      (unless (string= invisible-string "")
+      (unless (string-empty-p invisible-string)
 	(setq visible-string
 	      (propertize visible-string
 			  'help-echo (concat "..." invisible-string))))
       ;; Insert the visible and, if present, invisible author strings.
       (insert visible-string)
-      (unless (string= invisible-string "")
+      (unless (string-empty-p invisible-string)
 	(let ((start (point))
 	      overlay)
 	  (insert invisible-string)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 34/36] emacs: notmuch-tree-get-match: No longer define as command
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (32 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 33/36] emacs: use string-empty-p Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 35/36] emacs: allow opting out of notmuch's address completion Jonas Bernoulli
                     ` (3 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-tree.el | 1 -
 1 file changed, 1 deletion(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 95d5f642..13007a13 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -421,7 +421,6 @@ (defun notmuch-tree-get-message-id (&optional bare)
 
 (defun notmuch-tree-get-match ()
   "Return whether the current message is a match."
-  (interactive)
   (notmuch-tree-get-prop :match))
 
 ;;; Update display
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 35/36] emacs: allow opting out of notmuch's address completion
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (33 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 34/36] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-10 14:01   ` [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input Jonas Bernoulli
                     ` (2 subsequent siblings)
  37 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-address.el | 48 +++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index ca24c744..6e136473 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -54,21 +54,28 @@ (defun notmuch-address--harvest-ready ()
 (defcustom notmuch-address-command 'internal
   "Determines how address completion candidates are generated.
 
-If it is a string then that string should be an external program
-which must take a single argument (searched string) and output a
-list of completion candidates, one per line.
-
-Alternatively, it can be the symbol `internal', in which case
-internal completion is used; the variable
-`notmuch-address-internal-completion' can be used to customize
-this case.
-
-Finally, if this variable is nil then address completion is
-disabled."
+If this is a string, then that string should be an external
+program, which must take a single argument (searched string)
+and output a list of completion candidates, one per line.
+
+If this is the symbol `internal', then an implementation is used
+that relies on the \"notmuch address\" command, but does not use
+any third-party (i.e. \"external\") programs.
+
+If this is the symbol `as-is', then Notmuch does not modify the
+value of `message-completion-alist'. This option has to be set to
+this value before `notmuch' is loaded, otherwise the modification
+to `message-completion-alist' may already have taken place. This
+setting obviously does not prevent `message-completion-alist'
+from being modified at all; the user or some third-party package
+may still modify it.
+
+Finally, if this is nil, then address completion is disabled."
   :type '(radio
-	  (const :tag "Use internal address completion" internal)
-	  (const :tag "Disable address completion" nil)
-	  (string :tag "Use external completion command"))
+	  (const  :tag "Use internal address completion" internal)
+	  (string :tag "Use external completion command")
+	  (const  :tag "Disable address completion" nil)
+	  (const  :tag "Use default or third-party mechanism" as-is))
   :group 'notmuch-send
   :group 'notmuch-address
   :group 'notmuch-external)
@@ -160,12 +167,13 @@ (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (when (and notmuch-address-use-company
-	     (require 'company nil t))
-    (notmuch-company-setup))
-  (cl-pushnew (cons notmuch-address-completion-headers-regexp
-		    #'notmuch-address-expand-name)
-	      message-completion-alist :test #'equal))
+  (unless (eq notmuch-address-command 'as-is)
+    (when (and notmuch-address-use-company
+	       (require 'company nil t))
+      (notmuch-company-setup))
+    (cl-pushnew (cons notmuch-address-completion-headers-regexp
+		      #'notmuch-address-expand-name)
+		message-completion-alist :test #'equal)))
 
 (defun notmuch-address-toggle-internal-completion ()
   "Toggle use of internal completion for current buffer.
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (34 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 35/36] emacs: allow opting out of notmuch's address completion Jonas Bernoulli
@ 2021-01-10 14:01   ` Jonas Bernoulli
  2021-01-15 11:28     ` David Bremner
  2021-01-13  9:13   ` [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
  2021-01-13 12:11   ` David Bremner
  37 siblings, 1 reply; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-10 14:01 UTC (permalink / raw)
  To: notmuch

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".
---
 emacs/notmuch-address.el | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 6e136473..f0af6667 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -244,14 +244,8 @@ (defun notmuch-address-expand-name ()
 		    (t
 		     (funcall notmuch-address-selection-function
 			      (format "Address (%s matches): " num-options)
-			      ;; We put the first match as the initial
-			      ;; input; we put all the matches as
-			      ;; possible completions, moving the
-			      ;; first match to the end of the list
-			      ;; makes cursor up/down in the list work
-			      ;; better.
-			      (append (cdr options) (list (car options)))
-			      (car options))))))
+			      options
+			      orig)))))
       (if chosen
 	  (progn
 	    (push chosen notmuch-address-history)
-- 
2.29.1

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* Re: [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (35 preceding siblings ...)
  2021-01-10 14:01   ` [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input Jonas Bernoulli
@ 2021-01-13  9:13   ` Tomi Ollila
  2021-01-13 12:11   ` David Bremner
  37 siblings, 0 replies; 79+ messages in thread
From: Tomi Ollila @ 2021-01-13  9:13 UTC (permalink / raw)
  To: Jonas Bernoulli, notmuch

On Sun, Jan 10 2021, Jonas Bernoulli wrote:

> This fixes a minor whitespace bug that Tomi notices in (1).
>
> This also adds for commits, two of them in response to a concern
> raised by Tomi, who didn't "see enough point for requiring subr-x
> just [for string-empty-p]", which I agree with:
>
> 2) Changes how `cl-lib' and `pcase' are required.  I did that first
>    because I want to do it the same way as for `subr-x'.
>
> 3) Require `subr-x', so that we can use it without having to worry
>    whether we have now reached the threshold where it becomes
>    justified to require an additional library.
>
>    Personally I consider this library to be part of core elisp
>    libraries, and wish it were autoloaded like, say `subr'.  I am
>    not the only one with that opinion and some other package is
>    bound to load this very small library anyways, so we might as
>    well benefit from the goodies that it provides too.
>
> The remaining two new commits (4,5) I have already submitted earlier
> in a separate thread.  Unfortunately they did not get merged or even
> just discussed so far, so I am including them here again.

Series looks good (also patch 35/36 (*)). It was easy to review, although
took time to browse through all small changes. Marked ready using 
*-notmuch::needs-review in notmuch show buffer. 

I have been using the series for couple of days now (and sending this
email having the changes in use) -- it feels like this starts faster
than previously but that must be just a feeling.

Tomi

(*) I would even suggest "the best thing", but then it would need more
discussion...

>
>      Cheers,
>      Jonas
>
> Jonas Bernoulli (36):
>   emacs: use setq instead of set
>   emacs: sanitize dedicated widget action/notify functions
>   emacs: define new notmuch-search-item widget type
>   emacs: notmuch-start-notmuch: remove backward compatibility code
>   emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive
>   emacs: notmuch-start-notmuch-sentinel: assert buffer is alive
>   emacs: notmuch-start-notmuch: avoid storing process buffer twice
>   emacs: avoid passing around some redundant information
>   emacs: avoid killing process buffer when process is still alive
>   emacs: make headings outline-minor-mode compatible
>   emacs: use lexical-bindings in all libraries
>   emacs: deal with unused lexical arguments and variables
>   emacs: notmuch-tag--get-formats: silence byte-compiler
>   emacs: inline notmuch-sexp-eof into only caller
>   emacs: notmuch-wash-region-to-button: remove unused MSG argument
>   emacs: silence compiler wrt notmuch-show-insert-part-text/plain
>   emacs: define notmuch-message-queued-tag-changes as buffer-local
>   emacs: notmuch-message-apply-queued-tag-changes: cosmetics
>   emacs: notmuch-wash.el: require diff-mode at beginning of code
>   emacs: notmuch-mua-prompt-for-sender: don't force Ido on users
>   emacs: notmuch-mua.el: move all options into "Options" section
>   emacs: notmuch-crypto-status-button-type: fix potential bug
> 1 emacs: various cosmetic improvements
>   emacs: various comment improvements
>   emacs: various doc-string improvements
>   emacs: remove variable notmuch-search-disjunctive-regexp
>   emacs: define a few variables as automatically buffer-local
>   emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string
>   emacs: reorder notmuch.el a bit
>   emacs: avoid unnecessary let-bindings
> 2 emacs: improve how cl-lib and pcase are required
> 3 emacs: make subr-x available in all libraries
>   emacs: use string-empty-p
>   emacs: notmuch-tree-get-match: No longer define as command
> 4 emacs: allow opting out of notmuch's address completion
> 5 emacs: notmuch-address-expand-name: use the actual initial-input
>
>  emacs/coolj.el               |  14 +-
>  emacs/make-deps.el           |   2 +-
>  emacs/notmuch-address.el     | 103 +++++++-------
>  emacs/notmuch-company.el     |   3 -
>  emacs/notmuch-compat.el      |   4 +-
>  emacs/notmuch-crypto.el      |  14 +-
>  emacs/notmuch-draft.el       |  27 +++-
>  emacs/notmuch-hello.el       | 229 +++++++++++++++---------------
>  emacs/notmuch-jump.el        |  18 +--
>  emacs/notmuch-lib.el         | 199 +++++++++++++-------------
>  emacs/notmuch-maildir-fcc.el | 114 +++++++--------
>  emacs/notmuch-message.el     |  25 ++--
>  emacs/notmuch-mua.el         | 124 +++++++++--------
>  emacs/notmuch-parser.el      |  22 ++-
>  emacs/notmuch-print.el       |  16 ++-
>  emacs/notmuch-query.el       |  21 ++-
>  emacs/notmuch-show.el        | 130 ++++++++++-------
>  emacs/notmuch-tag.el         | 103 ++++++++------
>  emacs/notmuch-tree.el        |  61 ++++----
>  emacs/notmuch-wash.el        |  54 ++++----
>  emacs/notmuch.el             | 261 ++++++++++++++++++-----------------
>  emacs/rstdoc.el              |   2 +-
>  test/test-lib.el             |   4 +-
>  23 files changed, 813 insertions(+), 737 deletions(-)
>
> -- 
> 2.29.1
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 79+ messages in thread

* Re: [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope
  2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
                     ` (36 preceding siblings ...)
  2021-01-13  9:13   ` [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
@ 2021-01-13 12:11   ` David Bremner
  2021-01-13 13:02     ` Tomi Ollila
  2021-01-13 17:41     ` Jonas Bernoulli
  37 siblings, 2 replies; 79+ messages in thread
From: David Bremner @ 2021-01-13 12:11 UTC (permalink / raw)
  To: Jonas Bernoulli, notmuch

Jonas Bernoulli <jonas@bernoul.li> writes:

> This fixes a minor whitespace bug that Tomi notices in (1).
>
> This also adds for commits, two of them in response to a concern
> raised by Tomi, who didn't "see enough point for requiring subr-x
> just [for string-empty-p]", which I agree with:
>
> 2) Changes how `cl-lib' and `pcase' are required.  I did that first
>    because I want to do it the same way as for `subr-x'.
>
> 3) Require `subr-x', so that we can use it without having to worry
>    whether we have now reached the threshold where it becomes
>    justified to require an additional library.

I pushed applied the first 22 patches to master.

"[PATCH v2 23/36] emacs: various cosmetic improvements" leads to some
test failures. FWIW, I'm using Emacs 27.1 on Debian testing.

T310-emacs: Testing emacs interface
 FAIL   notmuch-fcc-dirs set to a list (with match)
	--- T310-emacs.28.EXPECTED	2021-01-13 12:00:57.901428602 +0000
	+++ T310-emacs.28.OUTPUT	2021-01-13 12:00:57.905428701 +0000
	@@ -1,5 +0,0 @@
	-From: Notmuch Test Suite <test_suite@notmuchmail.org>
	-To: 
	-Subject: 
	-Fcc: /home/bremner/software/upstream/notmuch/test/tmp.T310-emacs/mail/sent-list-match
	---text follows this line--
*ERROR*: Wrong type argument: listp, "sent-list-match"
 FAIL   notmuch-fcc-dirs set to a list (catch-all)
	--- T310-emacs.29.EXPECTED	2021-01-13 12:00:57.933429400 +0000
	+++ T310-emacs.29.OUTPUT	2021-01-13 12:00:57.933429400 +0000
	@@ -1,5 +0,0 @@
	-From: Notmuch Test Suite <test_suite@notmuchmail.org>
	-To: 
	-Subject: 
	-Fcc: /home/bremner/software/upstream/notmuch/test/tmp.T310-emacs/mail/sent-list-catch-all
	---text follows this line--
*ERROR*: Wrong type argument: listp, "failure"
 FAIL   notmuch-fcc-dirs set to a list (no match)
	--- T310-emacs.30.EXPECTED	2021-01-13 12:00:57.953429900 +0000
	+++ T310-emacs.30.OUTPUT	2021-01-13 12:00:57.957430000 +0000
	@@ -1,4 +0,0 @@
	-From: Notmuch Test Suite <test_suite@notmuchmail.org>
	-To: 
	-Subject: 
	---text follows this line--
*ERROR*: Wrong type argument: listp, "failure"

^ permalink raw reply	[flat|nested] 79+ messages in thread

* Re: [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope
  2021-01-13 12:11   ` David Bremner
@ 2021-01-13 13:02     ` Tomi Ollila
  2021-01-13 17:41     ` Jonas Bernoulli
  1 sibling, 0 replies; 79+ messages in thread
From: Tomi Ollila @ 2021-01-13 13:02 UTC (permalink / raw)
  To: David Bremner, Jonas Bernoulli, notmuch

On Wed, Jan 13 2021, David Bremner wrote:

> Jonas Bernoulli <jonas@bernoul.li> writes:
>
>> This fixes a minor whitespace bug that Tomi notices in (1).
>>
>> This also adds for commits, two of them in response to a concern
>> raised by Tomi, who didn't "see enough point for requiring subr-x
>> just [for string-empty-p]", which I agree with:
>>
>> 2) Changes how `cl-lib' and `pcase' are required.  I did that first
>>    because I want to do it the same way as for `subr-x'.
>>
>> 3) Require `subr-x', so that we can use it without having to worry
>>    whether we have now reached the threshold where it becomes
>>    justified to require an additional library.
>
> I pushed applied the first 22 patches to master.
>
> "[PATCH v2 23/36] emacs: various cosmetic improvements" leads to some
> test failures. FWIW, I'm using Emacs 27.1 on Debian testing.

I got the same.

After some trial and error w/ "educated guesses", reverting this change
in notmuch-maildir-fcc.el (git diff from my tree after revert), 
test passed.

in emacs/notmuch-maildir-fcc.el


@@ -107,13 +107,16 @@ (defun notmuch-fcc-header-setup ()
           ;; Old style - no longer works.
           (error "Invalid `notmuch-fcc-dirs' setting (old style)"))
          ((listp notmuch-fcc-dirs)
-          (or (seq-some (let ((from (message-field-value "From")))
-                          (pcase-lambda (`(,regexp ,folder))
-                            (and (string-match-p regexp from)
-                                 folder)))
-                        notmuch-fcc-dirs)
-              (progn (message "No Fcc header added.")
-                     nil)))
+          (let* ((from (message-field-value "From"))
+                 (match
+                  (catch 'first-match
+                    (dolist (re-folder notmuch-fcc-dirs)
+                      (when (string-match-p (car re-folder) from)
+                        (throw 'first-match re-folder))))))
+            (if match
+                (cdr match)
+              (message "No Fcc header added.")
+              nil)))


>
> T310-emacs: Testing emacs interface
>  FAIL   notmuch-fcc-dirs set to a list (with match)
> 	--- T310-emacs.28.EXPECTED	2021-01-13 12:00:57.901428602 +0000
> 	+++ T310-emacs.28.OUTPUT	2021-01-13 12:00:57.905428701 +0000
> 	@@ -1,5 +0,0 @@
> 	-From: Notmuch Test Suite <test_suite@notmuchmail.org>
> 	-To: 
> 	-Subject: 
> 	-Fcc: /home/bremner/software/upstream/notmuch/test/tmp.T310-emacs/mail/sent-list-match
> 	---text follows this line--
> *ERROR*: Wrong type argument: listp, "sent-list-match"
>  FAIL   notmuch-fcc-dirs set to a list (catch-all)
> 	--- T310-emacs.29.EXPECTED	2021-01-13 12:00:57.933429400 +0000
> 	+++ T310-emacs.29.OUTPUT	2021-01-13 12:00:57.933429400 +0000
> 	@@ -1,5 +0,0 @@
> 	-From: Notmuch Test Suite <test_suite@notmuchmail.org>
> 	-To: 
> 	-Subject: 
> 	-Fcc: /home/bremner/software/upstream/notmuch/test/tmp.T310-emacs/mail/sent-list-catch-all
> 	---text follows this line--
> *ERROR*: Wrong type argument: listp, "failure"
>  FAIL   notmuch-fcc-dirs set to a list (no match)
> 	--- T310-emacs.30.EXPECTED	2021-01-13 12:00:57.953429900 +0000
> 	+++ T310-emacs.30.OUTPUT	2021-01-13 12:00:57.957430000 +0000
> 	@@ -1,4 +0,0 @@
> 	-From: Notmuch Test Suite <test_suite@notmuchmail.org>
> 	-To: 
> 	-Subject: 
> 	---text follows this line--
> *ERROR*: Wrong type argument: listp, "failure"
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 79+ messages in thread

* [PATCH v3 23/36] emacs: various cosmetic improvements
  2021-01-10 14:00   ` [PATCH v2 23/36] emacs: various cosmetic improvements Jonas Bernoulli
@ 2021-01-13 17:37     ` Jonas Bernoulli
  0 siblings, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-13 17:37 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-address.el     | 22 ++++------
 emacs/notmuch-hello.el       | 24 ++++-------
 emacs/notmuch-jump.el        |  4 +-
 emacs/notmuch-lib.el         | 26 +++++------
 emacs/notmuch-maildir-fcc.el | 61 +++++++++++---------------
 emacs/notmuch-mua.el         | 28 ++++++------
 emacs/notmuch-query.el       | 11 +++--
 emacs/notmuch-tag.el         | 14 +++---
 emacs/notmuch.el             | 83 ++++++++++++++++++------------------
 9 files changed, 125 insertions(+), 148 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1017c3ce..2f0ec9b3 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -21,6 +21,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
@@ -160,15 +162,12 @@ (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (let* ((setup-company (and notmuch-address-use-company
-			     (require 'company nil t)))
-	 (pair (cons notmuch-address-completion-headers-regexp
-		     #'notmuch-address-expand-name)))
-    (when setup-company
-      (notmuch-company-setup))
-    (unless (member pair message-completion-alist)
-      (setq message-completion-alist
-	    (push pair message-completion-alist)))))
+  (when (and notmuch-address-use-company
+	     (require 'company nil t))
+    (notmuch-company-setup))
+  (cl-pushnew (cons notmuch-address-completion-headers-regexp
+		    #'notmuch-address-expand-name)
+	      message-completion-alist :test #'equal))
 
 (defun notmuch-address-toggle-internal-completion ()
   "Toggle use of internal completion for current buffer.
@@ -264,9 +263,6 @@ (defun notmuch-address-harvest-addr (result)
   (let ((name-addr (plist-get result :name-addr)))
     (puthash name-addr t notmuch-address-completions)))
 
-(defun notmuch-address-harvest-handle-result (obj)
-  (notmuch-address-harvest-addr obj))
-
 (defun notmuch-address-harvest-filter (proc string)
   (when (buffer-live-p (process-buffer proc))
     (with-current-buffer (process-buffer proc)
@@ -274,7 +270,7 @@ (defun notmuch-address-harvest-filter (proc string)
 	(goto-char (point-max))
 	(insert string))
       (notmuch-sexp-parse-partial-list
-       'notmuch-address-harvest-handle-result (process-buffer proc)))))
+       'notmuch-address-harvest-addr (process-buffer proc)))))
 
 (defvar notmuch-address-harvest-procs '(nil . nil)
   "The currently running harvests.
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index a134eb07..ffd3d799 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -432,8 +432,7 @@ (defun notmuch-hello-add-saved-search (widget &rest _event)
     ;; If an existing saved search with this name exists, remove it.
     (setq notmuch-saved-searches
 	  (cl-loop for elem in notmuch-saved-searches
-		   if (not (equal name
-				  (notmuch-saved-search-get elem :name)))
+		   unless (equal name (notmuch-saved-search-get elem :name))
 		   collect elem))
     ;; Add the new one.
     (customize-save-variable 'notmuch-saved-searches
@@ -481,18 +480,14 @@ (defun notmuch-hello-reflect (list ncols)
 	     append (notmuch-hello-reflect-generate-row ncols nrows row list))))
 
 (defun notmuch-hello-widget-search (widget &rest _ignore)
-  (cond
-   ((eq (widget-get widget :notmuch-search-type) 'tree)
-    (notmuch-tree (widget-get widget
-			      :notmuch-search-terms)))
-   ((eq (widget-get widget :notmuch-search-type) 'unthreaded)
-    (notmuch-unthreaded (widget-get widget
-				    :notmuch-search-terms)))
+  (cl-case (widget-get widget :notmuch-search-type)
+   (tree
+    (notmuch-tree (widget-get widget :notmuch-search-terms)))
+   (unthreaded
+    (notmuch-unthreaded (widget-get widget :notmuch-search-terms)))
    (t
-    (notmuch-search (widget-get widget
-				:notmuch-search-terms)
-		    (widget-get widget
-				:notmuch-search-oldest-first)))))
+    (notmuch-search (widget-get widget :notmuch-search-terms)
+		    (widget-get widget :notmuch-search-oldest-first)))))
 
 (defun notmuch-saved-search-count (search)
   (car (process-lines notmuch-command "count" search)))
@@ -823,8 +818,7 @@ (defun notmuch-hello-insert-search ()
   ;; instead of a space to make `show-trailing-whitespace'
   ;; happy, i.e. avoid it marking the whole line as trailing
   ;; spaces.
-  (widget-insert ".")
-  (put-text-property (1- (point)) (point) 'invisible t)
+  (widget-insert (propertize "." 'invisible t))
   (widget-insert "\n"))
 
 (defun notmuch-hello-insert-recent-searches ()
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 51bc4e31..34d6c796 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -63,8 +63,8 @@ (defun notmuch-jump-search ()
     (setq action-map (nreverse action-map))
     (if action-map
 	(notmuch-jump action-map "Search: ")
-      (error "To use notmuch-jump, \
-please customize shortcut keys in notmuch-saved-searches."))))
+      (error "To use notmuch-jump, %s"
+	     "please customize shortcut keys in notmuch-saved-searches."))))
 
 (defvar notmuch-jump--action nil)
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 1bdfc2b9..3add992b 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -192,8 +192,8 @@ (defun notmuch-command-to-string (&rest args)
 
 Otherwise the output will be returned."
   (with-temp-buffer
-    (let* ((status (apply #'call-process notmuch-command nil t nil args))
-	   (output (buffer-string)))
+    (let ((status (apply #'call-process notmuch-command nil t nil args))
+	  (output (buffer-string)))
       (notmuch-check-exit-status status (cons notmuch-command args) output)
       output)))
 
@@ -248,7 +248,8 @@ (defun notmuch-config-get (item)
 	 (len (length val)))
     ;; Trim off the trailing newline (if the value is empty or not
     ;; configured, there will be no newline)
-    (if (and (> len 0) (= (aref val (- len 1)) ?\n))
+    (if (and (> len 0)
+	     (= (aref val (- len 1)) ?\n))
 	(substring val 0 -1)
       val)))
 
@@ -538,13 +539,12 @@ (defun notmuch-common-do-stash (text)
 ;;; Generic Utilities
 
 (defun notmuch-plist-delete (plist property)
-  (let* ((xplist (cons nil plist))
-	 (pred xplist))
-    (while (cdr pred)
-      (when (eq (cadr pred) property)
-	(setcdr pred (cdddr pred)))
-      (setq pred (cddr pred)))
-    (cdr xplist)))
+  (let (p)
+    (while plist
+      (unless (eq property (car plist))
+	(setq p (plist-put p (car plist) (cadr plist))))
+      (setq plist (cddr plist)))
+    p))
 
 ;;; MML Utilities
 
@@ -555,8 +555,10 @@ (defun notmuch-match-content-type (t1 t2)
     (if (or (string= (cadr st1) "*")
 	    (string= (cadr st2) "*"))
 	;; Comparison of content types should be case insensitive.
-	(string= (downcase (car st1)) (downcase (car st2)))
-      (string= (downcase t1) (downcase t2)))))
+	(string= (downcase (car st1))
+		 (downcase (car st2)))
+      (string= (downcase t1)
+	       (downcase t2)))))
 
 (defvar notmuch-multipart/alternative-discouraged
   '(;; Avoid HTML parts.
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 9f09129d..c6bdd769 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -107,16 +107,13 @@ (defun notmuch-fcc-header-setup ()
 	   ;; Old style - no longer works.
 	   (error "Invalid `notmuch-fcc-dirs' setting (old style)"))
 	  ((listp notmuch-fcc-dirs)
-	   (let* ((from (message-field-value "From"))
-		  (match
-		   (catch 'first-match
-		     (dolist (re-folder notmuch-fcc-dirs)
-		       (when (string-match-p (car re-folder) from)
-			 (throw 'first-match re-folder))))))
-	     (if match
-		 (cdr match)
-	       (message "No Fcc header added.")
-	       nil)))
+	   (or (seq-some (let ((from (message-field-value "From")))
+			   (pcase-lambda (`(,regexp . ,folder))
+			     (and (string-match-p regexp from)
+				  folder)))
+			 notmuch-fcc-dirs)
+	       (progn (message "No Fcc header added.")
+		      nil)))
 	  (t
 	   (error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))
     (when subdir
@@ -128,9 +125,9 @@ (defun notmuch-maildir-add-notmuch-insert-style-fcc-header (subdir)
   ;; Notmuch insert does not accept absolute paths, so check the user
   ;; really want this header inserted.
   (when (or (not (= (elt subdir 0) ?/))
-	    (y-or-n-p
-	     (format "Fcc header %s is an absolute path and notmuch insert is requested.
-Insert header anyway? " subdir)))
+	    (y-or-n-p (format "Fcc header %s is an absolute path %s %s" subdir
+			      "and notmuch insert is requested."
+			      "Insert header anyway? ")))
     (message-add-header (concat "Fcc: " subdir))))
 
 (defun notmuch-maildir-add-file-style-fcc-header (subdir)
@@ -173,7 +170,7 @@ (defun notmuch-maildir-message-do-fcc ()
   "Process Fcc headers in the current buffer.
 
 This is a rearranged version of message mode's message-do-fcc."
-  (let (list file)
+  (let (files file)
     (save-excursion
       (save-restriction
 	(message-narrow-to-headers)
@@ -183,13 +180,11 @@ (defun notmuch-maildir-message-do-fcc ()
 	 (save-restriction
 	   (message-narrow-to-headers)
 	   (while (setq file (message-fetch-field "fcc" t))
-	     (push file list)
+	     (push file files)
 	     (message-remove-header "fcc" nil t)))
 	 (notmuch-maildir-setup-message-for-saving)
 	 ;; Process FCC operations.
-	 (while list
-	   (setq file (pop list))
-	   (notmuch-fcc-handler file))
+	 (mapc #'notmuch-fcc-handler files)
 	 (kill-buffer (current-buffer)))))))
 
 (defun notmuch-fcc-handler (fcc-header)
@@ -201,7 +196,8 @@ (defun notmuch-fcc-handler (fcc-header)
   (message "Doing Fcc...")
   (if notmuch-maildir-use-notmuch-insert
       (notmuch-maildir-fcc-with-notmuch-insert fcc-header)
-    (notmuch-maildir-fcc-file-fcc fcc-header)))
+    (notmuch-maildir-fcc-file-fcc fcc-header))
+  (message "Doing Fcc...done"))
 
 ;;; Functions for saving a message using notmuch insert.
 
@@ -230,9 +226,8 @@ (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
 or surrounding the entire folder name in double quotes.
 
 If CREATE is non-nil then create the folder if necessary."
-  (let* ((args (split-string-and-unquote fcc-header))
-	 (folder (car args))
-	 (tags (cdr args)))
+  (pcase-let ((`(,folder . ,tags)
+	       (split-string-and-unquote fcc-header)))
     (condition-case nil
 	(notmuch-maildir-notmuch-insert-current-buffer folder create tags)
       ;; Since there are many reasons notmuch insert could fail, e.g.,
@@ -265,7 +260,7 @@ (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
   (let* ((ftime (float-time))
 	 (microseconds (mod (* 1000000 ftime) 1000000))
 	 (hostname (notmuch-maildir-fcc-host-fixer (system-name))))
-    (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
+    (cl-incf notmuch-maildir-fcc-count)
     (format "%d.%d_%d_%d.%s"
 	    ftime
 	    (emacs-pid)
@@ -298,9 +293,7 @@ (defun notmuch-maildir-fcc-save-buffer-to-tmp (destdir)
 	   (write-file (concat destdir "/tmp/" msg-id))
 	   msg-id)
 	  (t
-	   (error (format "Can't write to %s. Not a maildir."
-			  destdir))
-	   nil))))
+	   (error "Can't write to %s. Not a maildir." destdir)))))
 
 (defun notmuch-maildir-fcc-move-tmp-to-new (destdir msg-id)
   (add-name-to-file
@@ -345,16 +338,12 @@ (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
       (catch 'link-error
 	(let ((msg-id (notmuch-maildir-fcc-save-buffer-to-tmp destdir)))
 	  (when msg-id
-	    (cond (mark-seen
-		   (condition-case nil
-		       (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
-		     (file-already-exists
-		      (throw 'link-error nil))))
-		  (t
-		   (condition-case nil
-		       (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id)
-		     (file-already-exists
-		      (throw 'link-error nil))))))
+	    (condition-case nil
+		(if mark-seen
+		    (notmuch-maildir-fcc-move-tmp-to-cur destdir msg-id t)
+		  (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id))
+	      (file-already-exists
+	       (throw 'link-error nil))))
 	  (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 74ffd8f2..4a08e8a7 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -179,13 +179,11 @@ (defun notmuch-mua-attachment-check ()
 
 (defun notmuch-mua-get-switch-function ()
   "Get a switch function according to `notmuch-mua-compose-in'."
-  (cond ((eq notmuch-mua-compose-in 'current-window)
-	 'switch-to-buffer)
-	((eq notmuch-mua-compose-in 'new-window)
-	 'switch-to-buffer-other-window)
-	((eq notmuch-mua-compose-in 'new-frame)
-	 'switch-to-buffer-other-frame)
-	(t (error "Invalid value for `notmuch-mua-compose-in'"))))
+  (pcase notmuch-mua-compose-in
+    ('current-window 'switch-to-buffer)
+    ('new-window     'switch-to-buffer-other-window)
+    ('new-frame      'switch-to-buffer-other-frame)
+    (_ (error "Invalid value for `notmuch-mua-compose-in'"))))
 
 (defun notmuch-mua-maybe-set-window-dedicated ()
   "Set the selected window as dedicated according to `notmuch-mua-compose-in'."
@@ -375,12 +373,10 @@ (defun notmuch-mua-pop-to-buffer (name switch-function)
 		(select-window window))
 	    (funcall switch-function buffer)
 	    (set-buffer buffer))
-	  (when (and (buffer-modified-p)
-		     (not (prog1
-			      (y-or-n-p
-			       "Message already being composed; erase? ")
-			    (message nil))))
-	    (error "Message being composed")))
+	  (when (buffer-modified-p)
+	    (if (y-or-n-p "Message already being composed; erase? ")
+		(message nil)
+	      (error "Message being composed"))))
       (funcall switch-function name)
       (set-buffer name))
     (erase-buffer)
@@ -611,8 +607,10 @@ (defun notmuch-mua-kill-buffer ()
 ;;; _
 
 (define-mail-user-agent 'notmuch-user-agent
-  'notmuch-mua-mail 'notmuch-mua-send-and-exit
-  'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
+  'notmuch-mua-mail
+  'notmuch-mua-send-and-exit
+  'notmuch-mua-kill-buffer
+  'notmuch-mua-send-hook)
 
 ;; Add some more headers to the list that `message-mode' hides when
 ;; composing a message.
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index ffce8814..d7349b77 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -41,11 +41,9 @@ (defun notmuch-query-get-threads (search-terms)
 
 (defun notmuch-query-map-aux  (mapper function seq)
   "Private function to do the actual mapping and flattening."
-  (apply 'append
-	 (mapcar
-	  (lambda (tree)
-	    (funcall mapper function tree))
-	  seq)))
+  (cl-mapcan (lambda (tree)
+	       (funcall mapper function tree))
+	     seq))
 
 (defun notmuch-query-map-threads (fn threads)
   "Apply function FN to every thread in THREADS.
@@ -63,7 +61,8 @@ (defun notmuch-query-map-tree (fn tree)
   "Apply function FN to every message in TREE.
 Flatten results to a list.  See the function
 `notmuch-query-get-threads' for more information."
-  (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
+  (cons (funcall fn (car tree))
+	(notmuch-query-map-forest fn (cadr tree))))
 
 ;;; Predefined queries
 
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index a553dfd9..0c9a32ac 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -454,8 +454,9 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((op (string-to-char tag-change))
-	    (tag (unless (string= tag-change "") (substring tag-change 1))))
+      (let ((op (aref tag-change 0))
+	    (tag (and (not (string= tag-change ""))
+		      (substring tag-change 1))))
 	(cl-case op
 	  (?+ (unless (member tag result-tags)
 		(push tag result-tags)))
@@ -482,13 +483,12 @@ (defun notmuch-tag (query tag-changes)
 directly, so that hooks specified in notmuch-before-tag-hook and
 notmuch-after-tag-hook will be run."
   ;; Perform some validation
-  (mapc (lambda (tag-change)
-	  (unless (string-match-p "^[-+]\\S-+$" tag-change)
-	    (error "Tag must be of the form `+this_tag' or `-that_tag'")))
-	tag-changes)
+  (dolist (tag-change tag-changes)
+    (unless (string-match-p "^[-+]\\S-+$" tag-change)
+      (error "Tag must be of the form `+this_tag' or `-that_tag'")))
   (unless query
     (error "Nothing to tag!"))
-  (unless (null tag-changes)
+  (when tag-changes
     (run-hooks 'notmuch-before-tag-hook)
     (if (<= (length query) notmuch-tag-argument-limit)
 	(apply 'notmuch-call-notmuch-process "tag"
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3928cd65..c4ee9e63 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -179,7 +179,7 @@ (defvar notmuch-search-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map notmuch-common-keymap)
     (define-key map "x" 'notmuch-bury-or-kill-this-buffer)
-    (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
+    (define-key map (kbd "DEL") 'notmuch-search-scroll-down)
     (define-key map "b" 'notmuch-search-scroll-down)
     (define-key map " " 'notmuch-search-scroll-up)
     (define-key map "<" 'notmuch-search-first-thread)
@@ -232,7 +232,7 @@ (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
 
-(defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")
+(defvar notmuch-search-disjunctive-regexp "\\<[oO][rR]\\>")
 
 ;;; Movement
 
@@ -950,40 +950,39 @@ (defun notmuch-read-query (prompt)
   "Read a notmuch-query from the minibuffer with completion.
 
 PROMPT is the string to prompt with."
-  (let*
-      ((all-tags
-	(mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
-		(process-lines notmuch-command "search" "--output=tags" "*")))
-       (completions
-	(append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
-		      "subject:" "attachment:")
-		(mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
-		(mapcar (lambda (tag) (concat "is:" tag)) all-tags)
-		(mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
-			(mailcap-mime-types)))))
-    (let ((keymap (copy-keymap minibuffer-local-map))
-	  (current-query (cl-case major-mode
-			   (notmuch-search-mode (notmuch-search-get-query))
-			   (notmuch-show-mode (notmuch-show-get-query))
-			   (notmuch-tree-mode (notmuch-tree-get-query))))
-	  (minibuffer-completion-table
-	   (completion-table-dynamic
-	    (lambda (string)
-	      ;; generate a list of possible completions for the current input
-	      (cond
-	       ;; this ugly regexp is used to get the last word of the input
-	       ;; possibly preceded by a '('
-	       ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
-		(mapcar (lambda (compl)
-			  (concat (match-string-no-properties 1 string) compl))
-			(all-completions (match-string-no-properties 2 string)
-					 completions)))
-	       (t (list string)))))))
-      ;; this was simpler than convincing completing-read to accept spaces:
-      (define-key keymap (kbd "TAB") 'minibuffer-complete)
-      (let ((history-delete-duplicates t))
-	(read-from-minibuffer prompt nil keymap nil
-			      'notmuch-search-history current-query nil)))))
+  (let* ((all-tags
+	  (mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
+		  (process-lines notmuch-command "search" "--output=tags" "*")))
+	 (completions
+	  (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
+			"subject:" "attachment:")
+		  (mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
+		  (mapcar (lambda (tag) (concat "is:" tag)) all-tags)
+		  (mapcar (lambda (mimetype) (concat "mimetype:" mimetype))
+			  (mailcap-mime-types))))
+	 (keymap (copy-keymap minibuffer-local-map))
+	 (current-query (cl-case major-mode
+			  (notmuch-search-mode (notmuch-search-get-query))
+			  (notmuch-show-mode (notmuch-show-get-query))
+			  (notmuch-tree-mode (notmuch-tree-get-query))))
+	 (minibuffer-completion-table
+	  (completion-table-dynamic
+	   (lambda (string)
+	     ;; Generate a list of possible completions for the current input.
+	     (cond
+	      ;; This ugly regexp is used to get the last word of the input
+	      ;; possibly preceded by a '('.
+	      ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
+	       (mapcar (lambda (compl)
+			 (concat (match-string-no-properties 1 string) compl))
+		       (all-completions (match-string-no-properties 2 string)
+					completions)))
+	      (t (list string)))))))
+    ;; This was simpler than convincing completing-read to accept spaces:
+    (define-key keymap (kbd "TAB") 'minibuffer-complete)
+    (let ((history-delete-duplicates t))
+      (read-from-minibuffer prompt nil keymap nil
+			    'notmuch-search-history current-query nil))))
 
 (defun notmuch-search-get-query ()
   "Return the current query in this search buffer."
@@ -1042,12 +1041,12 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
 		     (if oldest-first
 			 "--sort=oldest-first"
 		       "--sort=newest-first")
-		     query))
-	      ;; Use a scratch buffer to accumulate partial output.
-	      ;; This buffer will be killed by the sentinel, which
-	      ;; should be called no matter how the process dies.
-	      (parse-buf (generate-new-buffer " *notmuch search parse*")))
-	  (process-put proc 'parse-buf parse-buf)
+		     query)))
+	  ;; Use a scratch buffer to accumulate partial output.
+	  ;; This buffer will be killed by the sentinel, which
+	  ;; should be called no matter how the process dies.
+	  (process-put proc 'parse-buf
+		       (generate-new-buffer " *notmuch search parse*"))
 	  (set-process-filter proc 'notmuch-search-process-filter)
 	  (set-process-query-on-exit-flag proc nil))))
     (run-hooks 'notmuch-search-hook)))
-- 
2.30.0

^ permalink raw reply related	[flat|nested] 79+ messages in thread

* Re: [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope
  2021-01-13 12:11   ` David Bremner
  2021-01-13 13:02     ` Tomi Ollila
@ 2021-01-13 17:41     ` Jonas Bernoulli
  1 sibling, 0 replies; 79+ messages in thread
From: Jonas Bernoulli @ 2021-01-13 17:41 UTC (permalink / raw)
  To: David Bremner, notmuch

David Bremner <david@tethera.net> writes:

> I pushed applied the first 22 patches to master.

Thanks!

> "[PATCH v2 23/36] emacs: various cosmetic improvements" leads to some
> test failures. FWIW, I'm using Emacs 27.1 on Debian testing.

Sorry about, it seems I did not rerun the tests after making the
responsible change.  It was a silly one character (well two) bug:

-			   (pcase-lambda (`(,regexp ,folder))
+     			   (pcase-lambda (`(,regexp . ,folder))

I have send v3 of just that one commit (23).

     Jonas

^ permalink raw reply	[flat|nested] 79+ messages in thread

* Re: [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input
  2021-01-10 14:01   ` [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input Jonas Bernoulli
@ 2021-01-15 11:28     ` David Bremner
  0 siblings, 0 replies; 79+ messages in thread
From: David Bremner @ 2021-01-15 11:28 UTC (permalink / raw)
  To: Jonas Bernoulli, notmuch

Jonas Bernoulli <jonas@bernoul.li> writes:

> 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.

applied the remainder of the series.

^ permalink raw reply	[flat|nested] 79+ messages in thread

end of thread, other threads:[~2021-01-15 11:28 UTC | newest]

Thread overview: 79+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 01/32] emacs: use setq instead of set Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 03/32] emacs: define new notmuch-search-item widget type Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 04/32] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 05/32] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 06/32] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 07/32] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 08/32] emacs: avoid passing around some redundant information Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 09/32] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 10/32] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 11/32] emacs: use lexical-bindings in all libraries Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 12/32] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 13/32] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 14/32] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 15/32] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 16/32] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 17/32] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 18/32] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 19/32] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 20/32] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 21/32] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 22/32] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 23/32] emacs: various cosmetic improvements Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 24/32] emacs: various comment improvements Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 25/32] emacs: various doc-string improvements Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 26/32] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 27/32] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 28/32] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 29/32] emacs: reorder notmuch.el a bit Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 30/32] emacs: avoid unnecessary let-bindings Jonas Bernoulli
2020-12-14 16:24 ` [PATCH 31/32] emacs: use string-empty-p Jonas Bernoulli
2020-12-14 16:24 ` [PATCH 32/32] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
2020-12-27 10:14 ` [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
2020-12-28 14:08   ` Tomi Ollila
2020-12-30 17:10   ` Jonas Bernoulli
2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 01/36] emacs: use setq instead of set Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 02/36] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 03/36] emacs: define new notmuch-search-item widget type Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 04/36] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 05/36] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 06/36] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 07/36] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 08/36] emacs: avoid passing around some redundant information Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 09/36] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 10/36] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 11/36] emacs: use lexical-bindings in all libraries Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 12/36] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 13/36] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 14/36] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 15/36] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 16/36] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 17/36] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 18/36] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 19/36] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 20/36] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 21/36] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 22/36] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 23/36] emacs: various cosmetic improvements Jonas Bernoulli
2021-01-13 17:37     ` [PATCH v3 " Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 24/36] emacs: various comment improvements Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 25/36] emacs: various doc-string improvements Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 26/36] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 27/36] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 28/36] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 29/36] emacs: reorder notmuch.el a bit Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 30/36] emacs: avoid unnecessary let-bindings Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 31/36] emacs: improve how cl-lib and pcase are required Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 32/36] emacs: make subr-x available in all libraries Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 33/36] emacs: use string-empty-p Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 34/36] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 35/36] emacs: allow opting out of notmuch's address completion Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input Jonas Bernoulli
2021-01-15 11:28     ` David Bremner
2021-01-13  9:13   ` [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
2021-01-13 12:11   ` David Bremner
2021-01-13 13:02     ` Tomi Ollila
2021-01-13 17:41     ` Jonas Bernoulli

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).