emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 370d0e7 2/2: Update uses of if-let and when-let


From: Mark Oteiza
Subject: [Emacs-diffs] master 370d0e7 2/2: Update uses of if-let and when-let
Date: Tue, 12 Sep 2017 13:18:15 -0400 (EDT)

branch: master
commit 370d0e7aa7309b25fb9e974164261077b326e8e2
Author: Mark Oteiza <address@hidden>
Commit: Mark Oteiza <address@hidden>

    Update uses of if-let and when-let
    
    * lisp/dom.el (dom-previous-sibling):
    * lisp/emacs-lisp/package.el (package--with-work-buffer):
    (package--sort-deps-in-alist, package--sort-by-dependence):
    (package-install-from-archive, package-install):
    (package-menu-execute, package-menu--populate-new-package-list):
    * lisp/filenotify.el (file-notify--rm-descriptor):
    (file-notify--event-watched-file, file-notify--event-file-name):
    (file-notify--event-file1-name, file-notify-rm-watch):
    (file-notify-valid-p):
    * lisp/gnus/message.el (message-toggle-image-thumbnails):
    * lisp/gnus/nnimap.el (nnimap-request-move-article):
    * lisp/ibuf-ext.el (ibuffer-repair-saved-filters):
    * lisp/mpc.el (mpc-format):
    * lisp/net/eww.el (eww-tag-meta, eww-process-text-input):
    (eww-save-history):
    * lisp/net/shr.el (shr-tag-base, shr-tag-object, shr-make-table-1):
    * lisp/progmodes/prog-mode.el (prettify-symbols--post-command-hook):
    * lisp/svg.el (svg-remove):
    * lisp/textmodes/css-mode.el (css--named-color):
    (css--colon-inside-funcall):
    * lisp/textmodes/sgml-mode.el (html-current-buffer-classes):
    (html-current-buffer-ids): Use if-let* and when-let* instead.
---
 lisp/dom.el                 |  2 +-
 lisp/emacs-lisp/package.el  | 26 +++++++++++++-------------
 lisp/filenotify.el          | 12 ++++++------
 lisp/gnus/message.el        |  2 +-
 lisp/gnus/nnimap.el         |  2 +-
 lisp/ibuf-ext.el            |  2 +-
 lisp/mpc.el                 | 12 ++++++------
 lisp/net/eww.el             | 20 ++++++++++----------
 lisp/net/shr.el             |  6 +++---
 lisp/progmodes/prog-mode.el | 10 +++++-----
 lisp/svg.el                 |  8 ++++----
 lisp/textmodes/css-mode.el  |  4 ++--
 lisp/textmodes/sgml-mode.el |  8 ++++----
 13 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/lisp/dom.el b/lisp/dom.el
