Skip to content

Commit

Permalink
[Fix #1564] Add support to filter out internal namespaces and vars (#…
Browse files Browse the repository at this point in the history
…1724)

Hide all nREPL middleware details from `cider-browse-ns*` and `cider-apropos*` commands by customizing the variable `cider-filter-regexps`.
It should be a list of regexps matching the pattern of namespaces you want to filter out.
  • Loading branch information
cskksc authored and bbatsov committed May 1, 2016
1 parent ff2a6dc commit a9d1d58
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Allow the ns displayed by eldoc to be tailored via `cider-eldoc-ns-function`.
* After connecting a ClojureScript REPL, CIDER will try to figure out if it's being served on a port and will offer to open it in a browser.
* [#1720](https://github.com/clojure-emacs/cider/issues/1720): Add a command `cider-eval-sexp-at-point` to evaluate the form around point (bound to `C-c C-v`).
* [#1564](https://github.com/clojure-emacs/cider/issues/1564): CIDER's internal namespaces and vars are filtered from the ns-browser and apropos functions.

### Changes

Expand Down
19 changes: 18 additions & 1 deletion cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,21 @@ If CALLBACK is nil, use `cider-load-file-handler'."


;;; Sync Requests

(defcustom cider-filtered-namespaces-regexps
'("^cider.nrepl" "^refactor-nrepl" "^clojure.tools.nrepl")
"List of regexps used to filter out some vars/symbols/namespaces.
When nil, nothing is filtered out. Otherwise, all namespaces matching any
regexp from this list are dropped out of the \"ns-list\" op.
Also, \"apropos\" won't include vars from such namespaces.
This list is passed on to the nREPL middleware without any pre-processing.
So the regexps have to be in Clojure format (with twice the number of
backslashes) and not Emacs Lisp."
:type '(repeat string)
:safe #'listp
:group 'cider
:package-version '(cider . "0.13.0"))

(defun cider-sync-request:apropos (query &optional search-ns docs-p privates-p case-sensitive-p)
"Send \"apropos\" request for regexp QUERY.
Expand All @@ -827,7 +842,8 @@ Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P."
,@(when search-ns `("search-ns" ,search-ns))
,@(when docs-p '("docs?" "t"))
,@(when privates-p '("privates?" "t"))
,@(when case-sensitive-p '("case-sensitive?" "t"))))))
,@(when case-sensitive-p '("case-sensitive?" "t"))
"filter-regexps" ,cider-filtered-namespaces-regexps))))
(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"))))
Expand Down Expand Up @@ -880,6 +896,7 @@ CONTEXT represents a completion context for compliment."
(defun cider-sync-request:ns-list ()
"Get a list of the available namespaces."
(thread-first (list "op" "ns-list"
"filter-regexps" cider-filtered-namespaces-regexps
"session" (cider-current-session))
(cider-nrepl-send-sync-request)
(nrepl-dict-get "ns-list")))
Expand Down
20 changes: 20 additions & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ To remove the prefix altogether just set it to an empty string(`""`).

More details can be found [here](https://github.com/clojure-emacs/cider/issues/930).

* You can hide all nREPL middleware details from `cider-browse-ns*` and `cider-apropos*`
commands by customizing the variable `cider-filter-regexps`. It should be a list of
regexps matching the pattern of namespaces you want to filter out.

Its default value is `'("^cider.nrepl" "^refactor-nrepl" "^clojure.tools.nrepl")`,
the most commonly used middleware collections/packages.

An important thing to note is that this list of regexps is passed on to the middleware
without any pre-processing. So, the regexps have to be in Clojure format (with twice the number of backslashes)
and not Emacs Lisp. For example, to achieve the above effect, you could also set `cider-filter-regexps` to `'(".*nrepl")`.

To customize `cider-filter-regexps`, you could use the Emacs customize UI,
with <kbd>M-x</kbd> `customize-variable` <kbd>RET</kbd> `cider-filter-regexps`.

Or by including a similar snippet along with the other CIDER configuration.

```el
(setq cider-filter-regexps '(".*nrepl"))
```

## Overlays

When you evaluate code in Clojure files, the result is displayed in the buffer
Expand Down

0 comments on commit a9d1d58

Please sign in to comment.