Skip to content

Commit

Permalink
Merge pull request #44 from venantius/0.4.0
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
venantius committed Nov 7, 2015
2 parents 80e3a97 + 63b5566 commit 42c9597
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 81 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: clojure
notifications:
email: false
script: lein trampoline test
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 0.4.0
* Fixed the diff-dispatching interface to correctly diff types - in particular, resolves a bug when diffing hash-maps and array-maps.
* Changed the behavior of `source` at the REPL to be colorized.
* Adds support for custom whidbey/puget options, including specifying the width.
* Updated dependencies.

## 0.3.4
* Updated dependencies. Should set the stage for ClojureScript support.
* Updated dependencies.

## 0.3.3
* Add a bugfix for a colorscheme configuration issue that was introduced in 0.3.0
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ Got something to make Ultra even more awesome? Radical. Let's talk about how to
## Filing Issues

Ultra is composed of multiple dependencies, features, and code paths. When filing an issue, particularly related to bugs or performance problems, it's really helpful to narrow down which component of Ultra is responsible for the problem in question. Please [selectively disable](https://github.com/venantius/ultra#configuration) Ultra's features until you figure out which of the main four features is responsible for the behavior you're reporting.

In addition, it's helpful to include the following information:
- Your JDK version
- Your Leiningen version
- Which version of Ultra you're using

## Tests

I will be the first person to admit that this library is quite short on test coverage. That has become something of a problem over time, with PRs being submitted with breaking changes in other, unexpected areas. My policy going forward is going to be to require tests as part of a pull request; I simply can't keep accepting pull requests that I have to go back and re-write later because the original author didn't test the new behavior thoroughly enough.
86 changes: 61 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ I've written a blog post describing Ultra in greater depth [here](http://blog.ve

## Installation

To install and configure Ultra, add something like the following to your `~/.lein/profiles.clj`
To install Ultra, just add the following to your `~/.lein/profiles.clj`

```clojure
{:user {:plugins [[venantius/ultra "0.3.4"]]
:ultra {:color-scheme :solarized_dark}}}
{:user {:plugins [[venantius/ultra "0.4.0"]]}}
```

### Requirements

Leiningen version 2.5.2+
As of Ultra `0.4.0`, Clojure 1.7.x is required due to reader conditional usage in Ultar's dependencies.
Ultra `0.3.4` is the last version supporting Clojure 1.6.x

Leiningen version 2.5.2+
JDK 7+

#### ClojureScript Support

At the moment, Ultra doesn't have ClojureScript support at the REPL. See https://github.com/brandonbloom/fipp/issues/7.
At the moment, Ultra doesn't have ClojureScript support at the REPL. The relevant upstream issue to track work on this is https://github.com/greglook/puget/issues/27; from there, Whidbey will need to be updated, and then Ultra will be able to consume the changes.

