From 66eb1bb6d7304683a8fd82776aba5a972835e0a7 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 19 Mar 2016 21:26:36 +0200 Subject: [PATCH] Make it possible to pass to the apropos commands a list of space-separated words This is pretty much how Emacs's apropos works. The list of words is converted to a regexp behind the scenes. --- CHANGELOG.md | 1 + cider-apropos.el | 7 +++++-- cider-client.el | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9cc8566c..edf58365f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Javadoc commands take into account the variable `clojure.java.javadoc/*remote-javadocs*`. * Javadoc also works on classes of the AmazonAWS Java SDK. +* Apropos commands now accept lists of space-separated words as arguments, in addition to regular expressions (similar to Emacs's own apropos commands). ## 0.11.0 / 2016-03-03 diff --git a/cider-apropos.el b/cider-apropos.el index 3ba69e089..faf4a346d 100644 --- a/cider-apropos.el +++ b/cider-apropos.el @@ -101,8 +101,11 @@ ;;;###autoload (defun cider-apropos (query &optional ns docs-p privates-p case-sensitive-p) "Show all symbols whose names match QUERY, a regular expression. -The search may be limited to the namespace NS, and may optionally search doc -strings, include private vars, and be case sensitive." +QUERY can also be a list of space-separated words (e.g. take while) which +will be converted to a regular expression (like take.+while) automatically +behind the scenes. The search may be limited to the namespace NS, and may +optionally search doc strings, include private vars, and be case +sensitive." (interactive (cons (read-string "Search for Clojure symbol (a regular expression): ") (when current-prefix-arg diff --git a/cider-client.el b/cider-client.el index dc98dd448..f6dca5e24 100644 --- a/cider-client.el +++ b/cider-client.el @@ -789,15 +789,16 @@ If CALLBACK is nil, use `cider-load-file-handler'." "Send \"apropos\" request for regexp QUERY. Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P." - (let ((response (cider-nrepl-send-sync-request - `("op" "apropos" - "session" ,(cider-current-session) - "ns" ,(cider-current-ns) - "query" ,query - ,@(when search-ns `("search-ns" ,search-ns)) - ,@(when docs-p '("docs?" "t")) - ,@(when privates-p '("privates?" "t")) - ,@(when case-sensitive-p '("case-sensitive?" "t")))))) + (let* ((query (replace-regexp-in-string "[ \t]+" ".+" query)) + (response (cider-nrepl-send-sync-request + `("op" "apropos" + "session" ,(cider-current-session) + "ns" ,(cider-current-ns) + "query" ,query + ,@(when search-ns `("search-ns" ,search-ns)) + ,@(when docs-p '("docs?" "t")) + ,@(when privates-p '("privates?" "t")) + ,@(when case-sensitive-p '("case-sensitive?" "t")))))) (if (member "apropos-regexp-error" (nrepl-dict-get response "status")) (user-error "Invalid regexp: %s" (nrepl-dict-get response "error-msg")) (nrepl-dict-get response "apropos-matches"))))