index 4d0d423..52e7f4b 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -162,7 +162,7 @@ ATTRIBUTE would typically be `class', `id' or the like."
 
 (defun dom-previous-sibling (dom node)
   "Return the previous sibling of NODE in DOM."
-  (when-let (parent (dom-parent dom node))
+  (when-let* ((parent (dom-parent dom node)))
     (let ((siblings (dom-children parent))
          (previous nil))
       (while siblings
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 889d794..7301dbd 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1192,7 +1192,7 @@ errors signaled by ERROR-FORM or by BODY).
                                                  (let ((,b-sym 
(current-buffer)))
                                                    (require 'url-handlers)
                                                    (unless-error ,body
-                                                                 (when-let 
((er (plist-get status :error)))
+                                                                 (when-let* 
((er (plist-get status :error)))
                                                                    (error 
"Error retrieving: %s %S" ,url-sym er))
                                                                  
(with-current-buffer ,b-sym
                                                                    (goto-char 
(point-min))
@@ -1770,8 +1770,8 @@ Only these packages will be in the return value an their 
cdrs are
 destructively set to nil in ONLY."
   (let ((out))
     (dolist (dep (package-desc-reqs package))
-      (when-let ((cell (assq (car dep) only))
-                 (dep-package (cdr-safe cell)))
+      (when-let* ((cell (assq (car dep) only))
+                  (dep-package (cdr-safe cell)))
         (setcdr cell nil)
         (setq out (append (package--sort-deps-in-alist dep-package only)
                           out))))
@@ -1790,7 +1790,7 @@ if all the in-between dependencies are also in 
PACKAGE-LIST."
     (dolist (cell alist out-list)
       ;; `package--sort-deps-in-alist' destructively changes alist, so
       ;; some cells might already be empty.  We check this here.
-      (when-let ((pkg-desc (cdr cell)))
+      (when-let* ((pkg-desc (cdr cell)))
         (setcdr cell nil)
         (setq out-list
               (append (package--sort-deps-in-alist pkg-desc alist)
@@ -1847,7 +1847,7 @@ if all the in-between dependencies are also in 
PACKAGE-LIST."
                ;; Update the old pkg-desc which will be shown on the 
description buffer.
                (setf (package-desc-signed pkg-desc) t)
                ;; Update the new (activated) pkg-desc as well.
-               (when-let ((pkg-descs (cdr (assq (package-desc-name pkg-desc) 
package-alist))))
+               (when-let* ((pkg-descs (cdr (assq (package-desc-name pkg-desc) 
package-alist))))
                  (setf (package-desc-signed (car pkg-descs)) t))))))))))
 
 (defun package-installed-p (package &optional min-version)
@@ -1970,12 +1970,12 @@ to install it but still mark it as selected."
     (unless (or dont-select (package--user-selected-p name))
       (package--save-selected-packages
        (cons name package-selected-packages)))
-    (if-let ((transaction
-              (if (package-desc-p pkg)
-                  (unless (package-installed-p pkg)
-                    (package-compute-transaction (list pkg)
-                                                 (package-desc-reqs pkg)))
-                (package-compute-transaction () (list (list pkg))))))
+    (if-let* ((transaction
+               (if (package-desc-p pkg)
+                   (unless (package-installed-p pkg)
+                     (package-compute-transaction (list pkg)
+                                                  (package-desc-reqs pkg)))
+                 (package-compute-transaction () (list (list pkg))))))
         (package-download-transaction transaction)
       (message "`%s' is already installed" name))))
 
@@ -3281,7 +3281,7 @@ Optional argument NOQUERY non-nil means do not ask the 
user to confirm."
           (package--update-selected-packages .install .delete)
           (package-menu--perform-transaction install-list delete-list)
           (when package-selected-packages
-            (if-let ((removable (package--removable-packages)))
+            (if-let* ((removable (package--removable-packages)))
                 (message "Package menu: Operation finished.  %d packages %s"
                   (length removable)
                   (substitute-command-keys
@@ -3353,7 +3353,7 @@ Store this list in `package-menu--new-package-list'."
 
 (defun package-menu--find-and-notify-upgrades ()
   "Notify the user of upgradable packages."
-  (when-let ((upgrades (package-menu--find-upgrades)))
+  (when-let* ((upgrades (package-menu--find-upgrades)))
     (message "%d package%s can be upgraded; type `%s' to mark %s for 
upgrading."
       (length upgrades)
       (if (= (length upgrades) 1) "" "s")
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 64cfab1..6a3b9e1 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -71,7 +71,7 @@ struct.")
   "Remove DESCRIPTOR from `file-notify-descriptors'.
 DESCRIPTOR should be an object returned by `file-notify-add-watch'.
 If it is registered in `file-notify-descriptors', a stopped event is sent."
-  (when-let (watch (gethash descriptor file-notify-descriptors))
+  (when-let* ((watch (gethash descriptor file-notify-descriptors)))
     ;; Send `stopped' event.
     (unwind-protect
         (funcall
@@ -106,12 +106,12 @@ It is a form ((DESCRIPTOR ACTION FILE [FILE1-OR-COOKIE]) 
CALLBACK).")
 (defun file-notify--event-watched-file (event)
   "Return file or directory being watched.
 Could be different from the directory watched by the backend library."
-  (when-let (watch (gethash (car event) file-notify-descriptors))
+  (when-let* ((watch (gethash (car event) file-notify-descriptors)))
     (file-notify--watch-absolute-filename watch)))
 
 (defun file-notify--event-file-name (event)
   "Return file name of file notification event, or nil."
-  (when-let (watch (gethash (car event) file-notify-descriptors))
+  (when-let* ((watch (gethash (car event) file-notify-descriptors)))
     (directory-file-name
      (expand-file-name
       (or  (and (stringp (nth 2 event)) (nth 2 event)) "")
@@ -121,7 +121,7 @@ Could be different from the directory watched by the 
backend library."
 (defun file-notify--event-file1-name (event)
   "Return second file name of file notification event, or nil.
 This is available in case a file has been moved."
-  (when-let (watch (gethash (car event) file-notify-descriptors))
+  (when-let* ((watch (gethash (car event) file-notify-descriptors)))
     (and (stringp (nth 3 event))
          (directory-file-name
           (expand-file-name
@@ -375,7 +375,7 @@ FILE is the name of the file whose event is being reported."
 (defun file-notify-rm-watch (descriptor)
   "Remove an existing watch specified by its DESCRIPTOR.
 DESCRIPTOR should be an object returned by `file-notify-add-watch'."
-  (when-let (watch (gethash descriptor file-notify-descriptors))
+  (when-let* ((watch (gethash descriptor file-notify-descriptors)))
     (let ((handler (find-file-name-handler
                     (file-notify--watch-directory watch)
                     'file-notify-rm-watch)))
@@ -399,7 +399,7 @@ DESCRIPTOR should be an object returned by 
`file-notify-add-watch'."
 (defun file-notify-valid-p (descriptor)
   "Check a watch specified by its DESCRIPTOR.
 DESCRIPTOR should be an object returned by `file-notify-add-watch'."
-  (when-let (watch (gethash descriptor file-notify-descriptors))
+  (when-let* ((watch (gethash descriptor file-notify-descriptors)))
     (let ((handler (find-file-name-handler
                     (file-notify--watch-directory watch)
                     'file-notify-valid-p)))
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 996b0ac..214cf61 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -8410,7 +8410,7 @@ Used in `message-simplify-recipients'."
     (save-excursion
       (goto-char (point-min))
       (while (not (eobp))
-       (when-let ((props (get-text-property (point) 'display)))
+       (when-let* ((props (get-text-property (point) 'display)))
          (when (and (consp props)
                     (eq (car props) 'image))
            (put-text-property (point) (1+ (point)) 'display nil)
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 2943c8d..6424d9d 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -950,7 +950,7 @@ textual parts.")
                            internal-move-group server message-id
                            nnimap-request-articles-find-limit)))))
          ;; Move the article to a different method.
-         (when-let ((result (eval accept-form)))
+         (when-let* ((result (eval accept-form)))
            (nnimap-change-group group server)
            (nnimap-delete-article article)
            result))))))
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 2a68f77..8bcd188 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -375,7 +375,7 @@ format. See `ibuffer-update-saved-filters-format' and
     (let ((fixed (ibuffer-update-saved-filters-format ibuffer-saved-filters)))
       (prog1
           (setq ibuffer-saved-filters (cdr fixed))
-        (when-let (old-format-detected (car fixed))
+        (when-let* ((old-format-detected (car fixed)))
           (let ((warning-series t)
                 (updated-form
                  (with-output-to-string
diff --git a/lisp/mpc.el b/lisp/mpc.el
index cce7527..73692e2 100644
--- a/lisp/mpc.el
+++ b/lisp/mpc.el
@@ -1029,12 +1029,12 @@ If PLAYLIST is t or nil or missing, use the main 
playlist."
                      (let ((dir (file-name-directory (cdr (assq 'file info)))))
                        ;; (debug)
                        (push `(equal ',dir (file-name-directory (cdr (assq 
'file info)))) pred)
-                       (if-let ((covers '(".folder.png" "cover.jpg" 
"folder.jpg"))
-                                (cover (cl-loop for file in (directory-files 
(mpc-file-local-copy dir))
-                                                if (member (downcase file) 
covers)
-                                                return (concat dir file)))
-                                (file (with-demoted-errors "MPC: %s"
-                                        (mpc-file-local-copy cover))))
+                       (if-let* ((covers '(".folder.png" "cover.jpg" 
"folder.jpg"))
+                                 (cover (cl-loop for file in (directory-files 
(mpc-file-local-copy dir))
+                                                 if (member (downcase file) 
covers)
+                                                 return (concat dir file)))
+                                 (file (with-demoted-errors "MPC: %s"
+                                         (mpc-file-local-copy cover))))
                            (let (image)
                              (if (null size) (setq image (create-image file))
                                (let ((tempfile (make-temp-file "mpc" nil 
".jpg")))
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 03d9172..2938e35 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -521,7 +521,7 @@ Currently this means either text/html or 
application/xhtml+xml."
 (defun eww-tag-meta (dom)
   (when (and (cl-equalp (dom-attr dom 'http-equiv) "refresh")
              (< eww-redirect-level 5))
-    (when-let (refresh (dom-attr dom 'content))
+    (when-let* ((refresh (dom-attr dom 'content)))
       (when (or (string-match "^\\([0-9]+\\) *;.*url=\"\\([^\"]+\\)\"" refresh)
                 (string-match "^\\([0-9]+\\) *;.*url='\\([^']+\\)'" refresh)
                 (string-match "^\\([0-9]+\\) *;.*url=\\([^ ]+\\)" refresh))
@@ -1110,13 +1110,13 @@ just re-display the HTML already fetched."
 See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
 
 (defun eww-process-text-input (beg end replace-length)
-  (when-let (pos (and (< (1+ end) (point-max))
-                     (> (1- end) (point-min))
-                     (cond
-                      ((get-text-property (1+ end) 'eww-form)
-                       (1+ end))
-                      ((get-text-property (1- end) 'eww-form)
-                       (1- end)))))
+  (when-let* ((pos (and (< (1+ end) (point-max))
+                       (> (1- end) (point-min))
+                       (cond
+                        ((get-text-property (1+ end) 'eww-form)
+                         (1+ end))
+                        ((get-text-property (1- end) 'eww-form)
+                         (1- end))))))
     (let* ((form (get-text-property pos 'eww-form))
           (properties (text-properties-at pos))
            (buffer-undo-list t)
@@ -1799,8 +1799,8 @@ If CHARSET is nil then use UTF-8."
   (setq eww-data (list :title ""))
   ;; Don't let the history grow infinitely.  We store quite a lot of
   ;; data per page.
-  (when-let (tail (and eww-history-limit
-                      (nthcdr eww-history-limit eww-history)))
+  (when-let* ((tail (and eww-history-limit
+                        (nthcdr eww-history-limit eww-history))))
     (setcdr tail nil)))
 
 (defvar eww-current-buffer)
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index fe93fc3..cb915da 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1363,7 +1363,7 @@ ones, in case fg and bg are nil."
       plist)))
 
 (defun shr-tag-base (dom)
-  (when-let (base (dom-attr dom 'href))
+  (when-let* ((base (dom-attr dom 'href)))
     (setq shr-base (shr-parse-base base)))
   (shr-generic dom))
 
@@ -1388,7 +1388,7 @@ ones, in case fg and bg are nil."
   (unless shr-inhibit-images
     (let ((start (point))
          url multimedia image)
-      (when-let (type (dom-attr dom 'type))
+      (when-let* ((type (dom-attr dom 'type)))
        (when (string-match "\\`image/svg" type)
          (setq url (dom-attr dom 'data)
                image t)))
@@ -2178,7 +2178,7 @@ flags that control whether to collect or render objects."
            (when (and (not (stringp column))
                       (or (memq (dom-tag column) '(td th))
                           (not column)))
-             (when-let (span (dom-attr column 'rowspan))
+             (when-let* ((span (dom-attr column 'rowspan)))
                (aset rowspans i (+ (aref rowspans i)
                                    (1- (string-to-number span)))))
              ;; Sanity check for invalid column-spans.
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 8f66f1c..eddaa89 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -225,11 +225,11 @@ on the symbol."
       (apply #'font-lock-flush prettify-symbols--current-symbol-bounds)
       (setq prettify-symbols--current-symbol-bounds nil))
     ;; Unprettify the current symbol.
-    (when-let ((c (get-prop-as-list 'composition))
-              (s (get-prop-as-list 'prettify-symbols-start))
-              (e (get-prop-as-list 'prettify-symbols-end))
-              (s (apply #'min s))
-              (e (apply #'max e)))
+    (when-let* ((c (get-prop-as-list 'composition))
+               (s (get-prop-as-list 'prettify-symbols-start))
+               (e (get-prop-as-list 'prettify-symbols-end))
+               (s (apply #'min s))
+               (e (apply #'max e)))
       (with-silent-modifications
        (setq prettify-symbols--current-symbol-bounds (list s e))
        (remove-text-properties s e '(composition))))))
diff --git a/lisp/svg.el b/lisp/svg.el
index fc1a6d6..8310eba 100644
--- a/lisp/svg.el
+++ b/lisp/svg.el
@@ -264,10 +264,10 @@ If the SVG is later changed, the image will also be 
updated."
 
 (defun svg-remove (svg id)
   "Remove the element identified by ID from SVG."
-  (when-let ((node (car (dom-by-id
-                         svg
-                         (concat "\\`" (regexp-quote id)
-                                 "\\'")))))
+  (when-let* ((node (car (dom-by-id
+                          svg
+                          (concat "\\`" (regexp-quote id)
+                                  "\\'")))))
     (dom-remove-node svg node)))
 
 (provide 'svg)
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 1e49ca8..44ba870 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1045,7 +1045,7 @@ This function simply drops any transparency."
   "Check whether STR, seen at point, is CSS named color.
 Returns STR if it is a valid color.  Special care is taken
 to exclude some SCSS constructs."
-  (when-let ((color (assoc str css--color-map)))
+  (when-let* ((color (assoc str css--color-map)))
     (save-excursion
       (goto-char start-point)
       (forward-comment (- (point)))
@@ -1154,7 +1154,7 @@ for determining whether point is within a selector."
 
 (defun css--colon-inside-funcall ()
   "Return t if point is inside a function call."
-  (when-let (opening-paren-pos (nth 1 (syntax-ppss)))
+  (when-let* ((opening-paren-pos (nth 1 (syntax-ppss))))
     (save-excursion
       (goto-char opening-paren-pos)
       (eq (char-after) ?\())))
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 1f99786..78fbbb5 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -2242,8 +2242,8 @@ The result is cached in `html--buffer-classes-cache'."
              (classes
               (seq-mapcat
                (lambda (el)
-                 (when-let (class-list
-                            (cdr (assq 'class (dom-attributes el))))
+                 (when-let* ((class-list
+                              (cdr (assq 'class (dom-attributes el)))))
                    (split-string class-list)))
                (dom-by-class dom ""))))
         (setq-local html--buffer-classes-cache (cons tick classes))
@@ -2260,8 +2260,8 @@ The result is cached in `html--buffer-ids-cache'."
              (ids
               (seq-mapcat
                (lambda (el)
-                 (when-let (id-list
-                            (cdr (assq 'id (dom-attributes el))))
+                 (when-let* ((id-list
+                              (cdr (assq 'id (dom-attributes el)))))
                    (split-string id-list)))
                (dom-by-id dom ""))))
         (setq-local html--buffer-ids-cache (cons tick ids))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]