From e1a700067a22214f54064c281219fbbbef87de06 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sat, 8 Aug 2020 13:49:43 +0200 Subject: [PATCH] emacs: Use 'when' instead of 'if' when there is no ELSE part --- emacs/notmuch-address.el | 8 ++-- emacs/notmuch-compat.el | 6 +-- emacs/notmuch-hello.el | 8 ++-- emacs/notmuch-jump.el | 54 ++++++++++----------- emacs/notmuch-lib.el | 10 ++-- emacs/notmuch-mua.el | 24 +++++----- emacs/notmuch-query.el | 4 +- emacs/notmuch-show.el | 93 ++++++++++++++++++------------------ emacs/notmuch-tree.el | 30 ++++++------ emacs/notmuch-wash.el | 68 +++++++++++++------------- emacs/notmuch.el | 100 +++++++++++++++++++-------------------- test/test-lib.el | 4 +- 12 files changed, 206 insertions(+), 203 deletions(-) diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index 2dd08661..85531489 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -171,10 +171,10 @@ 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) - (if (local-variable-p 'company-idle-delay) - (kill-local-variable 'company-idle-delay) - (notmuch-setq-local company-idle-delay nil)))) + (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)))) (defun notmuch-address-matching (substring) "Returns a list of completion candidates matching SUBSTRING. diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el index 388ef70f..3340918f 100644 --- a/emacs/notmuch-compat.el +++ b/emacs/notmuch-compat.el @@ -68,9 +68,9 @@ 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) - (with-output-to-temp-buffer " *Char Help*" - (princ msg)))))) + (when (stringp msg) + (with-output-to-temp-buffer " *Char Help*" + (princ msg)))))) ((memq char chars) (setq done t)) ((and executing-kbd-macro (= char -1)) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 1c0b1848..c17b46bc 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -589,8 +589,8 @@ with `notmuch-hello-query-counts'." (mapc (lambda (elem) ;; (not elem) indicates an empty slot in the matrix. (when elem - (if (> column-indent 0) - (widget-insert (make-string column-indent ? ))) + (when (> column-indent 0) + (widget-insert (make-string column-indent ? ))) (let* ((name (plist-get elem :name)) (query (plist-get elem :query)) (oldest-first (cl-case (plist-get elem :sort-order) @@ -890,8 +890,8 @@ 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)) - (add-to-list 'notmuch-hello-hidden-sections title)) + (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))) (if is-hidden diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el index adf79650..e302fe00 100644 --- a/emacs/notmuch-jump.el +++ b/emacs/notmuch-jump.el @@ -169,37 +169,37 @@ 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) - (define-key map key - `(lambda () (interactive) - (setq notmuch-jump--action ',fn) - (exit-minibuffer))))) + (when (= (length key) 1) + (define-key map key + `(lambda () (interactive) + (setq notmuch-jump--action ',fn) + (exit-minibuffer))))) ;; 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) - (if (> (length key) 1) - (let* ((key (elt key 0)) - (keystr (string key)) - (new-prompt (concat prompt (format-kbd-macro keystr) " ")) - (action-submap nil)) - (unless (lookup-key map keystr) - (pcase-dolist (`(,k ,n ,f) action-map) - (when (= key (elt k 0)) - (push (list (substring k 1) n f) action-submap))) - ;; We deal with backspace specially - (push (list (kbd "DEL") - "Backup" - (apply-partially #'notmuch-jump action-map prompt)) - action-submap) - (setq action-submap (nreverse action-submap)) - (define-key map keystr - `(lambda () (interactive) - (setq notmuch-jump--action - ',(apply-partially #'notmuch-jump - action-submap - new-prompt)) - (exit-minibuffer))))))) + (when (> (length key) 1) + (let* ((key (elt key 0)) + (keystr (string key)) + (new-prompt (concat prompt (format-kbd-macro keystr) " ")) + (action-submap nil)) + (unless (lookup-key map keystr) + (pcase-dolist (`(,k ,n ,f) action-map) + (when (= key (elt k 0)) + (push (list (substring k 1) n f) action-submap))) + ;; We deal with backspace specially + (push (list (kbd "DEL") + "Backup" + (apply-partially #'notmuch-jump action-map prompt)) + action-submap) + (setq action-submap (nreverse action-submap)) + (define-key map keystr + `(lambda () (interactive) + (setq notmuch-jump--action + ',(apply-partially #'notmuch-jump + action-submap + new-prompt)) + (exit-minibuffer))))))) map)) ;; diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 98056eb6..da48bb86 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -664,11 +664,11 @@ 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) - (defadvice mm-shr (before load-gnus-arts activate) - (require 'gnus-art nil t) - (ad-disable-advice 'mm-shr 'before 'load-gnus-arts) - (ad-activate 'mm-shr))) +(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) + (ad-activate 'mm-shr))) (defun notmuch-mm-display-part-inline (msg part content-type process-crypto) "Use the mm-decode/mm-view functions to display a part in the diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index dc1f518c..2910a63e 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -275,8 +275,8 @@ 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 - (forward-line -1)) + (when message-signature-insert-empty-line + (forward-line -1)) (goto-char (point-max)))) (let ((from (plist-get original-headers :From)) (date (plist-get original-headers :Date)) @@ -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,14 +429,15 @@ 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)) - (defadvice ido-completing-read (before notmuch-ido-mode-init activate) - (ido-init-completion-maps) - (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup) - (add-hook 'choose-completion-string-functions - 'ido-choose-completion-string) - (ad-disable-advice 'ido-completing-read 'before 'notmuch-ido-mode-init) - (ad-activate 'ido-completing-read))) +(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) + (add-hook 'choose-completion-string-functions + 'ido-choose-completion-string) + (ad-disable-advice 'ido-completing-read 'before 'notmuch-ido-mode-init) + (ad-activate 'ido-completing-read))) (defun notmuch-mua-prompt-for-sender () "Prompt for a sender from the user's configured identities." diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el index 1db9d7ca..a8e5d11f 100644 --- a/emacs/notmuch-query.el +++ b/emacs/notmuch-query.el @@ -30,8 +30,8 @@ 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 - (setq args (append args '("--decrypt=true")))) + (when notmuch-show-process-crypto + (setq args (append args '("--decrypt=true")))) (setq args (append args search-terms)) (apply #'notmuch-call-notmuch-sexp args))) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 7a033150..f1cd92fe 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -346,10 +346,10 @@ operation on the contents of the current buffer." (indenting notmuch-show-indent-content)) (with-temp-buffer (insert all) - (if indenting - (indent-rigidly (point-min) - (point-max) - (- (* notmuch-show-indent-messages-width depth)))) + (when indenting + (indent-rigidly (point-min) + (point-max) + (- (* notmuch-show-indent-messages-width depth)))) ;; Remove the original header. (goto-char (point-min)) (re-search-forward "^$" (point-max) nil) @@ -392,13 +392,13 @@ 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) - (let ((inhibit-read-only t)) - (replace-match (concat "(" - (notmuch-tag-format-tags - tags - (notmuch-show-get-prop :orig-tags)) - ")")))))) + (when (re-search-forward "(\\([^()]*\\))$" (line-end-position) t) + (let ((inhibit-read-only t)) + (replace-match (concat "(" + (notmuch-tag-format-tags + tags + (notmuch-show-get-prop :orig-tags)) + ")")))))) (defun notmuch-clean-address (address) "Try to clean a single email ADDRESS for display. Return a cons @@ -488,9 +488,9 @@ 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 - (not (string-equal "" header-value))) - (notmuch-show-insert-header header header-value)))) + (when (and header-value + (not (string-equal "" header-value))) + (notmuch-show-insert-header header header-value)))) notmuch-message-headers) (save-excursion (save-restriction @@ -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) - (push (cons 'notmuch-show-mode #'notmuch-show--cid-w3m-retrieve) - 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)) (setq mm-html-inhibit-images nil)) (defvar w3m-current-buffer) ;; From `w3m.el'. @@ -767,22 +767,22 @@ 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") - ;; https://bugs.gnu.org/28350 - ;; - ;; For newer emacs, we fall back to notmuch-show-insert-part-*/* - ;; (see notmuch-show-handlers-for) - (defun notmuch-show-insert-part-text/enriched - (msg part content-type nth depth button) - ;; By requiring enriched below, we ensure that the function - ;; enriched-decode-display-prop is defined before it will be - ;; shadowed by the letf below. Otherwise the version in - ;; enriched.el may be loaded a bit later and used instead (for - ;; the first time). - (require 'enriched) - (cl-letf (((symbol-function 'enriched-decode-display-prop) - (lambda (start end &optional param) (list start end)))) - (notmuch-show-insert-part-*/* msg part content-type nth depth button)))) +(when (version< emacs-version "25.3") + ;; https://bugs.gnu.org/28350 + ;; + ;; For newer emacs, we fall back to notmuch-show-insert-part-*/* + ;; (see notmuch-show-handlers-for) + (defun notmuch-show-insert-part-text/enriched + (msg part content-type nth depth button) + ;; By requiring enriched below, we ensure that the function + ;; enriched-decode-display-prop is defined before it will be + ;; shadowed by the letf below. Otherwise the version in + ;; enriched.el may be loaded a bit later and used instead (for + ;; the first time). + (require 'enriched) + (cl-letf (((symbol-function 'enriched-decode-display-prop) + (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) ;; If we can deduce a MIME type from the filename of the attachment, @@ -849,8 +849,8 @@ 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) - (push func result))) + (when (functionp func) + (push func result))) ;; Reverse order of prefrence. (list (intern (concat "notmuch-show-insert-part-*/*")) (intern (concat @@ -1080,10 +1080,10 @@ 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 - (indent-rigidly content-start - content-end - (* notmuch-show-indent-messages-width depth))) + (when notmuch-show-indent-content + (indent-rigidly content-start + content-end + (* notmuch-show-indent-messages-width depth))) (setq message-end (point-max-marker)) ;; Save the extents of this message over the whole text of the ;; message. @@ -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,9 +1786,9 @@ 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) - (setq message-ids - (append message-ids (list (notmuch-show-get-message-id))))) + (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)))) message-ids))) @@ -1842,8 +1843,8 @@ archives the entire current thread, (apply changes in thread from the search from which this thread was originally shown." (interactive) - (if (notmuch-show-advance) - (notmuch-show-archive-thread-then-next))) + (when (notmuch-show-advance) + (notmuch-show-archive-thread-then-next))) (defun notmuch-show-rewind () "Backup through the thread (reverse scrolling compared to \ diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index a5ae0edb..6a619ec2 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -967,19 +967,19 @@ 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) - (with-current-buffer buffer - (save-excursion - (let ((inhibit-read-only t) - (atbob (bobp))) - (goto-char (point-max)) - (if (eq status 'signal) - (insert "Incomplete search results (tree view process was killed).\n")) - (when (eq status 'exit) - (insert "End of search results.") - (unless (= exit-status 0) - (insert (format " (process returned %d)" exit-status))) - (insert "\n"))))))))) + (when (buffer-live-p buffer) + (with-current-buffer buffer + (save-excursion + (let ((inhibit-read-only t) + (atbob (bobp))) + (goto-char (point-max)) + (when (eq status 'signal) + (insert "Incomplete search results (tree view process was killed).\n")) + (when (eq status 'exit) + (insert "End of search results.") + (unless (= exit-status 0) + (insert (format " (process returned %d)" exit-status))) + (insert "\n"))))))))) (defun notmuch-tree-process-filter (proc string) "Process and filter the output of \"notmuch show\" for tree view." @@ -1023,8 +1023,8 @@ 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") - (setq search-args basic-query)) + (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 "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index 31fda61f..ce4b9637 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -216,8 +216,8 @@ that PREFIX should not include a newline." (goto-char (1+ end)) (save-excursion (goto-char beg) - (if prefix - (insert-before-markers prefix)) + (when prefix + (insert-before-markers prefix)) (let ((button-beg (point))) (insert-before-markers (notmuch-wash-button-label overlay) "\n") (let ((button (make-button button-beg (1- (point)) @@ -229,13 +229,13 @@ 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)) - (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"))) + (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"))) (while (and (< (point) (point-max)) (re-search-forward notmuch-wash-citation-regexp nil t)) (let* ((cite-start (match-beginning 0)) @@ -254,21 +254,21 @@ that PREFIX should not include a newline." (notmuch-wash-region-to-button msg hidden-start (point-marker) "citation"))))) - (if (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) - (let ((sig-start-marker (make-marker)) - (sig-end-marker (make-marker))) - (set-marker sig-start-marker sig-start) - (set-marker sig-end-marker (point-max)) - (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 - "signature")))))) + (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-marker (make-marker)) + (sig-end-marker (make-marker))) + (set-marker sig-start-marker sig-start) + (set-marker sig-end-marker (point-max)) + (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 + "signature")))))) ;; @@ -286,12 +286,12 @@ 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") - (delete-region (match-beginning 0) (match-end 0))) + (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") - (delete-region (match-beginning 0) (match-end 0)))) + (when (looking-at "\n") + (delete-region (match-beginning 0) (match-end 0)))) ;; @@ -399,12 +399,12 @@ for error." (patch-end (point-max)) part) (goto-char patch-start) - (if (or - ;; Patch ends with signature. - (re-search-forward notmuch-wash-signature-regexp nil t) - ;; Patch ends with bugtraq comment. - (re-search-forward "^\\*\\*\\* " nil t)) - (setq patch-end (match-beginning 0))) + (when (or + ;; Patch ends with signature. + (re-search-forward notmuch-wash-signature-regexp nil t) + ;; Patch ends with bugtraq comment. + (re-search-forward "^\\*\\*\\* " nil t)) + (setq patch-end (match-beginning 0))) (save-restriction (narrow-to-region patch-start patch-end) (setq part (plist-put part :content-type "inline patch")) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 93e92b39..4fc338e2 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -674,28 +674,28 @@ of the result." (when (memq status '(exit signal)) (catch 'return (kill-buffer (process-get proc 'parse-buf)) - (if (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) - (insert "Incomplete search results (search process was killed).\n")) - (when (eq status 'exit) - (insert "End of search results.\n") - ;; For version mismatch, there's no point in - ;; showing the search buffer - (when (or (= exit-status 20) (= exit-status 21)) - (kill-buffer) - (throw 'return nil)) - (if (and atbob + (when (buffer-live-p buffer) + (with-current-buffer buffer + (save-excursion + (let ((inhibit-read-only t) + (atbob (bobp))) + (goto-char (point-max)) + (when (eq status 'signal) + (insert "Incomplete search results (search process was killed).\n")) + (when (eq status 'exit) + (insert "End of search results.\n") + ;; For version mismatch, there's no point in + ;; showing the search buffer + (when (or (= exit-status 20) (= exit-status 21)) + (kill-buffer) + (throw 'return nil)) + (when (and atbob (not (string= notmuch-search-target-thread "found"))) - (set 'never-found-target-thread t))))) - (when (and never-found-target-thread - notmuch-search-target-line) - (goto-char (point-min)) - (forward-line (1- notmuch-search-target-line))))))))) + (set 'never-found-target-thread t))))) + (when (and never-found-target-thread + notmuch-search-target-line) + (goto-char (point-min)) + (forward-line (1- notmuch-search-target-line))))))))) (define-widget 'notmuch--custom-face-edit 'lazy "Custom face edit with a tag Edit Face" @@ -760,31 +760,31 @@ 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) - (length formatted-sample)) - (let ((visible-length (- (length formatted-sample) - (length "... ")))) - ;; Truncate the visible string according to the width of - ;; the display string. - (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. - (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string) - ;; Second clause is destructive on `visible-string', so - ;; order is important. - (setq invisible-string (concat (match-string 3 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 - ;; after `invisible-string'. - (setq padding (make-string (- (length formatted-sample) - (length visible-string) - (length "...")) - ? )))) + (when (> (length formatted-authors) + (length formatted-sample)) + (let ((visible-length (- (length formatted-sample) + (length "... ")))) + ;; Truncate the visible string according to the width of + ;; the display string. + (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. + (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string) + ;; Second clause is destructive on `visible-string', so + ;; order is important. + (setq invisible-string (concat (match-string 3 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 + ;; after `invisible-string'. + (setq padding (make-string (- (length formatted-sample) + (length visible-string) + (length "...")) + ? )))) ;; Use different faces to show matching and non-matching authors. (if (string-match "\\(.*\\)|\\(.*\\)" visible-string) ;; The visible string contains both matching and @@ -1006,8 +1006,8 @@ the configured default sort order." (notmuch-tag-clear-cache) (let ((proc (get-buffer-process (current-buffer))) (inhibit-read-only t)) - (if proc - (error "notmuch search process already running for query `%s'" query)) + (when proc + (error "notmuch search process already running for query `%s'" query)) (erase-buffer) (goto-char (point-min)) (save-excursion @@ -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. - (load notmuch-init-file t t nil t)) +(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 diff --git a/test/test-lib.el b/test/test-lib.el index a1233390..6a39bbe2 100644 --- a/test/test-lib.el +++ b/test/test-lib.el @@ -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))) -- 2.43.0