## Features
For a detailed list of features, check out the [wiki](https://github.com/venantius/ultra/wiki). Here's the highlight reel:
Expand All @@ -45,14 +47,13 @@ For a detailed list of features, check out the [wiki](https://github.com/venanti

## Configuration

All of the above features are enabled by default, but can be turned off by setting a `false` flag in your profile. If you wanted Ultra to essentially no-op, your profile would look like this:
All of the above features are enabled by default, but can be turned off by setting a `false` flag in your profile. If you wanted Ultra to essentially no-op, your configuration map would look like this:

```clojure
{:user {:plugins [[venantius/ultra "0.3.4"]]
:ultra {:repl false
:stacktraces false
:tests false
:java false}}}
{:ultra {:repl false
:stacktraces false
:tests false
:java false}}}}
```

### Color schemes
Expand All @@ -64,22 +65,57 @@ At the moment Ultra supports the following color schemes:
If you want to set the colors yourself instead of using a theme you can configure them directly, e.g.:

```clojure
{:user {:plugins [[venantius/ultra "0.3.4"]]
:ultra {:color-scheme {:delimiter [:red]
:tag [:red]
:nil [:cyan]
:boolean [:cyan]
:number [:cyan]
:string [:cyan]
:character [:cyan]
:keyword [:green]
:symbol nil
:function-symbol [:blue]
:class-delimiter [:blue]
:class-name nil
:exception nil}}}}
{:ultra {:color-scheme {:delimiter [:red]
:tag [:red]
:nil [:cyan]
:boolean [:cyan]
:number [:cyan]
:string [:cyan]
:character [:cyan]
:keyword [:green]
:symbol nil
:function-symbol [:blue]
:class-delimiter [:blue]
:class-name nil
:exception nil}}}
```

### Additional REPL Configuration

Ultra uses [Whidbey](https://github.com/greglook/whidbey) as its pretty-printing engine, and supports all of Whidbey's configuration flags.

```clojure
{:ultra {:repl {:width 180
:map-delimiter ""
:extend-notation true
:print-meta true
...}}}
```

###### `:width`

Number of characters to try to wrap pretty-printed forms at.

###### `:print-meta`

If true, metadata will be printed before values.

###### `:sort-keys`

Print maps and sets with ordered keys. Defaults to true, which will sort all collections. If a number, counted collections will be sorted up to the set size. Otherwise, collections are not sorted before printing.

###### `:map-delimiter`

The text placed between key-value pairs in a map.

###### `:map-coll-separator`

The text placed between a map key and a collection value. The keyword :line will cause line breaks if the whole map does not fit on a single line.

###### `:seq-limit`

If set to a positive number, then lists will only render at most the first n elements. This can help prevent unintentional realization of infinite lazy sequences.

## Contributing

Please open an issue here before submitting pull requests; I prefer to have documentation and consensus that either of our time will be well spent by working on it. When opening an issue -- particularly for bugs -- please refer to [CONTRIBUTING.md](https://github.com/venantius/ultra/blob/master/CONTRIBUTING.md)
Expand Down
14 changes: 9 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
(defproject venantius/ultra "0.3.4"
(defproject venantius/ultra "0.4.0"
:description "Ultra: A Leiningen plugin for a superior development environment"
:url "http://github.com/venantius/ultra"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/tools.nrepl "0.2.10"]
[org.clojure/tools.nrepl "0.2.11"]

[im.chit/hara.class "2.2.11"]
[im.chit/hara.reflect "2.2.11"]
[io.aviso/pretty "0.1.18"]
[mvxcvi/whidbey "1.0.0"]
[mvxcvi/puget "0.8.1"]
[mvxcvi/whidbey "1.1.1"]
[mvxcvi/puget "0.9.2"]
[org.clojars.brenton/google-diff-match-patch "0.1"]
[robert/hooke "1.3.0"]
[org.clojars.brenton/google-diff-match-patch "0.1"]]
[venantius/glow "0.1.2"]]
:test-selectors {:default (complement :demo)
:demo :demo}
:min-lein-version "2.5.2"
:eval-in-leiningen true)
6 changes: 3 additions & 3 deletions src/ultra/colorscheme.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[clojure.java.io :as io]
[io.aviso.exception]
[puget.color.ansi :as ansi]
[whidbey.render]))
[whidbey.repl]))

(defn valid-colorscheme?
[k]
Expand Down Expand Up @@ -60,7 +60,7 @@
color-scheme
(load-colorscheme color-scheme))]
(alter-var-root
#'whidbey.render/options
#'whidbey.repl/printer
merge
(assoc opts :color-scheme color-scheme))
{:color-scheme color-scheme})
(set-pretty-colors color-scheme)))
6 changes: 3 additions & 3 deletions src/ultra/hardcore.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns ultra.hardcore
"See what I did there?"
(:require [clojure.tools.nrepl.server]
[ultra.colorscheme :as colorscheme]
[robert.hooke :refer [add-hook]]))

(def configured? (atom {}))
Expand Down Expand Up @@ -48,8 +49,7 @@
"Dynamically import ultra's colorscheme namespace and configures it."
{:added "0.3.0"}
[opts]
`(do ~(require 'ultra.colorscheme)
(ultra.colorscheme/set-colorscheme ~opts)))
`(colorscheme/set-colorscheme ~opts))

