Skip to content

Commit b34057a

Browse files
xiongtxbbatsov
authored andcommitted
Replace if-let and when-let with starred versions
Fix #2130. Emacs 26 obsoletes `if-let` and `when-let`, replacing them with `if-let*` and `when-let*`. This raises byte-compilation warnings (treated as errors) when testing against Emacs 26. See: http://git.savannah.gnu.org/cgit/emacs.git/tree/etc/NEWS?h=emacs-26#n1278
1 parent b484daa commit b34057a

25 files changed

+206
-206
lines changed

cider-apropos.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ optionally search doc strings (based on DOCS-P), include private vars
144144
(y-or-n-p "Case-sensitive? ")))))
145145
(cider-ensure-connected)
146146
(cider-ensure-op-supported "apropos")
147-
(if-let ((summary (cider-apropos-summary
148-
query ns docs-p privates-p case-sensitive-p))
149-
(results (cider-sync-request:apropos query ns docs-p privates-p case-sensitive-p)))
147+
(if-let* ((summary (cider-apropos-summary
148+
query ns docs-p privates-p case-sensitive-p))
149+
(results (cider-sync-request:apropos query ns docs-p privates-p case-sensitive-p)))
150150
(cider-show-apropos summary results query docs-p)
151151
(message "No apropos matches for %S" query)))
152152

@@ -191,10 +191,10 @@ optionally search doc strings (based on DOCS-P), include private vars
191191
(y-or-n-p "Case-sensitive? ")))))
192192
(cider-ensure-connected)
193193
(cider-ensure-op-supported "apropos")
194-
(if-let ((summary (cider-apropos-summary
195-
query ns docs-p privates-p case-sensitive-p))
196-
(results (mapcar (lambda (r) (nrepl-dict-get r "name"))
197-
(cider-sync-request:apropos query ns docs-p privates-p case-sensitive-p))))
194+
(if-let* ((summary (cider-apropos-summary
195+
query ns docs-p privates-p case-sensitive-p))
196+
(results (mapcar (lambda (r) (nrepl-dict-get r "name"))
197+
(cider-sync-request:apropos query ns docs-p privates-p case-sensitive-p))))
198198
(cider-apropos-act-on-symbol (completing-read (concat summary ": ") results))
199199
(message "No apropos matches for %S" query)))
200200

