Skip to content

Commit

Permalink
mu4e: use if-let*, when-let*
Browse files Browse the repository at this point in the history
Avoid the silly byte-compilation warning
  • Loading branch information
djcb committed Oct 28, 2024
1 parent 0f16b22 commit b4adf32
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion mu4e/mu4e-actions.el
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ the message."
"Browse the archive for a mailing list message MSG.
See `mu4e-mailing-list-archive-url'."
(interactive (list (mu4e-message-at-point)))
(if-let ((url (mu4e-mailing-list-archive-url msg)))
(if-let* ((url (mu4e-mailing-list-archive-url msg)))
(browse-url url)
(mu4e-warn "No archive available for this message")))

Expand Down
4 changes: 2 additions & 2 deletions mu4e/mu4e-bookmarks.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ I.e., very new messages.")
(defun mu4e-jump-to-favorite ()
"Jump to to the favorite bookmark, if any."
(interactive)
(when-let ((fav (mu4e--bookmark-query (mu4e-bookmark-favorite))))
(when-let* ((fav (mu4e--bookmark-query (mu4e-bookmark-favorite))))
(mu4e-search-bookmark fav)))

(defun mu4e--bookmarks-modeline-item ()
"Modeline item showing message counts for the favorite bookmark.
This uses the one special ':favorite' bookmark, and if there is
one, creates a propertized string for display in the modeline."
(when-let ((fav ;; any results for the favorite bookmark item?
(when-let* ((fav ;; any results for the favorite bookmark item?
(seq-find (lambda (bm) (plist-get bm :favorite))
(mu4e-query-items 'bookmarks))))
(cl-destructuring-bind (&key unread count delta-unread
Expand Down
2 changes: 1 addition & 1 deletion mu4e/mu4e-contacts.el
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ The address are either plain e-mail addresses or regexps (strings
address patterns (if any)."
(seq-remove
(lambda (addr) (and no-regexp (string-match-p "^/.*/" addr)))
(when-let ((props (mu4e-server-properties)))
(when-let* ((props (mu4e-server-properties)))
(plist-get props :personal-addresses))))

(defun mu4e-personal-address-p (addr)
Expand Down
12 changes: 6 additions & 6 deletions mu4e/mu4e-draft.el
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ also marked as Seen.
Function assumes that it is executed in the context of the
message buffer."
(when-let ((buf (find-file-noselect path)))
(when-let* ((buf (find-file-noselect path)))
(with-current-buffer buf
(let ((in-reply-to (message-field-value "in-reply-to"))
(forwarded-from)
Expand Down Expand Up @@ -445,14 +445,14 @@ appropriate flag at the message forwarded or replied-to."
;; typically, draft is gone and the sent message appears in sent. Update flags
;; for related messages, i.e. for Forwarded ('Passed') and Replied messages,
;; try to set the appropriate flag at the message forwarded or replied-to.
(when-let ((fcc-path (message-field-value "Fcc")))
(when-let* ((fcc-path (message-field-value "Fcc")))
(mu4e--set-parent-flags fcc-path)
;; we end up with a ((buried) buffer here, visiting the
;; fcc-path; not quite sure why. But let's get rid of it (#2681)
(when-let ((buf (find-buffer-visiting fcc-path)))
(when-let* ((buf (find-buffer-visiting fcc-path)))
(kill-buffer buf)))
;; remove draft
(when-let ((draft (buffer-file-name)))
(when-let* ((draft (buffer-file-name)))
(mu4e--server-remove draft)))

(defun mu4e--compose-before-send ()
Expand Down Expand Up @@ -492,7 +492,7 @@ Creates a buffer NAME and returns it."
(defun mu4e--message-is-yours-p ()
"Mu4e's override for `message-is-yours-p'."
(seq-some (lambda (field)
(if-let ((recip (message-field-value field)))
(if-let* ((recip (message-field-value field)))
(mu4e-personal-or-alternative-address-p
(car (mail-header-parse-address recip)))))
'("From" "Sender")))
Expand Down Expand Up @@ -596,7 +596,7 @@ COMPOSE-TYPE and PARENT are as in `mu4e--draft'."
(set-visited-file-name ;; make it a draft file
(mu4e--draft-message-path (mu4e--draft-basename) parent)))
;; fcc
(when-let ((fcc-path (mu4e--fcc-path (mu4e--draft-basename) parent)))
(when-let* ((fcc-path (mu4e--fcc-path (mu4e--draft-basename) parent)))
(message-add-header (concat "Fcc: " fcc-path "\n")))

(mu4e--prepare-draft-headers compose-type)
Expand Down
4 changes: 2 additions & 2 deletions mu4e/mu4e-headers.el
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ This is suitable for displaying in the header view."

(defsubst mu4e~headers-insert-header (msg pos)
"Insert a header for MSG at point POS."
(when-let ((line (mu4e~message-header-line msg))
(when-let* ((line (mu4e~message-header-line msg))
(docid (plist-get msg :docid)))
(goto-char pos)
(insert
Expand Down Expand Up @@ -1436,7 +1436,7 @@ If SUBTHREAD is non-nil, only apply to subthread."
(if (functionp mu4e-view-auto-mark-as-read)
(funcall mu4e-view-auto-mark-as-read msg)
mu4e-view-auto-mark-as-read)))
(when-let ((buf (mu4e-get-view-buffer (current-buffer) nil)))
(when-let* ((buf (mu4e-get-view-buffer (current-buffer) nil)))
(with-current-buffer buf
(mu4e-loading-mode 1)))
(mu4e--server-view docid mark-as-read)))
Expand Down
4 changes: 2 additions & 2 deletions mu4e/mu4e-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Return the matching choice value (cdr of the cell)."
(mapconcat #'car choices ", "))))
(while (not chosen)
(message nil) ;; this seems needed...
(when-let ((kar (read-char-exclusive prompt)))
(when-let* ((kar (read-char-exclusive prompt)))
(when (eq kar ?\e) (keyboard-quit)) ;; `read-char-exclusive' is a C
;; function and doesn't check for
;; `keyboard-quit', there we need to
Expand Down Expand Up @@ -543,7 +543,7 @@ Or go to the top level if there is none."

(defun mu4e--jump-to-bookmark (bookmark)
"View the message referred to by BOOKMARK."
(when-let ((msgid (bookmark-prop-get bookmark 'message-id)))
(when-let* ((msgid (bookmark-prop-get bookmark 'message-id)))
(mu4e-view-message-with-message-id msgid)))

;;; Macros
Expand Down
2 changes: 1 addition & 1 deletion mu4e/mu4e-lists.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ e.g. public-inbox-based archives."
(defmacro mu4e-x-seq-url (base-url)
"Construct x-seq archive URL for MSG or nil if not found."
`(lambda (msg)
(when-let ((xseq (mu4e-fetch-field msg "X-Seq")))
(when-let* ((xseq (mu4e-fetch-field msg "X-Seq")))
(concat ,base-url "/" xseq))))

;;; Configuration
Expand Down
4 changes: 2 additions & 2 deletions mu4e/mu4e-message.el
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ Returns the full path."
(defun mu4e-sexp-at-point ()
"Show or hide the s-expression for the message-at-point, if any."
(interactive)
(if-let ((win (get-buffer-window mu4e--sexp-buffer-name)))
(if-let* ((win (get-buffer-window mu4e--sexp-buffer-name)))
(delete-window win)
(when-let ((msg (mu4e-message-at-point 'noerror)))
(when-let* ((msg (mu4e-message-at-point 'noerror)))
(when (buffer-live-p mu4e--sexp-buffer-name)
(kill-buffer mu4e--sexp-buffer-name))
(with-current-buffer-window
Expand Down
2 changes: 1 addition & 1 deletion mu4e/mu4e-mime-parts.el
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ There are some internal fields as well, e.g. ; subject to change:
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(when-let ((part (get-text-property (point) 'gnus-data))
(when-let* ((part (get-text-property (point) 'gnus-data))
(index (get-text-property (point) 'gnus-part)))
(when (and part (numberp index) (not (member index indices)))
(let* ((disp (mm-handle-disposition part))
Expand Down
2 changes: 1 addition & 1 deletion mu4e/mu4e-thread.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Reset individual folding states."
"Unfold thread at point and store state unless NO-SAVE is t."
(interactive)
(unless (eq (line-end-position) (point-max))
(when-let ((overlay (mu4e-thread-is-folded)))
(when-let* ((overlay (mu4e-thread-is-folded)))
(unless no-save
(mu4e-thread--save-state 'unfolded))
(delete-overlay overlay))))
Expand Down
8 changes: 4 additions & 4 deletions mu4e/mu4e-view.el
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ As a side-effect, a message that is being viewed loses its
;; buffer-local state that *must* survive is correctly copied
;; across.
(let ((linked-headers-buffer))
(when-let ((existing-buffer (mu4e-get-view-buffer nil nil)))
(when-let* ((existing-buffer (mu4e-get-view-buffer nil nil)))
;; required; this state must carry over from the killed buffer
;; to the new one.
(setq linked-headers-buffer mu4e-linked-headers-buffer)
Expand Down Expand Up @@ -749,7 +749,7 @@ determine which browser function to use."
"Refresh the message view."
;;; XXX: sometimes, side-effect: increase the header-buffers size
(interactive)
(when-let ((msg (and (derived-mode-p 'mu4e-view-mode)
(when-let* ((msg (and (derived-mode-p 'mu4e-view-mode)
mu4e--view-message)))
(mu4e-view-quit)
(mu4e-view msg)))
Expand Down Expand Up @@ -789,7 +789,7 @@ Note that for some messages, this can trigger high CPU load."
((or ':path ':maildir ':list)
(mu4e--view-gnus-insert-header field fieldval))
(':message-id
(when-let ((msgid (plist-get msg :message-id)))
(when-let* ((msgid (plist-get msg :message-id)))
(mu4e--view-gnus-insert-header field (format "<%s>" msgid))))
(':mailing-list
(let ((list (plist-get msg :list)))
Expand Down Expand Up @@ -1109,7 +1109,7 @@ Article Treatment' for more options."
;; This function assumes `gnus-article-mime-handle-alist' is sorted by
;; pertinence, i.e. the first HTML part found in it is the most important one.
(save-excursion
(if-let ((html-part
(if-let*((html-part
(seq-find (lambda (handle)
(equal (mm-handle-media-type (cdr handle))
"text/html"))
Expand Down
10 changes: 5 additions & 5 deletions mu4e/mu4e-window.el
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ This is an action function for buffer display, see Info
node `(elisp) Buffer Display Action Functions'. It should be
called only by `display-buffer' or a function directly or
indirectly called by the latter."
(when-let ((window (or (display-buffer-reuse-window buffer alist)
(when-let* ((window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-pop-up-window buffer alist)
(display-buffer-use-some-window buffer alist))))
Expand Down Expand Up @@ -364,9 +364,9 @@ and `mu4e-headers-visible-lines' or
This function is best called from the hook
`mu4e-view-rendered-hook'."
(unless (mu4e-current-buffer-type-p 'view)
(mu4e-error "Cannot resize as this is not a valid view buffer."))
(when-let (win (and mu4e-linked-headers-buffer
(get-buffer-window mu4e-linked-headers-buffer)))
(mu4e-error "Cannot resize as this is not a valid view buffer"))
(when-let* ((win (and mu4e-linked-headers-buffer
(get-buffer-window mu4e-linked-headers-buffer)))
;; This can fail for any number of reasons. If it does, we do
;; nothing. If the user has customized the window display we may
;; find it impossible to resize the window, and that should not be
Expand All @@ -377,7 +377,7 @@ This function is best called from the hook
(window-width win nil))
t t nil))
((eq mu4e-split-view 'horizontal)
(set-window-text-height win mu4e-headers-visible-lines))))))
(set-window-text-height win mu4e-headers-visible-lines)))))))

(provide 'mu4e-window)
;;; mu4e-window.el ends here

0 comments on commit b4adf32

Please sign in to comment.