Skip to content

Commit

Permalink
Replace if-let and when-let with starred versions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xiongtx authored and bbatsov committed Dec 11, 2017
1 parent b484daa commit b34057a
Show file tree
Hide file tree
Showing 25 changed files with 206 additions and 206 deletions.
14 changes: 7 additions & 7 deletions cider-apropos.el
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ optionally search doc strings (based on DOCS-P), include private vars
(y-or-n-p "Case-sensitive? ")))))
(cider-ensure-connected)
(cider-ensure-op-supported "apropos")
(if-let ((summary (cider-apropos-summary
query ns docs-p privates-p case-sensitive-p))
(results (cider-sync-request:apropos query ns docs-p privates-p case-sensitive-p)))
(if-let* ((summary (cider-apropos-summary
query ns docs-p privates-p case-sensitive-p))
(results (cider-sync-request:apropos query ns docs-p privates-p case-sensitive-p)))
(cider-show-apropos summary results query docs-p)
(message "No apropos matches for %S" query)))

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

Expand Down
6 changes: 3 additions & 3 deletions cider-browse-spec.el
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ may also be a button, so this function can be used a the button's `action'
property."
(interactive)
(let ((pos (or pos (point))))
(when-let ((spec (button-get pos 'spec-name)))
(when-let* ((spec (button-get pos 'spec-name)))
(cider-browse-spec--browse spec))))

;; Interactive Functions
Expand All @@ -292,8 +292,8 @@ property."
(interactive)
(cider-ensure-connected)
(cider-ensure-op-supported "spec-example")
(if-let ((spec cider-browse-spec--current-spec))
(if-let ((example (cider-sync-request:spec-example spec)))
(if-let* ((spec cider-browse-spec--current-spec))
(if-let* ((example (cider-sync-request:spec-example spec)))
(with-current-buffer (cider-popup-buffer cider-browse-spec-example-buffer t)
(cider-browse-spec-example-mode)
(setq-local cider-browse-spec--current-spec spec)
Expand Down
2 changes: 1 addition & 1 deletion cider-classpath.el
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
(interactive)
(cider-ensure-connected)
(cider-ensure-op-supported "classpath")
(when-let ((entry (completing-read "Classpath entries: " (cider-sync-request:classpath))))
(when-let* ((entry (completing-read "Classpath entries: " (cider-sync-request:classpath))))
(find-file-other-window entry)))

(provide 'cider-classpath)
Expand Down
50 changes: 25 additions & 25 deletions cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ precedence over other connections associated with the same project.
If ALL-CONNECTIONS is non-nil, the return value is a list and all matching
connections are returned, instead of just the most recent."
(when-let ((project-directory (or project-directory
(when-let* ((project-directory (or project-directory
(clojure-project-dir (cider-current-dir))))
(fn (if all-connections #'seq-filter #'seq-find)))
(or (funcall fn (lambda (conn)
(when-let ((conn-proj-dir (with-current-buffer conn
(when-let* ((conn-proj-dir (with-current-buffer conn
nrepl-project-dir)))
(equal (file-truename project-directory)
(file-truename conn-proj-dir))))
Expand Down Expand Up @@ -304,7 +304,7 @@ at all."
"Return the first connection of another type than CONNECTION.
Only return connections in the same project or nil.
CONNECTION defaults to `cider-current-connection'."
(when-let ((connection (or connection (cider-current-connection)))
(when-let* ((connection (or connection (cider-current-connection)))
(connection-type (cider--connection-type connection)))
(cider-current-connection (pcase connection-type
(`"clj" "cljs")
Expand All @@ -317,7 +317,7 @@ CONNECTION defaults to `cider-current-connection'."
DO NOT USE THIS FUNCTION.
It was written only to be used in `cider-map-connections', as a workaround
to a still-undetermined bug in the state-stracker backend."
(when-let ((project-connections (cider-find-connection-buffer-for-project-directory
(when-let* ((project-connections (cider-find-connection-buffer-for-project-directory
nil :all-connections))
(cljs-conn
;; So we have multiple connections. Look for the connection type we
Expand Down Expand Up @@ -387,7 +387,7 @@ connection but can be invoked from any buffer (like `cider-refresh')."
((err "needs a ClojureScript REPL")))))))
(funcall function curr)
(when (eq which :both)
(when-let ((other-connection (cider-other-connection curr)))
(when-let* ((other-connection (cider-other-connection curr)))
(funcall function other-connection))))))


Expand Down Expand Up @@ -417,7 +417,7 @@ connection but can be invoked from any buffer (like `cider-refresh')."
(defun cider-connection-browser ()
"Open a browser buffer for nREPL connections."
(interactive)
(if-let ((buffer (get-buffer cider--connection-browser-buffer-name)))
(if-let* ((buffer (get-buffer cider--connection-browser-buffer-name)))
(progn
(cider--connections-refresh-buffer buffer)
(unless (get-buffer-window buffer)
Expand All @@ -428,7 +428,7 @@ connection but can be invoked from any buffer (like `cider-refresh')."
"Refresh the connections buffer, if the buffer exists.
The connections buffer is determined by
`cider--connection-browser-buffer-name'"
(when-let ((buffer (get-buffer cider--connection-browser-buffer-name)))
(when-let* ((buffer (get-buffer cider--connection-browser-buffer-name)))
(cider--connections-refresh-buffer buffer)))

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

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

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

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

(defun cider-sync-request:eldoc (symbol &optional class member)
"Send \"eldoc\" op with parameters SYMBOL or CLASS and MEMBER."
(when-let ((eldoc (thread-first `("op" "eldoc"
"ns" ,(cider-current-ns)
,@(when symbol `("symbol" ,symbol))
,@(when class `("class" ,class))
,@(when member `("member" ,member)))
(cider-nrepl-send-sync-request nil 'abort-on-input))))
(when-let* ((eldoc (thread-first `("op" "eldoc"
"ns" ,(cider-current-ns)
,@(when symbol `("symbol" ,symbol))
,@(when class `("class" ,class))
,@(when member `("member" ,member)))
(cider-nrepl-send-sync-request nil 'abort-on-input))))
(if (member "no-eldoc" (nrepl-dict-get eldoc "status"))
nil
eldoc)))

(defun cider-sync-request:eldoc-datomic-query (symbol)
"Send \"eldoc-datomic-query\" op with parameter SYMBOL."
(when-let ((eldoc (thread-first `("op" "eldoc-datomic-query"
"ns" ,(cider-current-ns)
,@(when symbol `("symbol" ,symbol)))
(cider-nrepl-send-sync-request nil 'abort-on-input))))
(when-let* ((eldoc (thread-first `("op" "eldoc-datomic-query"
"ns" ,(cider-current-ns)
,@(when symbol `("symbol" ,symbol)))
(cider-nrepl-send-sync-request nil 'abort-on-input))))
(if (member "no-eldoc" (nrepl-dict-get eldoc "status"))
nil
eldoc)))
Expand Down
14 changes: 7 additions & 7 deletions cider-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ relative, it is expanded within each of the open Clojure buffers till an
existing file ending with URL has been found."
(require 'arc-mode)
(cond ((string-match "^file:\\(.+\\)" url)
(when-let ((file (cider--url-to-file (match-string 1 url)))
(path (cider--file-path file)))
(when-let* ((file (cider--url-to-file (match-string 1 url)))
(path (cider--file-path file)))
(find-file-noselect path)))
((string-match "^\\(jar\\|zip\\):\\(file:.+\\)!/\\(.+\\)" url)
(when-let ((entry (match-string 3 url))
(file (cider--url-to-file (match-string 2 url)))
(path (cider--file-path file))
(name (format "%s:%s" path entry)))
(when-let* ((entry (match-string 3 url))
(file (cider--url-to-file (match-string 2 url)))
(path (cider--file-path file))
(name (format "%s:%s" path entry)))
(or (find-buffer-visiting name)
(if (tramp-tramp-file-p path)
(progn
Expand All @@ -223,7 +223,7 @@ existing file ending with URL has been found."
(set-buffer-modified-p nil)
(set-auto-mode)
(current-buffer))))))
(t (if-let ((path (cider--file-path url)))
(t (if-let* ((path (cider--file-path url)))
(find-file-noselect path)
(unless (file-name-absolute-p url)
(let ((cider-buffers (cider-util--clojure-buffers))
Expand Down
12 changes: 6 additions & 6 deletions cider-compat.el
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ threading."

(eval-and-compile

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

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

(eval-and-compile

Expand Down
22 changes: 11 additions & 11 deletions cider-debug.el
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ This variable must be set before starting the repl connection."
(defun cider-browse-instrumented-defs ()
"List all instrumented definitions."
(interactive)
(if-let ((all (thread-first (cider-nrepl-send-sync-request '("op" "debug-instrumented-defs"))
(nrepl-dict-get "list"))))
(if-let* ((all (thread-first (cider-nrepl-send-sync-request '("op" "debug-instrumented-defs"))
(nrepl-dict-get "list"))))
(with-current-buffer (cider-popup-buffer cider-browse-ns-buffer t)
(let ((inhibit-read-only t))
(erase-buffer)
Expand Down Expand Up @@ -230,7 +230,7 @@ Each element of LOCALS should be a list of at least two elements."
(format (propertize "%s\n" 'face 'default)
(string-join
(nrepl-dict-map (lambda (char cmd)
(when-let ((pos (cl-search char cmd)))
(when-let* ((pos (cl-search char cmd)))
(put-text-property pos (1+ pos) 'face 'cider-debug-prompt-face cmd))
cmd)
command-dict)
Expand Down Expand Up @@ -343,8 +343,8 @@ In order to work properly, this mode must be activated by
;; We wait a moment before clearing overlays and the read-onlyness, so that
;; cider-nrepl has a chance to send the next message, and so that the user
;; doesn't accidentally hit `n' between two messages (thus editing the code).
(when-let ((proc (unless nrepl-ongoing-sync-request
(get-buffer-process (cider-current-connection)))))
(when-let* ((proc (unless nrepl-ongoing-sync-request
(get-buffer-process (cider-current-connection)))))
(accept-process-output proc 1))
(unless cider--debug-mode
(setq buffer-read-only nil)
Expand Down Expand Up @@ -443,7 +443,7 @@ Return trimmed CODE."
ID is the id of the message that instrumented CODE.
REASON is a keyword describing why this buffer was necessary."
(let ((buffer-name (format cider--debug-buffer-format id)))
(if-let ((buffer (get-buffer buffer-name)))
(if-let* ((buffer (get-buffer buffer-name)))
(cider-popup-buffer-display buffer 'select)
(with-current-buffer (cider-popup-buffer buffer-name 'select
#'clojure-mode 'ancillary)
Expand All @@ -465,7 +465,7 @@ REASON is a keyword describing why this buffer was necessary."

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

Expand Down Expand Up @@ -580,9 +580,9 @@ is a coordinate measure in sexps."
(save-excursion
(let ((out))
;; We prefer in-source debugging.
(when-let ((buf (and file line column
(ignore-errors
(cider--find-buffer-for-file file)))))
(when-let* ((buf (and file line column
(ignore-errors
(cider--find-buffer-for-file file)))))
;; The logic here makes it hard to use `with-current-buffer'.
(with-current-buffer buf
;; This is for restoring point inside buf.
Expand Down Expand Up @@ -648,7 +648,7 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
RESPONSE is a message received from the nrepl describing the value and
coordinates of a sexp. Create an overlay after the specified sexp
displaying its value."
(when-let ((marker (cider--debug-find-source-position response)))
(when-let* ((marker (cider--debug-find-source-position response)))
(with-current-buffer (marker-buffer marker)
(save-excursion
(goto-char marker)
Expand Down
14 changes: 7 additions & 7 deletions cider-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ opposite of what that option dictates."
"Open the source for the current symbol, if available."
(interactive)
(if cider-docview-file
(if-let ((buffer (and (not (cider--tooling-file-p cider-docview-file))
(cider-find-file cider-docview-file))))
(if-let* ((buffer (and (not (cider--tooling-file-p cider-docview-file))
(cider-find-file cider-docview-file))))
(cider-jump-to buffer (if cider-docview-line
(cons cider-docview-line nil)
cider-docview-symbol)
Expand Down Expand Up @@ -262,12 +262,12 @@ opposite of what that option dictates."

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

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

Expand Down Expand Up @@ -396,9 +396,9 @@ Tables are marked to be ignored by line wrap."
(depr (nrepl-dict-get info "deprecated"))
(macro (nrepl-dict-get info "macro"))
(special (nrepl-dict-get info "special-form"))
(forms (when-let ((str (nrepl-dict-get info "forms-str")))
(forms (when-let* ((str (nrepl-dict-get info "forms-str")))
(split-string str "\n")))
(args (when-let ((str (nrepl-dict-get info "arglists-str")))
(args (when-let* ((str (nrepl-dict-get info "arglists-str")))
(split-string str "\n")))
(doc (or (nrepl-dict-get info "doc")
"Not documented."))
Expand Down Expand Up @@ -428,7 +428,7 @@ Tables are marked to be ignored by line wrap."
(emit (concat " "(cider-font-lock-as 'java-mode iface)))))
(when (or super ifaces)
(insert "\n"))
(when-let ((forms (or forms args)))
(when-let* ((forms (or forms args)))
(dolist (form forms)
(insert " ")
(emit (cider-font-lock-as-clojure form))))
Expand Down
Loading

0 comments on commit b34057a

Please sign in to comment.