clojure/tools.nrepl — pull request #5 by mtopolnik (2013-02-03 21:46:25+00:00)
Title: Configurable middleware

In the discussion on [pull request #963](https://github.com/technomancy/leiningen/pull/963) in leiningen the issue of nrepl middleware configuration came up. The specific requirement was to configure the `session` middleware with an initial namespace as specified in `project.clj`, instead of the default `user`. There is no fundamental restriction in nREPL that would stand in the way, but there is no provided convenience currently in place. Since server startup code must often be written as an unevaluated form, to be evaluated after a context switch into userland, it is harder than usual to write the configuration code without such convenience within the nREPL namespace.

This pull request offers two enhancements:

1. make `session` middleware configurable with an initial namespace;
2. provide support in `default-handler` to pass in extra middleware configuration arguments.

The key convenience function is `apply-middleware-stack`, which applies the middleware along with extra arguments. `default-handler` is modified to rely on it.