cider-browse-spec.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ may also be a button, so this function can be used a the button's `action'
282282
property."
283283
(interactive)
284284
(let ((pos (or pos (point))))
285-
(when-let ((spec (button-get pos 'spec-name)))
285+
(when-let* ((spec (button-get pos 'spec-name)))
286286
(cider-browse-spec--browse spec))))
287287

288288
;; Interactive Functions
@@ -292,8 +292,8 @@ property."
292292
(interactive)
293293
(cider-ensure-connected)
294294
(cider-ensure-op-supported "spec-example")
295-
(if-let ((spec cider-browse-spec--current-spec))
296-
(if-let ((example (cider-sync-request:spec-example spec)))
295+
(if-let* ((spec cider-browse-spec--current-spec))
296+
(if-let* ((example (cider-sync-request:spec-example spec)))
297297
(with-current-buffer (cider-popup-buffer cider-browse-spec-example-buffer t)
298298
(cider-browse-spec-example-mode)
299299
(setq-local cider-browse-spec--current-spec spec)

cider-classpath.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
(interactive)
105105
(cider-ensure-connected)
106106
(cider-ensure-op-supported "classpath")
107-
(when-let ((entry (completing-read "Classpath entries: " (cider-sync-request:classpath))))
107+
(when-let* ((entry (completing-read "Classpath entries: " (cider-sync-request:classpath))))
108108
(find-file-other-window entry)))
109109

110110
(provide 'cider-classpath)

cider-client.el

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ precedence over other connections associated with the same project.
161161
162162
If ALL-CONNECTIONS is non-nil, the return value is a list and all matching
163163
connections are returned, instead of just the most recent."
164-
(when-let ((project-directory (or project-directory
164+
(when-let* ((project-directory (or project-directory
165165
(clojure-project-dir (cider-current-dir))))
166166
(fn (if all-connections #'seq-filter #'seq-find)))
167167
(or (funcall fn (lambda (conn)
168-
(when-let ((conn-proj-dir (with-current-buffer conn
168+
(when-let* ((conn-proj-dir (with-current-buffer conn
169169
nrepl-project-dir)))
170170
(equal (file-truename project-directory)
171171
(file-truename conn-proj-dir))))
@@ -304,7 +304,7 @@ at all."
304304
"Return the first connection of another type than CONNECTION.
305305
Only return connections in the same project or nil.
306306
CONNECTION defaults to `cider-current-connection'."
307-
(when-let ((connection (or connection (cider-current-connection)))
307+
(when-let* ((connection (or connection (cider-current-connection)))
308308
(connection-type (cider--connection-type connection)))
309309
(cider-current-connection (pcase connection-type
310310
(`"clj" "cljs")
@@ -317,7 +317,7 @@ CONNECTION defaults to `cider-current-connection'."
317317
DO NOT USE THIS FUNCTION.
318318
It was written only to be used in `cider-map-connections', as a workaround
319319
to a still-undetermined bug in the state-stracker backend."
320-
(when-let ((project-connections (cider-find-connection-buffer-for-project-directory
320+
(when-let* ((project-connections (cider-find-connection-buffer-for-project-directory
321321
nil :all-connections))
322322
(cljs-conn
323323
;; So we have multiple connections. Look for the connection type we
@@ -387,7 +387,7 @@ connection but can be invoked from any buffer (like `cider-refresh')."
387387
((err "needs a ClojureScript REPL")))))))
388388
(funcall function curr)
389389
(when (eq which :both)
390-
(when-let ((other-connection (cider-other-connection curr)))
390+
(when-let* ((other-connection (cider-other-connection curr)))
391391
(funcall function other-connection))))))
392392

393393

@@ -417,7 +417,7 @@ connection but can be invoked from any buffer (like `cider-refresh')."
417417
(defun cider-connection-browser ()
418418
"Open a browser buffer for nREPL connections."
419419
(interactive)
420-
(if-let ((buffer (get-buffer cider--connection-browser-buffer-name)))
420+
(if-let* ((buffer (get-buffer cider--connection-browser-buffer-name)))
421421
(progn
422422
(cider--connections-refresh-buffer buffer)
423423
(unless (get-buffer-window buffer)
@@ -428,7 +428,7 @@ connection but can be invoked from any buffer (like `cider-refresh')."
428428
"Refresh the connections buffer, if the buffer exists.
429429
The connections buffer is determined by
430430
`cider--connection-browser-buffer-name'"
431-
(when-let ((buffer (get-buffer cider--connection-browser-buffer-name)))
431+
(when-let* ((buffer (get-buffer cider--connection-browser-buffer-name)))
432432
(cider--connections-refresh-buffer buffer)))
433433

434434
(add-hook 'nrepl-disconnected-hook #'cider--connections-refresh)
@@ -620,7 +620,7 @@ REPL's ns, otherwise fall back to \"user\".
620620
When NO-DEFAULT is non-nil, it will return nil instead of \"user\"."
621621
(or cider-buffer-ns
622622
(clojure-find-ns)
623-
(when-let ((repl-buf (cider-current-connection)))
623+
(when-let* ((repl-buf (cider-current-connection)))
624624
(buffer-local-value 'cider-buffer-ns repl-buf))
625625
(if no-default nil "user")))
626626

@@ -833,15 +833,15 @@ unless ALL is truthy."
833833
"Find the definition of VAR, optionally at a specific LINE.
834834
835835
Display the results in a different window."
836-
(if-let ((info (cider-var-info var)))
836+
(if-let* ((info (cider-var-info var)))
837837
(progn
838838
(if line (setq info (nrepl-dict-put info "line" line)))
839839
(cider--jump-to-loc-from-info info t))
840840
(user-error "Symbol `%s' not resolved" var)))
841841

842842
(defun cider--find-var (var &optional line)
843843
"Find the definition of VAR, optionally at a specific LINE."
844-
(if-let ((info (cider-var-info var)))
844+
(if-let* ((info (cider-var-info var)))
845845
(progn
846846
(if line (setq info (nrepl-dict-put info "line" line)))
847847
(cider--jump-to-loc-from-info info))
@@ -929,11 +929,11 @@ Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P."
929929
(defun cider-sync-request:complete (str context)
930930
"Return a list of completions for STR using nREPL's \"complete\" op.
931931
CONTEXT represents a completion context for compliment."
932-
(when-let ((dict (thread-first `("op" "complete"
933-
"ns" ,(cider-current-ns)
934-
"symbol" ,str
935-
"context" ,context)
936-
(cider-nrepl-send-sync-request nil 'abort-on-input))))
932+
(when-let* ((dict (thread-first `("op" "complete"
933+
"ns" ,(cider-current-ns)
934+
"symbol" ,str
935+
"context" ,context)
936+
(cider-nrepl-send-sync-request nil 'abort-on-input))))
937937
(nrepl-dict-get dict "completions")))
938938

939939
(defun cider-sync-request:complete-flush-caches ()
@@ -956,22 +956,22 @@ CONTEXT represents a completion context for compliment."
956956

957957
(defun cider-sync-request:eldoc (symbol &optional class member)
958958
"Send \"eldoc\" op with parameters SYMBOL or CLASS and MEMBER."
959-
(when-let ((eldoc (thread-first `("op" "eldoc"
960-
"ns" ,(cider-current-ns)
961-
,@(when symbol `("symbol" ,symbol))
962-
,@(when class `("class" ,class))
963-
,@(when member `("member" ,member)))
964-
(cider-nrepl-send-sync-request nil 'abort-on-input))))
959+
(when-let* ((eldoc (thread-first `("op" "eldoc"
960+
"ns" ,(cider-current-ns)
961+
,@(when symbol `("symbol" ,symbol))
962+
,@(when class `("class" ,class))
963+
,@(when member `("member" ,member)))
964+
(cider-nrepl-send-sync-request nil 'abort-on-input))))
965965
(if (member "no-eldoc" (nrepl-dict-get eldoc "status"))
966966
nil
967967
eldoc)))
968968

969969
(defun cider-sync-request:eldoc-datomic-query (symbol)
970970
"Send \"eldoc-datomic-query\" op with parameter SYMBOL."
971-
(when-let ((eldoc (thread-first `("op" "eldoc-datomic-query"
972-
"ns" ,(cider-current-ns)
973-
,@(when symbol `("symbol" ,symbol)))
974-
(cider-nrepl-send-sync-request nil 'abort-on-input))))
971+
(when-let* ((eldoc (thread-first `("op" "eldoc-datomic-query"
972+
"ns" ,(cider-current-ns)
973+
,@(when symbol `("symbol" ,symbol)))
974+
(cider-nrepl-send-sync-request nil 'abort-on-input))))
975975
(if (member "no-eldoc" (nrepl-dict-get eldoc "status"))
976976
nil
977977
eldoc)))

cider-common.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ relative, it is expanded within each of the open Clojure buffers till an
192192
existing file ending with URL has been found."
193193
(require 'arc-mode)
194194
(cond ((string-match "^file:\\(.+\\)" url)
195-
(when-let ((file (cider--url-to-file (match-string 1 url)))
196-
(path (cider--file-path file)))
195+
(when-let* ((file (cider--url-to-file (match-string 1 url)))
196+
(path (cider--file-path file)))
197197
(find-file-noselect path)))
198198
((string-match "^\\(jar\\|zip\\):\\(file:.+\\)!/\\(.+\\)" url)
199-
(when-let ((entry (match-string 3 url))
200-
(file (cider--url-to-file (match-string 2 url)))
201-
(path (cider--file-path file))
202-
(name (format "%s:%s" path entry)))
199+
(when-let* ((entry (match-string 3 url))
200+
(file (cider--url-to-file (match-string 2 url)))
201+
(path (cider--file-path file))
202+
(name (format "%s:%s" path entry)))
203203
(or (find-buffer-visiting name)
204204
(if (tramp-tramp-file-p path)
205205
(progn
@@ -223,7 +223,7 @@ existing file ending with URL has been found."
223223
(set-buffer-modified-p nil)
224224
(set-auto-mode)
225225
(current-buffer))))))
226-
(t (if-let ((path (cider--file-path url)))
226+
(t (if-let* ((path (cider--file-path url)))
227227
(find-file-noselect path)
228228
(unless (file-name-absolute-p url)
229229
(let ((cider-buffers (cider-util--clojure-buffers))

cider-compat.el

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ threading."
125125

126126
(eval-and-compile
127127

128-
(unless (fboundp 'if-let)
129-
(defmacro if-let (bindings then &rest else)
128+
(unless (fboundp 'if-let*)
129+
(defmacro if-let* (bindings then &rest else)
130130
"Process BINDINGS and if all values are non-nil eval THEN, else ELSE.
131131
Argument BINDINGS is a list of tuples whose car is a symbol to be
132132
bound and (optionally) used in THEN, and its cadr is a sexp to be
@@ -143,15 +143,15 @@ to bind a single value, BINDINGS can just be a plain tuple."
143143
,then
144144
,@else))))
145145

146-
(unless (fboundp 'when-let)
147-
(defmacro when-let (bindings &rest body)
146+
(unless (fboundp 'when-let*)
147+
(defmacro when-let* (bindings &rest body)
148148
"Process BINDINGS and if all values are non-nil eval BODY.
149149
Argument BINDINGS is a list of tuples whose car is a symbol to be
150150
bound and (optionally) used in BODY, and its cadr is a sexp to be
151151
evalled to set symbol's value. In the special case you only want
152152
to bind a single value, BINDINGS can just be a plain tuple."
153-
(declare (indent 1) (debug if-let))
154-
`(if-let ,bindings ,(macroexp-progn body)))))
153+
(declare (indent 1) (debug if-let*))
154+
`(if-let* ,bindings ,(macroexp-progn body)))))
155155

156156
(eval-and-compile
157157

cider-debug.el

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ This variable must be set before starting the repl connection."
122122
(defun cider-browse-instrumented-defs ()
123123
"List all instrumented definitions."
124124
(interactive)
125-
(if-let ((all (thread-first (cider-nrepl-send-sync-request '("op" "debug-instrumented-defs"))
126-
(nrepl-dict-get "list"))))
125+
(if-let* ((all (thread-first (cider-nrepl-send-sync-request '("op" "debug-instrumented-defs"))
126+
(nrepl-dict-get "list"))))
127127
(with-current-buffer (cider-popup-buffer cider-browse-ns-buffer t)
128128
(let ((inhibit-read-only t))
129129
(erase-buffer)
@@ -230,7 +230,7 @@ Each element of LOCALS should be a list of at least two elements."
230230
(format (propertize "%s\n" 'face 'default)
231231
(string-join
232232
(nrepl-dict-map (lambda (char cmd)
233-
(when-let ((pos (cl-search char cmd)))
233+
(when-let* ((pos (cl-search char cmd)))
234234
(put-text-property pos (1+ pos) 'face 'cider-debug-prompt-face cmd))
235235
cmd)
236236
command-dict)
@@ -343,8 +343,8 @@ In order to work properly, this mode must be activated by
343343
;; We wait a moment before clearing overlays and the read-onlyness, so that
344344
;; cider-nrepl has a chance to send the next message, and so that the user
345345
;; doesn't accidentally hit `n' between two messages (thus editing the code).
346-
(when-let ((proc (unless nrepl-ongoing-sync-request
347-
(get-buffer-process (cider-current-connection)))))
346+
(when-let* ((proc (unless nrepl-ongoing-sync-request
347+
(get-buffer-process (cider-current-connection)))))
348348
(accept-process-output proc 1))
349349
(unless cider--debug-mode
350350
(setq buffer-read-only nil)
@@ -443,7 +443,7 @@ Return trimmed CODE."
443443
ID is the id of the message that instrumented CODE.
444444
REASON is a keyword describing why this buffer was necessary."
445445
(let ((buffer-name (format cider--debug-buffer-format id)))
446-
(if-let ((buffer (get-buffer buffer-name)))
446+
(if-let* ((buffer (get-buffer buffer-name)))
447447
(cider-popup-buffer-display buffer 'select)
448448
(with-current-buffer (cider-popup-buffer buffer-name 'select
449449
#'clojure-mode 'ancillary)
@@ -465,7 +465,7 @@ REASON is a keyword describing why this buffer was necessary."
465465

466466
(defun cider--debug-goto-keyval (key)
467467
"Find KEY in current sexp or return nil."
468-
(when-let ((limit (ignore-errors (save-excursion (up-list) (point)))))
468+
(when-let* ((limit (ignore-errors (save-excursion (up-list) (point)))))
469469
(search-forward-regexp (concat "\\_<" (regexp-quote key) "\\_>")
470470
limit 'noerror)))
471471

@@ -580,9 +580,9 @@ is a coordinate measure in sexps."
580580
(save-excursion
581581
(let ((out))
582582
;; We prefer in-source debugging.
583-
(when-let ((buf (and file line column
584-
(ignore-errors
585-
(cider--find-buffer-for-file file)))))
583+
(when-let* ((buf (and file line column
584+
(ignore-errors
585+
(cider--find-buffer-for-file file)))))
586586
;; The logic here makes it hard to use `with-current-buffer'.
587587
(with-current-buffer buf
588588
;; This is for restoring point inside buf.
@@ -648,7 +648,7 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
648648
RESPONSE is a message received from the nrepl describing the value and
649649
coordinates of a sexp. Create an overlay after the specified sexp
650650
displaying its value."
651-
(when-let ((marker (cider--debug-find-source-position response)))
651+
(when-let* ((marker (cider--debug-find-source-position response)))
652652
(with-current-buffer (marker-buffer marker)
653653
(save-excursion
654654
(goto-char marker)

cider-doc.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ opposite of what that option dictates."
226226
"Open the source for the current symbol, if available."
227227
(interactive)
228228
(if cider-docview-file
229-
(if-let ((buffer (and (not (cider--tooling-file-p cider-docview-file))
230-
(cider-find-file cider-docview-file))))
229+
(if-let* ((buffer (and (not (cider--tooling-file-p cider-docview-file))
230+
(cider-find-file cider-docview-file))))
231231
(cider-jump-to buffer (if cider-docview-line
232232
(cons cider-docview-line nil)
233233
cider-docview-symbol)
@@ -262,12 +262,12 @@ opposite of what that option dictates."
262262

263263
(defun cider-create-doc-buffer (symbol)
264264
"Populates *cider-doc* with the documentation for SYMBOL."
265-
(when-let ((info (cider-var-info symbol)))
265+
(when-let* ((info (cider-var-info symbol)))
266266
(cider-docview-render (cider-make-popup-buffer cider-doc-buffer) symbol info)))
267267

268268
(defun cider-doc-lookup (symbol)
269269
"Look up documentation for SYMBOL."
270-
(if-let ((buffer (cider-create-doc-buffer symbol)))
270+
(if-let* ((buffer (cider-create-doc-buffer symbol)))
271271
(cider-popup-buffer-display buffer cider-doc-auto-select-buffer)
272272
(user-error "Symbol %s not resolved" symbol)))
273273

@@ -396,9 +396,9 @@ Tables are marked to be ignored by line wrap."
396396
(depr (nrepl-dict-get info "deprecated"))
397397
(macro (nrepl-dict-get info "macro"))
398398
(special (nrepl-dict-get info "special-form"))
399-
(forms (when-let ((str (nrepl-dict-get info "forms-str")))
399+
(forms (when-let* ((str (nrepl-dict-get info "forms-str")))
400400
(split-string str "\n")))
401-
(args (when-let ((str (nrepl-dict-get info "arglists-str")))
401+
(args (when-let* ((str (nrepl-dict-get info "arglists-str")))
402402
(split-string str "\n")))
403403
(doc (or (nrepl-dict-get info "doc")
404404
"Not documented."))
@@ -428,7 +428,7 @@ Tables are marked to be ignored by line wrap."
428428
(emit (concat " "(cider-font-lock-as 'java-mode iface)))))
429429
(when (or super ifaces)
430430
(insert "\n"))
431-
(when-let ((forms (or forms args)))
431+
(when-let* ((forms (or forms args)))
432432
(dolist (form forms)
433433
(insert " ")
434434
(emit (cider-font-lock-as-clojure form))))

0 commit comments

Comments
 (0)