]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch.el
emacs: Use 'and' instead of 'when' when the return value matters
[notmuch] / emacs / notmuch.el
index d6e0a9d54ee48a6e074dd3f85dd561f19ae63ab8..4120764352ff57115d9d4cae63f96ef87e227f02 100644 (file)
@@ -264,7 +264,8 @@ there will be called at other points of notmuch execution."
   (goto-char (point-max))
   (forward-line -2)
   (let ((beg (notmuch-search-result-beginning)))
-    (when beg (goto-char beg))))
+    (when beg
+      (goto-char beg))))
 
 (defun notmuch-search-first-thread ()
   "Select the first thread in the search results."
@@ -406,11 +407,12 @@ If there is no thread at POS (or point), returns nil."
   "Return the point at the beginning of the thread at POS (or point).
 
 If there is no thread at POS (or point), returns nil."
-  (when (notmuch-search-get-result pos)
-    ;; We pass 1+point because previous-single-property-change starts
-    ;; searching one before the position we give it.
-    (previous-single-property-change (1+ (or pos (point)))
-                                    'notmuch-search-result nil (point-min))))
+  (and (notmuch-search-get-result pos)
+       ;; We pass 1+point because previous-single-property-change starts
+       ;; searching one before the position we give it.
+       (previous-single-property-change (1+ (or pos (point)))
+                                       'notmuch-search-result nil
+                                       (point-min))))
 
 (defun notmuch-search-result-end (&optional pos)
   "Return the point at the end of the thread at POS (or point).
@@ -418,9 +420,10 @@ If there is no thread at POS (or point), returns nil."
 The returned point will be just after the newline character that
 ends the result line.  If there is no thread at POS (or point),
 returns nil."
-  (when (notmuch-search-get-result pos)
-    (next-single-property-change (or pos (point)) 'notmuch-search-result
-                                nil (point-max))))
+  (and (notmuch-search-get-result pos)
+       (next-single-property-change (or pos (point))
+                                   'notmuch-search-result nil
+                                   (point-max))))
 
 (defun notmuch-search-foreach-result (beg end fn)
   "Invoke FN for each result between BEG and END.
@@ -443,8 +446,8 @@ BEG."
     (while (and pos (or (< pos end) first))
       (when (notmuch-search-get-result pos)
        (funcall fn pos))
-      (setq pos (notmuch-search-result-end pos)
-           first nil))))
+      (setq pos (notmuch-search-result-end pos))
+      (setq first nil))))
 ;; Unindent the function argument of notmuch-search-foreach-result so
 ;; the indentation of callers doesn't get out of hand.
 (put 'notmuch-search-foreach-result 'lisp-indent-function 2)
@@ -461,7 +464,8 @@ BEG."
 
 If BARE is set then do not prefix with \"thread:\"."
   (let ((thread (plist-get (notmuch-search-get-result) :thread)))
-    (when thread (concat (unless bare "thread:") thread))))
+    (when thread
+      (concat (and (not bare) "thread:") thread))))
 
 (defun notmuch-search-find-stable-query ()
   "Return the stable queries for the current thread.
@@ -482,8 +486,8 @@ no messages in the region then return nil."
        (push (car queries) query-list))
       (when (and all (cadr queries))
        (push (cadr queries) query-list)))
-    (when query-list
-      (concat "(" (mapconcat 'identity query-list ") or (") ")"))))
+    (and query-list
+        (concat "(" (mapconcat 'identity query-list ") or (") ")"))))
 
 (defun notmuch-search-find-authors ()
   "Return the authors for the current thread."
@@ -589,8 +593,8 @@ is inactive this applies to the thread at point.
 If ONLY-MATCHED is non-nil, only tag matched messages."
   (interactive (notmuch-search-interactive-tag-changes))
   (unless (and beg end)
-    (setq beg (car (notmuch-interactive-region))
-         end (cadr (notmuch-interactive-region))))
+    (setq beg (car (notmuch-interactive-region)))
+    (setq end (cadr (notmuch-interactive-region))))
   (let ((search-string (notmuch-search-find-stable-query-region
                        beg end only-matched)))
     (notmuch-tag search-string tag-changes)
@@ -762,8 +766,8 @@ non-authors is found, assume that all of the authors match."
                                   (length "... "))))
            ;; Truncate the visible string according to the width of
            ;; the display string.
-           (setq visible-string (substring formatted-authors 0 visible-length)
-                 invisible-string (substring formatted-authors visible-length))
+           (setq visible-string (substring formatted-authors 0 visible-length))
+           (setq invisible-string (substring formatted-authors visible-length))
            ;; If possible, truncate the visible string at a natural
            ;; break (comma or pipe), as incremental search doesn't
            ;; match across the visible/invisible border.
@@ -771,8 +775,8 @@ non-authors is found, assume that all of the authors match."
              ;; Second clause is destructive on `visible-string', so
              ;; order is important.
              (setq invisible-string (concat (match-string 3 visible-string)
-                                            invisible-string)
-                   visible-string (concat (match-string 1 visible-string)
+                                            invisible-string))
+             (setq visible-string (concat (match-string 1 visible-string)
                                           (match-string 2 visible-string))))
            ;; `visible-string' may be shorter than the space allowed
            ;; by `format-string'. If so we must insert some padding
@@ -785,17 +789,18 @@ non-authors is found, assume that all of the authors match."
       (if (string-match "\\(.*\\)|\\(.*\\)" visible-string)
          ;; The visible string contains both matching and
          ;; non-matching authors.
-         (setq visible-string (notmuch-search-author-propertize visible-string)
-               ;; The invisible string must contain only non-matching
-               ;; authors, as the visible-string contains both.
-               invisible-string (propertize invisible-string
-                                            'face 'notmuch-search-non-matching-authors))
+         (progn
+           (setq visible-string (notmuch-search-author-propertize visible-string))
+           ;; The invisible string must contain only non-matching
+           ;; authors, as the visible-string contains both.
+           (setq invisible-string (propertize invisible-string
+                                              'face 'notmuch-search-non-matching-authors)))
        ;; The visible string contains only matching authors.
        (setq visible-string (propertize visible-string
-                                        'face 'notmuch-search-matching-authors)
-             ;; The invisible string may contain both matching and
-             ;; non-matching authors.
-             invisible-string (notmuch-search-author-propertize invisible-string)))
+                                        'face 'notmuch-search-matching-authors))
+       ;; The invisible string may contain both matching and
+       ;; non-matching 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 ""))