Skip to content

Commit

Permalink
All 0.1.5 changes (see changelog)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-brandt committed Jan 11, 2022
1 parent 7feba88 commit fe595a3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 52 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## [Unreleased]

## [0.1.5] - 2022-01-10
### Fixed
- Bugfix for errors when pretty-printing forms with required namespaces

## [0.1.4] - 2022-01-03
### Added
### Fixed
- Fixed an issue where nested data-scope reader tags will result in the outer tag
pretty-printing macroexpanded forms from the inner tag. The fix ignores inner tags
when pretty-printing content for the outer tag.
Expand Down Expand Up @@ -34,7 +38,8 @@ in the pretty-printed output of `#pp`.
### Added
- Initial Release!

[Unreleased]: https://github.com/jsofra/data-scope/compare/0.1.4...HEAD
[Unreleased]: https://github.com/jsofra/data-scope/compare/0.1.5...HEAD
[0.1.5]: https://github.com/tervorz/data-scope/compare/0.1.4...0.1.5
[0.1.4]: https://github.com/tervorz/data-scope/compare/0.1.3...0.1.4
[0.1.3]: https://github.com/tervorz/data-scope/compare/0.1.2...0.1.3
[0.1.2]: https://github.com/tervorz/data-scope/compare/0.1.1...0.1.2
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ which was inspired by [Spyscope](https://github.com/dgrnbrg/spyscope).

#### Leiningen

Add `[tervorz/data-scope "0.1.4"]` to your project.clj's `:dependencies`.
Add `[tervorz/data-scope "0.1.5"]` to your project.clj's `:dependencies`.

If you want data-scope to be automatically loaded and available in every project's
`user` namespace, add the following to the `:user` profile in `~/.lein/profiles.clj`:

:dependencies [[tervorz/data-scope "0.1.4"]]
:dependencies [[tervorz/data-scope "0.1.5"]]
:injections [(require 'ds)]

#### Boot
Expand All @@ -32,7 +32,7 @@ After requiring the namespace, you must also run `(boot.core/load-data-readers!)
to get the reader tags working. Using a `~/.boot/profile.boot` file:

``` clojure
(set-env! :dependencies #(conj % '[tervorz/data-scope "0.1.4"]))
(set-env! :dependencies #(conj % '[tervorz/data-scope "0.1.5"]))
(boot.core/load-data-readers!)
(require 'ds)
```
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject tervorz/data-scope "0.1.4"
(defproject tervorz/data-scope "0.1.5"
:description "Tools for interactively examining data."
:url "https://github.com/tervorz/data-scope"
:license {:name "Eclipse Public License"
Expand Down
46 changes: 19 additions & 27 deletions src/data_scope/pprint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,30 @@
(println)
evaluated)

(defn pprint-wrapper
"A wrapper that helps the pretty-printer identify whether or not there's a
nested ds macro expansion in pretty-printed output."
([form]
(print-and-return form (eval form)))
([form thread-type]
(fn [threaded-arg]
(let [form-as-list (if (not (list? form))
(list form)
form)
[f & args] (when (list? form-as-list) form-as-list)
quoted-arg `(quote ~threaded-arg)
evaluated (case thread-type
:first (->> quoted-arg
(conj (seq args))
(cons f)
eval)
:last (-> form-as-list
vec
(conj quoted-arg)
seq
eval))]
(print-and-return form evaluated)))))

(defn scope-pprint [form]
`(pprint-wrapper '~form))
`(do
;; tag helps identify this as a pretty-print form for when we're
;; outputting nested pretty-print forms to the console
{:tervorz.data-scope/tag "ds-pprint"}
(print-and-return '~form ~form)))

(defn scope-pprint-thread-last [form]
`((pprint-wrapper '~form :last)))
`((do
;; tag helps identify this as a pretty-print form for when we're
;; outputting nested pretty-print forms to the console
{:tervorz.data-scope/tag "ds-pprint-threaded"}
(fn [x#]
(let [form# (->> x# ~form)]
(print-and-return '~form form#))))))

(defn scope-pprint-thread-first [form]
`((pprint-wrapper '~form :first)))
`((do
;; tag helps identify this as a pretty-print form for when we're
;; outputting nested pretty-print forms to the console
{:tervorz.data-scope/tag "ds-pprint-threaded"}
(fn [x#]
(let [form# (-> x# ~form)]
(print-and-return '~form form#))))))

(defn scope-print-table [form]
`(let [form# ~form]
Expand Down
53 changes: 34 additions & 19 deletions src/ds.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,43 @@
The above example has a #pp->> macro that results in macroexpanded output to
#pp, so we try to filter that noise out from the #pp output."
[form]
(cond
;; if your form isn't a collection, we don't need to worry about
;; filtering out noise
(not (coll? form))
form
(let [tag (when (coll? form)
(if (<= (count form) 1)
;; threaded forms
(second (first form))
;; non-threaded forms
(second form)))
[k form-type] (when (map? tag) (first tag))
tagged? (= :tervorz.data-scope/tag k)
threaded? (= "ds-pprint-threaded" form-type)
non-threaded? (= "ds-pprint" form-type)]
(or (cond
;; if your form isn't tagged as a pretty-print form, there
;; is nothing to filter out
(not tagged?)
form

;; threaded printed items will have a form that looks like:
;; `((ds/pprint-wrapper (quote original-form)))`
(and (= 1 (count form))
(coll? (first form))
(= 'ds/pprint-wrapper (ffirst form)))
(second (second (first form)))
;; threaded printed items will have a form that looks like:
;; `((do
;; {:tervorz.data-scope/tag "ds-pprint-threaded"}
;; (fn [x#]
;; (let [form# (->> x# ~form)]
;; (print-and-return '~form form#)))))
;; and we're taking out '~form from the last line
threaded?
(some-> form first (nth 2 nil) (nth 2 nil) (nth 2 nil) (nth 1 nil) eval)

;; regular pretty-printed items look like:
;; `(ds/pprint-wrapper (quote original-form))`
(= 'ds/pprint-wrapper (first form))
(second (second form))
;; regular pretty-printed items look like:
;; `(do
;; {:tervorz.data-scope/tag "ds-pprint"}
;; (print-and-return '~form ~form))
;; and we're taking out the '~form from the last line
non-threaded?
(-> form (nth 2 nil) (nth 1 nil) eval))

;; if the form is a collection but isn't wrapped with pprint, then the
;; form doesn't have any nested pretty-print macros
:else
form))
;; if the form isn't tagged or any of the above conditions
;; returns nil, just return the original form
form)))

(defn location-line-and-form
"Prints the namespace, fn, and line where the literal was placed, and also
Expand Down

0 comments on commit fe595a3

Please sign in to comment.