emacs: Use 'when' instead of 'if' when there is no ELSE part

This commit is contained in:
Jonas Bernoulli 2020-08-08 13:49:43 +02:00 committed by David Bremner
parent 09f6533c37
commit e1a700067a
12 changed files with 206 additions and 203 deletions

View file

@ -171,7 +171,7 @@ toggles the setting in this buffer."
(if (local-variable-p 'notmuch-address-command)
(kill-local-variable 'notmuch-address-command)
(notmuch-setq-local notmuch-address-command 'internal))
(if (boundp 'company-idle-delay)
(when (boundp 'company-idle-delay)
(if (local-variable-p 'company-idle-delay)
(kill-local-variable 'company-idle-delay)
(notmuch-setq-local company-idle-delay nil))))

View file

@ -68,7 +68,7 @@ inlined."
;; This is an inlined copy of help-form-show as that
;; was introduced in emacs 24 too.
(let ((msg (eval help-form)))
(if (stringp msg)
(when (stringp msg)
(with-output-to-temp-buffer " *Char Help*"
(princ msg))))))
((memq char chars)

View file

@ -589,7 +589,7 @@ with `notmuch-hello-query-counts'."
(mapc (lambda (elem)
;; (not elem) indicates an empty slot in the matrix.
(when elem
(if (> column-indent 0)
(when (> column-indent 0)
(widget-insert (make-string column-indent ? )))
(let* ((name (plist-get elem :name))
(query (plist-get elem :query))
@ -890,7 +890,7 @@ Supports the following entries in OPTIONS as a plist:
the same values as :filter. If :filter and :filter-count are specified, this
will be used instead of :filter, not in conjunction with it."
(widget-insert title ": ")
(if (and notmuch-hello-first-run (plist-get options :initially-hidden))
(when (and notmuch-hello-first-run (plist-get options :initially-hidden))
(add-to-list 'notmuch-hello-hidden-sections title))
(let ((is-hidden (member title notmuch-hello-hidden-sections))
(start (point)))

View file

@ -169,7 +169,7 @@ buffer."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map notmuch-jump-minibuffer-map)
(pcase-dolist (`(,key ,name ,fn) action-map)
(if (= (length key) 1)
(when (= (length key) 1)
(define-key map key
`(lambda () (interactive)
(setq notmuch-jump--action ',fn)
@ -178,7 +178,7 @@ buffer."
;; binding) we avoid problems if the user specifies a binding which
;; is a prefix of another binding.
(pcase-dolist (`(,key ,name ,fn) action-map)
(if (> (length key) 1)
(when (> (length key) 1)
(let* ((key (elt key 0))
(keystr (string key))
(new-prompt (concat prompt (format-kbd-macro keystr) " "))

View file

@ -664,7 +664,7 @@ MSG (if it isn't already)."
;; first loading gnus-art, which defines it, resulting in a
;; void-variable error. Hence, we advise `mm-shr' to ensure gnus-art
;; is loaded.
(if (>= emacs-major-version 24)
(when (>= emacs-major-version 24)
(defadvice mm-shr (before load-gnus-arts activate)
(require 'gnus-art nil t)
(ad-disable-advice 'mm-shr 'before 'load-gnus-arts)

View file

@ -275,7 +275,7 @@ Typically this is added to `notmuch-mua-send-hook'."
(narrow-to-region (point) (point-max))
(goto-char (point-max))
(if (re-search-backward message-signature-separator nil t)
(if message-signature-insert-empty-line
(when message-signature-insert-empty-line
(forward-line -1))
(goto-char (point-max))))
(let ((from (plist-get original-headers :From))
@ -388,7 +388,8 @@ modified. This function is notmuch addaptation of
;; https://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
;; We need to convert any string input, eg from rmail-start-mail.
(dolist (h other-headers other-headers)
(if (stringp (car h)) (setcar h (intern (capitalize (car h))))))))
(when (stringp (car h))
(setcar h (intern (capitalize (car h))))))))
(args (list yank-action send-actions))
;; Cause `message-setup-1' to do things relevant for mail,
;; such as observe `message-default-mail-headers'.
@ -428,7 +429,8 @@ the From: header is already filled in by notmuch."
;; without some explicit initialization fill freeze the operation.
;; Hence, we advice `ido-completing-read' to ensure required initialization
;; is done.
(if (and (= emacs-major-version 23) (< emacs-minor-version 4))
(when (and (= emacs-major-version 23)
(< emacs-minor-version 4))
(defadvice ido-completing-read (before notmuch-ido-mode-init activate)
(ido-init-completion-maps)
(add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup)

View file

@ -30,7 +30,7 @@ A thread is a forest or list of trees. A tree is a two element
list where the first element is a message, and the second element
is a possibly empty forest of replies."
(let ((args '("show" "--format=sexp" "--format-version=4")))
(if notmuch-show-process-crypto
(when notmuch-show-process-crypto
(setq args (append args '("--decrypt=true"))))
(setq args (append args search-terms))
(apply #'notmuch-call-notmuch-sexp args)))

View file

@ -346,7 +346,7 @@ operation on the contents of the current buffer."
(indenting notmuch-show-indent-content))
(with-temp-buffer
(insert all)
(if indenting
(when indenting
(indent-rigidly (point-min)
(point-max)
(- (* notmuch-show-indent-messages-width depth))))
@ -392,7 +392,7 @@ operation on the contents of the current buffer."
"Update the displayed tags of the current message."
(save-excursion
(goto-char (notmuch-show-message-top))
(if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
(when (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
(let ((inhibit-read-only t))
(replace-match (concat "("
(notmuch-tag-format-tags
@ -488,7 +488,7 @@ message at DEPTH in the current thread."
(mapc (lambda (header)
(let* ((header-symbol (intern (concat ":" header)))
(header-value (plist-get headers header-symbol)))
(if (and header-value
(when (and header-value
(not (string-equal "" header-value)))
(notmuch-show-insert-header header header-value))))
notmuch-message-headers)
@ -606,10 +606,10 @@ will return nil if the CID is unknown or cannot be retrieved."
(defun notmuch-show-setup-w3m ()
"Instruct w3m how to retrieve content from a \"related\" part of a message."
(interactive)
(if (boundp 'w3m-cid-retrieve-function-alist)
(unless (assq 'notmuch-show-mode w3m-cid-retrieve-function-alist)
(when (and (boundp 'w3m-cid-retrieve-function-alist)
(not (assq 'notmuch-show-mode w3m-cid-retrieve-function-alist)))
(push (cons 'notmuch-show-mode #'notmuch-show--cid-w3m-retrieve)
w3m-cid-retrieve-function-alist)))
w3m-cid-retrieve-function-alist))
(setq mm-html-inhibit-images nil))
(defvar w3m-current-buffer) ;; From `w3m.el'.
@ -767,7 +767,7 @@ will return nil if the CID is unknown or cannot be retrieved."
(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))
(if (version< emacs-version "25.3")
(when (version< emacs-version "25.3")
;; https://bugs.gnu.org/28350
;;
;; For newer emacs, we fall back to notmuch-show-insert-part-*/*
@ -849,7 +849,7 @@ will return nil if the CID is unknown or cannot be retrieved."
"Return a list of content handlers for a part of type CONTENT-TYPE."
(let (result)
(mapc (lambda (func)
(if (functionp func)
(when (functionp func)
(push func result)))
;; Reverse order of prefrence.
(list (intern (concat "notmuch-show-insert-part-*/*"))
@ -1080,7 +1080,7 @@ is t, hide the part initially and show the button."
(insert "\n"))
(setq content-end (point-marker))
;; Indent according to the depth in the thread.
(if notmuch-show-indent-content
(when notmuch-show-indent-content
(indent-rigidly content-start
content-end
(* notmuch-show-indent-messages-width depth)))
@ -1288,7 +1288,8 @@ and THREAD. The next query is THREAD alone, and serves as a
fallback if the prior matches no messages."
(let (queries)
(push (list thread) queries)
(if context (push (list thread "and (" context ")") queries))
(when context
(push (list thread "and (" context ")") queries))
queries))
(defun notmuch-show--build-buffer (&optional state)
@ -1785,7 +1786,7 @@ Reshows the current thread with matches defined by the new query-string."
(let (message-ids done)
(goto-char (point-min))
(while (not done)
(if (notmuch-show-message-visible-p)
(when (notmuch-show-message-visible-p)
(setq message-ids
(append message-ids (list (notmuch-show-get-message-id)))))
(setq done (not (notmuch-show-goto-message-next))))
@ -1842,7 +1843,7 @@ archives the entire current thread, (apply changes in
thread from the search from which this thread was originally
shown."
(interactive)
(if (notmuch-show-advance)
(when (notmuch-show-advance)
(notmuch-show-archive-thread-then-next)))
(defun notmuch-show-rewind ()

View file

@ -967,13 +967,13 @@ Complete list of currently available key bindings:
(never-found-target-thread nil))
(when (memq status '(exit signal))
(kill-buffer (process-get proc 'parse-buf))
(if (buffer-live-p buffer)
(when (buffer-live-p buffer)
(with-current-buffer buffer
(save-excursion
(let ((inhibit-read-only t)
(atbob (bobp)))
(goto-char (point-max))
(if (eq status 'signal)
(when (eq status 'signal)
(insert "Incomplete search results (tree view process was killed).\n"))
(when (eq status 'exit)
(insert "End of search results.")
@ -1023,7 +1023,7 @@ the same as for the function notmuch-tree."
(and query-context
(concat " and (" query-context ")"))))
(message-arg (if unthreaded "--unthreaded" "--entire-thread")))
(if (equal (car (process-lines notmuch-command "count" search-args)) "0")
(when (equal (car (process-lines notmuch-command "count" search-args)) "0")
(setq search-args basic-query))
(notmuch-tag-clear-cache)
(let ((proc (notmuch-start-notmuch

View file

@ -216,7 +216,7 @@ that PREFIX should not include a newline."
(goto-char (1+ end))
(save-excursion
(goto-char beg)
(if prefix
(when prefix
(insert-before-markers prefix))
(let ((button-beg (point)))
(insert-before-markers (notmuch-wash-button-label overlay) "\n")
@ -229,7 +229,7 @@ that PREFIX should not include a newline."
"Excerpt citations and up to one signature."
(goto-char (point-min))
(beginning-of-line)
(if (and (< (point) (point-max))
(when (and (< (point) (point-max))
(re-search-forward notmuch-wash-original-regexp nil t))
(let* ((msg-start (match-beginning 0))
(msg-end (point-max))
@ -254,12 +254,12 @@ that PREFIX should not include a newline."
(notmuch-wash-region-to-button
msg hidden-start (point-marker)
"citation")))))
(if (and (not (eobp))
(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))))
(if (<= sig-lines notmuch-wash-signature-lines-max)
(when (<= sig-lines notmuch-wash-signature-lines-max)
(let ((sig-start-marker (make-marker))
(sig-end-marker (make-marker)))
(set-marker sig-start-marker sig-start)
@ -286,11 +286,11 @@ that PREFIX should not include a newline."
(delete-region (match-beginning 1) (match-end 1)))
;; Remove a leading blank line.
(goto-char (point-min))
(if (looking-at "\n")
(when (looking-at "\n")
(delete-region (match-beginning 0) (match-end 0)))
;; Remove a trailing blank line.
(goto-char (point-max))
(if (looking-at "\n")
(when (looking-at "\n")
(delete-region (match-beginning 0) (match-end 0))))
;;
@ -399,7 +399,7 @@ for error."
(patch-end (point-max))
part)
(goto-char patch-start)
(if (or
(when (or
;; Patch ends with signature.
(re-search-forward notmuch-wash-signature-regexp nil t)
;; Patch ends with bugtraq comment.

View file

@ -674,13 +674,13 @@ of the result."
(when (memq status '(exit signal))
(catch 'return
(kill-buffer (process-get proc 'parse-buf))
(if (buffer-live-p buffer)
(when (buffer-live-p buffer)
(with-current-buffer buffer
(save-excursion
(let ((inhibit-read-only t)
(atbob (bobp)))
(goto-char (point-max))
(if (eq status 'signal)
(when (eq status 'signal)
(insert "Incomplete search results (search process was killed).\n"))
(when (eq status 'exit)
(insert "End of search results.\n")
@ -689,7 +689,7 @@ of the result."
(when (or (= exit-status 20) (= exit-status 21))
(kill-buffer)
(throw 'return nil))
(if (and atbob
(when (and atbob
(not (string= notmuch-search-target-thread "found")))
(set 'never-found-target-thread t)))))
(when (and never-found-target-thread
@ -760,7 +760,7 @@ non-authors is found, assume that all of the authors match."
(invisible-string "")
(padding ""))
;; Truncate the author string to fit the specification.
(if (> (length formatted-authors)
(when (> (length formatted-authors)
(length formatted-sample))
(let ((visible-length (- (length formatted-sample)
(length "... "))))
@ -1006,7 +1006,7 @@ the configured default sort order."
(notmuch-tag-clear-cache)
(let ((proc (get-buffer-process (current-buffer)))
(inhibit-read-only t))
(if proc
(when proc
(error "notmuch search process already running for query `%s'" query))
(erase-buffer)
(goto-char (point-min))
@ -1156,7 +1156,7 @@ beginning of the line."
(provide 'notmuch)
;; After provide to avoid loops if notmuch was require'd via notmuch-init-file.
(if init-file-user ; don't load init file if the -q option was used.
(when init-file-user ; don't load init file if the -q option was used.
(load notmuch-init-file t t nil t))
;;; notmuch.el ends here

View file

@ -36,7 +36,7 @@
;; Work around a bug in emacs 23.1 and emacs 23.2 which prevents
;; noninteractive (kill-emacs) from emacsclient.
(if (and (= emacs-major-version 23) (< emacs-minor-version 3))
(when (and (= emacs-major-version 23) (< emacs-minor-version 3))
(defadvice kill-emacs (before disable-yes-or-no-p activate)
"Disable yes-or-no-p before executing kill-emacs"
(defun yes-or-no-p (prompt) t)))
@ -46,7 +46,7 @@
;; seems to be present in Emacs 23.1.
;; Running `list-processes' after `accept-process-output' seems to work
;; around this problem.
(if (and (= emacs-major-version 23) (= emacs-minor-version 1))
(when (and (= emacs-major-version 23) (= emacs-minor-version 1))
(defadvice accept-process-output (after run-list-processes activate)
"run list-processes after executing accept-process-output"
(list-processes)))