(defn run-configuration
"Initialize and configure Ultra's various components."
Expand Down Expand Up @@ -81,5 +81,5 @@
[opts]
(add-hook #'clojure.test/try-expr
(fn [f & args]
(configure! opts)
(configure! (assoc opts :repl false))
(apply f args))))
8 changes: 2 additions & 6 deletions src/ultra/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(if (not (false? repl))
(-> project
(plugin/set-interactive-eval-renderer
'whidbey.render/render-str)
'whidbey.repl/render-str)
(plugin/add-nrepl-middleware
`clojure.tools.nrepl.middleware.render-values/render-values))
project))
Expand All @@ -36,11 +36,7 @@
[project opts]
(-> project
(plugin/add-dependencies
(plugin/plugin-dependency project 'venantius/ultra)
['mvxcvi/puget "0.8.1"]
['mvxcvi/whidbey "1.0.0"]
['im.chit/hara.class "2.2.7"]
['im.chit/hara.reflect "2.2.7"])
(plugin/plugin-dependency project 'venantius/ultra))
(update-in [:injections] concat `[(require 'ultra.hardcore)
(ultra.hardcore/add-test-hooks! ~opts)])
(assoc :monkeypatch-clojure-test false)
Expand Down
4 changes: 2 additions & 2 deletions src/ultra/printer.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns ultra.printer
(:require [puget.printer :as printer]
[whidbey.render :as render]))
[whidbey.repl :as repl]))

(defn cprint
"Puget's cprint, set to always use the Puget options."
{:added "0.1.3"}
[x]
(printer/cprint x render/options))
(printer/cprint x repl/printer))
17 changes: 0 additions & 17 deletions src/ultra/printer/escape_hatch.clj

This file was deleted.

34 changes: 23 additions & 11 deletions src/ultra/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@
(:require [clojure.main :as main]
[clojure.repl :as repl]
[clojure.tools.nrepl.server]
[glow.core :as glow]
[io.aviso.repl :as pretty-repl]
[ultra.printer :refer [cprint]]
[ultra.printer.escape-hatch]))
[ultra.printer :refer [cprint]]))

(defmacro pprint-source
(defmacro source
"Prints the source code for the given symbol, if it can find it.
This requires that the symbol resolve to a Var defined in a
namespace for which the .clj is in the classpath.
Example: (source filter)
Note that unlike clojure.repl/source, this fn can execute code, and
as such should only be used with trusted sources."
Example: (source filter)"
{:added "0.2.1"}
[n]
`(cprint (read-string (or (clojure.repl/source-fn '~n)
(str "Source not found")))))
`(if-let [source# (clojure.repl/source-fn '~n)]
(println (glow/highlight source#))
(println "Source not found")))

(defn replace-source
"First, re-define `clojure.repl/source (which is a macro) to be false.
Then, install our new preferred macro in its place.
Note: I'm happy with how this works, but not the code itself. Odds are good
that I'll try to refactor this in the future."
{:added "0.3.5"}
[]
(binding [*ns* (the-ns 'clojure.repl)]
(require '[glow.core :as glow])
(eval (read-string (repl/source-fn 'ultra.repl/source)))))

(defn add-middleware
"Alter the default handler to include the provided middleware"
Expand Down Expand Up @@ -46,7 +56,9 @@
[repl stacktraces]
(when (not (false? repl))
(require 'ultra.repl.whidbey)
(eval '(ultra.repl.whidbey/add-whidbey-middleware)))
(require 'whidbey.repl)
(eval '(ultra.repl.whidbey/add-whidbey-middleware))
(eval `(whidbey.repl/update-options! ~repl))
(replace-source))
(when (not (false? stacktraces))
(add-pretty-middleware)))

4 changes: 1 addition & 3 deletions src/ultra/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
(:require [clojure.data :as data]
[clojure.pprint :as pp]
[puget.color.ansi :as ansi]
[puget.printer :as printer]
[ultra.test.diff :as diff]
[whidbey.render :as render]))
[ultra.test.diff :as diff]))


(defn generate-diffs
Expand Down
12 changes: 7 additions & 5 deletions src/ultra/test/diff.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@
(fn [a b actual expected]
(cond
(and (string? a) (string? b)) ::diff-strs
(and (vector? a) (vector? b)) ::diff-vecs
(and (list? a) (list? b)) ::diff-vecs
(not= (class a) (class b)) ::wrong-class
(and (vector? actual) (vector? expected)) ::diff-vecs
(and (list? actual) (list? expected)) ::diff-vecs
(and (not= (class a) (class b))
(some? a)
(some? b)) ::wrong-class
:default [a b actual expected])))

(defmethod prn-diffs ::diff-strs
Expand All @@ -71,8 +73,8 @@
(print-expected actual expected)
(let [puget-str (fn [x] (s/trim-newline (with-out-str (cprint x))))]
(print "\nexpected: ")
(let [a (with-out-str (println (puget-str b)
"to be an instance of"
(let [a (with-out-str (println (puget-str b)
"to be an instance of"
(class a)))
b (with-out-str (println (puget-str b)
"is an instance of"
Expand Down

0 comments on commit 42c9597

Please sign in to comment.