[PATCH 00/32] [emacs] Add outline headings and switch to lexical scope

classic Classic list List threaded Threaded
79 messages Options
1234
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/32] [emacs] Add outline headings and switch to lexical scope

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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 01/32] emacs: use setq instead of set

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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 02/32] emacs: sanitize dedicated widget action/notify functions

In reply to this post by Jonas Bernoulli
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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 03/32] emacs: define new notmuch-search-item widget type

In reply to this post by Jonas Bernoulli
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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 04/32] emacs: notmuch-start-notmuch: remove backward compatibility code

In reply to this post by Jonas Bernoulli
We no longer support Emacs releases before version 25.1.

Also adjust the sentinels which only had to deal with
an error file when using an older Emacs release was used.
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 05/32] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive

In reply to this post by Jonas Bernoulli
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 06/32] emacs: notmuch-start-notmuch-sentinel: assert buffer is alive

In reply to this post by Jonas Bernoulli
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 07/32] emacs: notmuch-start-notmuch: avoid storing process buffer twice

In reply to this post by Jonas Bernoulli
The buffer of the error process is accessible using `process-buffer'.
We still have to store the error-buffer in the non-error process
because for that process `process-buffer' obviously returns its own
buffer.
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 08/32] emacs: avoid passing around some redundant information

In reply to this post by Jonas Bernoulli
When running "notmuch" we use its full path but when displaying the
command to the user we show just its name for readability reasons.
Avoid passing around both representations because it is very easy
to get the name from the path.

Notmuch itself uses the involved functions just for "notmuch" but
there might be extensions that use them for other executable so we
forgo other potential simplifications.
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 09/32] emacs: avoid killing process buffer when process is still alive

In reply to this post by Jonas Bernoulli
In practice this probably does not make a difference or we would
have heard about it many times, but better be safe than sorry.

Process sentinels are called not only when the process has finished
but also on other state changes.
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 10/32] emacs: make headings outline-minor-mode compatible

In reply to this post by Jonas Bernoulli
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings.  That makes it very convenient to navigate
code and to show/hide parts of a file.

Elips libraries typically have four top-level sections, e.g.:

;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here

In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.

Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).

If the file is rather short, then I left "Code:" as the only section
that contains code.  Otherwise I split the file into multiple sibling
sections.  The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".

If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line.  This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it.  (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)

Before this commit some libraries already uses section headings, some
of them consistently.  When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.

A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.

Sections, including but not limited to their heading, can and should
be further improved in the future.
---
 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))
 
-;;
+;;; 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 <[hidden email]>
 
+;;; Code:
+
 (require 'cl-lib)
 
 ;; Ensure that the dynamic variables that are defined by this library
--
2.29.1
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 11/32] emacs: use lexical-bindings in all libraries

In reply to this post by Jonas Bernoulli
Doing so causes many new compile warnings.  Some of these warnings
concern genuine changes in behavior that have to be addressed right
away.

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

A third group of warnings concern arguments that are not actually used
inside the function but which cannot be removed because the functions
signature is dictated by some outside convention.  Silencing these
warning is also delayed until subsequent commits.
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 12/32] emacs: deal with unused lexical arguments and variables

In reply to this post by Jonas Bernoulli
The previous commit switched to lexical-binding but without dealing
with the new warnings about unused lexical arguments and variables.

This commit deals with most of them, in most cases by either removing
leftover bindings that are actually unnecessary, or by marking certain
arguments as "known to be unused" by prefixing their names with "_".

In the case of the functions named `notmuch-show-insert-...' the
amount of silencing that is required is a bit extreme and we might
want to investigate if there is a better way.

In the case of `notmuch-mua-mail', ignoring CONTINUE means that we do
not fully follow the intended behavior described in `compose-mail's
doc-string.
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 13/32] emacs: notmuch-tag--get-formats: silence byte-compiler

In reply to this post by Jonas Bernoulli
`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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 14/32] emacs: inline notmuch-sexp-eof into only caller

In reply to this post by Jonas Bernoulli
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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 15/32] emacs: notmuch-wash-region-to-button: remove unused MSG argument

In reply to this post by Jonas Bernoulli
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 16/32] emacs: silence compiler wrt notmuch-show-insert-part-text/plain

In reply to this post by Jonas Bernoulli
`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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 17/32] emacs: define notmuch-message-queued-tag-changes as buffer-local

In reply to this post by Jonas Bernoulli
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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 18/32] emacs: notmuch-message-apply-queued-tag-changes: cosmetics

In reply to this post by Jonas Bernoulli
---
 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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH 19/32] emacs: notmuch-wash.el: require diff-mode at beginning of code

In reply to this post by Jonas Bernoulli
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
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
1234