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

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

Date: Mon, 14 Dec 2020 17:23:41 +0100

To: notmuch@notmuchmail.org


From: 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
 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)))
@@ -406,7 +406,7 @@ (defun notmuch-address-harvest-trigger ()
       (setq notmuch-address-last-harvest now)
        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)
    ((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."
     (widget-insert ". ")
     (widget-insert "You have ")
     (widget-create 'link
-		   :notify (lambda (&rest ignore)
+		   :notify (lambda (&rest _ignore)
 		   :help-echo "Refresh"
@@ -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))
       (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))
       (widget-create 'push-button
-		     :notify `(lambda (widget &rest ignore)
+		     :notify `(lambda (widget &rest _ignore)
 				(add-to-list 'notmuch-hello-hidden-sections
@@ -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 ""
     (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)
   ;; 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)
 		      (throw 'link-error nil))))
-		   (condition-case err
+		   (condition-case nil
 		       (notmuch-maildir-fcc-move-tmp-to-new destdir msg-id)
 		      (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)
-(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."
@@ -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."
-(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 ": "))
@@ -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)))
@@ -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)))
-(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)))
-(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)))
-(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)))
-(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)
-(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)))
-(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)))
-(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))))
-(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
 ;; 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)
-(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)
@@ -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)
 (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.
-      (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)."
   (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.
@@ -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
-	    (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)
   (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)
   (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
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org