[PATCH v2 08/23] emacs: Use 'unless' instead of 'when' and 'not'

Subject: [PATCH v2 08/23] emacs: Use 'unless' instead of 'when' and 'not'

Date: Thu, 6 Aug 2020 09:18:55 +0200

To: notmuch@notmuchmail.org

Cc:

From: Jonas Bernoulli


Also use 'unless' in a few cases where previously 'if' was used with
'not' but without an ELSE part.
---
 emacs/notmuch-hello.el  | 6 +++---
 emacs/notmuch-mua.el    | 4 ++--
 emacs/notmuch-parser.el | 2 +-
 emacs/notmuch-show.el   | 3 +--
 emacs/notmuch-tag.el    | 4 ++--
 emacs/notmuch-tree.el   | 8 ++++----
 emacs/notmuch.el        | 4 ++--
 test/test-lib.el        | 6 +++---
 8 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 1c084bf7..25e28a52 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -638,7 +638,7 @@ (defun notmuch-hello-window-configuration-change ()
     (dolist (window (window-list))
       (let ((last-buf (window-parameter window 'notmuch-hello-last-buffer))
 	    (cur-buf (window-buffer window)))
-	(when (not (eq last-buf cur-buf))
+	(unless (eq last-buf cur-buf)
 	  ;; This window changed or is new.  Update recorded buffer
 	  ;; for next time.
 	  (set-window-parameter window 'notmuch-hello-last-buffer cur-buf)
@@ -652,7 +652,7 @@ (defun notmuch-hello-window-configuration-change ()
       ;; 24, we can't do it right here because something in this
       ;; hook's call stack overrides hello's point placement.
       (run-at-time nil nil #'notmuch-hello t))
-    (when (null hello-buf)
+    (unless hello-buf
       ;; Clean up hook
       (remove-hook 'window-configuration-change-hook
 		   #'notmuch-hello-window-configuration-change))))
@@ -908,7 +908,7 @@ (defun notmuch-hello-insert-searches (title query-list &rest options)
 				(notmuch-hello-update))
 		     "hide"))
     (widget-insert "\n")
-    (when (not is-hidden)
+    (unless is-hidden
       (let ((searches (apply 'notmuch-hello-query-counts query-list options)))
 	(when (or (not (plist-get options :hide-if-empty))
 		  searches)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index f6d8ffc5..dc1f518c 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -198,7 +198,7 @@ (defun notmuch-mua-user-agent-emacs ()
 (defun notmuch-mua-add-more-hidden-headers ()
   "Add some headers to the list that are hidden by default."
   (mapc (lambda (header)
-	  (when (not (member header message-hidden-headers))
+	  (unless (member header message-hidden-headers)
 	    (push header message-hidden-headers)))
 	notmuch-mua-hidden-headers))
 
@@ -368,7 +368,7 @@ (defun notmuch-mua-mail (&optional to subject other-headers continue
   (interactive)
   (when notmuch-mua-user-agent-function
     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
-      (when (not (string= "" user-agent))
+      (unless (string= "" user-agent)
 	(push (cons 'User-Agent user-agent) other-headers))))
   (unless (assq 'From other-headers)
     (push (cons 'From (message-make-from
diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el
index 06e7487b..fbcfc2ef 100644
--- a/emacs/notmuch-parser.el
+++ b/emacs/notmuch-parser.el
@@ -78,7 +78,7 @@ (defun notmuch-sexp-read (sp)
 	 ;; parse, extend the partial parse to figure out when we
 	 ;; have a complete list.
 	 (catch 'return
-	   (when (null (notmuch-sexp--partial-state sp))
+	   (unless (notmuch-sexp--partial-state sp)
 	     (let ((start (point)))
 	       (condition-case nil
 		   (throw 'return (read (current-buffer)))
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 211be091..6102ca2e 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1060,8 +1060,7 @@ (defun notmuch-show-insert-msg (msg depth)
       ;; If the subject of this message is the same as that of the
       ;; previous message, don't display it when this message is
       ;; collapsed.
-      (when (not (string= notmuch-show-previous-subject
-			  bare-subject))
+      (unless (string= notmuch-show-previous-subject bare-subject)
 	(forward-line 1))
       (setq headers-start (point-marker)))
     (setq headers-end (point-marker))
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 2fcf5a9e..1067f185 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -382,8 +382,8 @@ (defun notmuch-tag-completions (&rest search-terms)
   "Return a list of tags for messages matching SEARCH-TERMS.
 
 Returns all tags if no search terms are given."
-  (if (null search-terms)
-      (setq search-terms (list "*")))
+  (unless search-terms
+    (setq search-terms (list "*")))
   (split-string
    (with-output-to-string
      (with-current-buffer standard-output
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 37a5d1c8..a5ae0edb 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1063,10 +1063,10 @@ (defun notmuch-tree (&optional query query-context target buffer-name open-targe
   OPEN-TARGET: If TRUE open the target message in the message pane.
   UNTHREADED: If TRUE only show matching messages in an unthreaded view."
   (interactive)
-  (if (null query)
-      (setq query (notmuch-read-query (concat "Notmuch "
-					      (if unthreaded "unthreaded " "tree ")
-					      "view search: "))))
+  (unless query
+    (setq query (notmuch-read-query (concat "Notmuch "
+					    (if unthreaded "unthreaded " "tree ")
+					    "view search: "))))
   (let ((buffer (get-buffer-create (generate-new-buffer-name
 				    (or buffer-name
 					(concat "*notmuch-"
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 41207643..93e92b39 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -803,13 +803,13 @@ (defun notmuch-search-insert-authors (format-string authors)
 	(setq invisible-string (notmuch-search-author-propertize invisible-string)))
       ;; If there is any invisible text, add it as a tooltip to the
       ;; visible text.
-      (when (not (string= invisible-string ""))
+      (unless (string= invisible-string "")
 	(setq visible-string
 	      (propertize visible-string
 			  'help-echo (concat "..." invisible-string))))
       ;; Insert the visible and, if present, invisible author strings.
       (insert visible-string)
-      (when (not (string= invisible-string ""))
+      (unless (string= invisible-string "")
 	(let ((start (point))
 	      overlay)
 	  (insert invisible-string)
diff --git a/test/test-lib.el b/test/test-lib.el
index aae9e833..a1233390 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -81,7 +81,7 @@ (defun visible-buffer-substring (start end)
   (let (str)
     (while (< start end)
       (let ((next-pos (next-char-property-change start end)))
-	(when (not (invisible-p start))
+	(unless (invisible-p start)
 	  (setq str (concat str (buffer-substring-no-properties
 				 start next-pos))))
 	(setq start next-pos)))
@@ -97,8 +97,8 @@ (defun test-process-running (pid)
 (defun orphan-watchdog-check (pid)
   "Periodically check that the process with id PID is still
 running, quit if it terminated."
-  (if (not (test-process-running pid))
-      (kill-emacs)))
+  (unless (test-process-running pid)
+    (kill-emacs)))
 
 (defun orphan-watchdog (pid)
   "Initiate orphan watchdog check."
-- 
2.28.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: