-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support pp for large/complex structures #44
Comments
Hi, Avdi. Thanks for checking out the lib! Short ResponseComposing the long response made me think through a bunch of stuff, so I'm rather tempted to see if I can't hack it in for a short-term solution, and then figure out the stuff below for a proper long-term solution. I'll probably give that a shot today or tomorrow, unless @lukeaiken would like to try (let me know and I'll walk you through what I'm thinking). Long ResponseWe already display the previous lineIf you set the --xmpfilter-style flag, it will already display the value on the previous line. I didn't realize that xmpfilter would pretty inspect the previous result in this case, so it does not do that at present. { foo: 42,
bar: {
baz: 1,
buz: 2,
fuz: 3,
},
wibble: {
magic_word: "xyzzy",
}
}
# => {:foo=>42, :bar=>{:baz=>1, :buz=>2, :fuz=>3}, :wibble=>{:magic_word=>"xyzzy"}} Recording with
|
Here is where they do it. They call that for each line, setting multiline only for the style you showed Playing with their code: require 'pp' # => true
h = { foo: 42, # => 42
bar: {
baz: 1, # => 1
buz: 2, # => 2
fuz: 3, # => 3
}, # => {:baz=>1, :buz=>2, :fuz=>3}
wibble: {
magic_word: "xyzzy", # => "xyzzy"
} # => {:magic_word=>"xyzzy"}
} # => {:foo=>42, :bar=>{:baz=>1, :buz=>2, :fuz=>3}, :wibble=>{:magic_word=>"xyzzy"}}
PP.pp(h, '', 40) # => "{:foo=>42,\n :bar=>{:baz=>1, :buz=>2, :fuz=>3},\n :wibble=>{:magic_word=>\"xyzzy\"}}\n"
.gsub(/\r?\n/, 'PPPROTECT'); # => "{:foo=>42,PPPROTECT :bar=>{:baz=>1, :buz=>2, :fuz=>3},PPPROTECT :wibble=>{:magic_word=>\"xyzzy\"}}PPPROTECT" So this is harder than I thought, since, it alternates between which method it uses to record the value. So I'd need to know on a line-by-line basis which inspection method to use. @avdi, do you find you actually use the difference? ie what if there was just a flag you could set to use pretty printed inspections? Then you could Like this constraint exists because I'm mimicking the other tool, but it might be that if we identify what the purpose of it is, that there is a better way to integrate it in SiB. |
Also, is xmpfilter's line number behaviour correct? {foo: 42, bar: {baz: 1,buz: 2,fuz: 3},wibble: {magic_word: "xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
__LINE__ # => 1 |
I do, in a really organic way. One of my production values in RubyTapas is that I try to leave as much context on the screen as possible. That means I'm often slowly building up a screenful or more of code a bit at a time, annotating certain parts of it with xmpfilter comments and re-evaluating regularly. When an expression I'm evaluating will produce a short inspection, I put the xmp tag on the same line. When I know it will produce multi-line or complex output, I put the xmp tag on the next line, relying on the pretty_inspect behavior to render it readably. In the end I'm left with a mix of inline and next-line annotations. Switching back and forth between two different types of filter invocation would reformat the whole buffer and would be visually jarring in a way my current workflow isn't. |
This is a big advancement in terms of #44 Still needs to: * Put them on multiple lines * Select the correct widths (where does xmpfilter get this value?) * Clean that shit up >.< * Make sure that we can pass the result of one of these things back through and it'll get correctly cleaned up Other notes: * ExtractFindComments out of RewriteComments. I'm not really happy with this, anything that does a job should not be an object. Thinking about trying to pull the initialization of all these parser things up as high as possible, then they can parse just once and hand that stuff around, instead of every class that needs code parsed having to deal with this shit. * Get some tests passing again (got more to do, but I need to work w/ my sister for a bit)
ContextHey, @avdi, getting pretty close to having this ready. I need to figure out what width to pass to PP.pp They default the value to 79, and then pass a width of 5 less than that, so 74. Presumably these numbers are because 80 is a standard terminal, then subtract 1 for the hash to comment the line out, and the next 5 for spaces to line it up with the hash-rocket. But I can get the same results by setting it as low as 40. Hoping you can let me know how yours gets set. Maybe you explicitly pass it in your rcodetools.el, or maybe something else somewhere else is setting it. To reduce the effort, I've included some bash scripts you can use to figure this out. Finding the widthThis one adds a line to your xmpfilter that will print out the width when running multi-line expressions: ruby -pi -e 'puts %q(puts "\e[32mWIDTH=#{@width.inspect}\e[0m") if $. == 176' `gem which rcodetools/xmpfilter` This one will then run your example through xmpfilter, we should see it print out the width: printf '{foo:42,bar:{baz:1,buz:2,fuz:3},wibble:{magic_word:"xyzzy"}}\n# =>'|xmpfilter This one will then remove the line I added, returning it to normal. ruby -ni -e 'print unless $. == 176' `gem which rcodetools/xmpfilter` This should all work, but if it gets totally horked, you can Let me know what the width is, I'll mimic the xmpfilter settings. |
… running & passing Technically, #44 is working now, but really, it needs a lot of refactoring and better test coverage
I don't think I've ever manually set anything up relating to xmpfilter Here's the output:
Thanks for your work on this! Avdi Grimm On Wed, Sep 17, 2014 at 1:04 AM, Josh Cheek notifications@github.com
|
Cool. I've got it working already, but it requires a per-line decision about how to record the expression, which is a pretty big change. So I'm taking advantage of the opportunity to make a lot of big changes and release a major version. here's an example a cuke based on your example, which is currently passing. If you'd be willing to try it out, let me know, I'll do a prerelease version. I also moved the markers (annotations) to a place where it will be easy to choose your own, so that will probably happen, and I'll probably also get xmpfilter-style to respect the alignment strategies. |
I'm going to try and use this on the next RubyTapas video record (sometime Avdi Grimm On Sun, Sep 21, 2014 at 10:41 PM, Josh Cheek notifications@github.com
|
Okay, let me get a release out for you, then. Been a hectic day, only just saw this :P |
Well, not going to happen today. Wound up sauced and still have to do some things for tomorrow's class. The git version on this branch is probably fine, was just trying to add some extra tests and more holistic functionality around it. But let me know if anything goes awry and I'll make sure to address that specifically. |
Hey, @avdi, just released v3.0.0.beta.1 gem install seeing_is_believing -v 3.0.0.beta.1 I'm not super confident in it, b/c I'm getting nondeterministic CI failures, but tried it out locally and so far haven't had any issues. Give it a shot and let me know if there's anything super broken, I'll hit it up quickly. Also, going to add some nice features for the real 3.0.0 release, so there's that to look forward to! ExampleGiven this code SeeingIsBelieving::VERSION # =>
{ foo: 42,
bar: {baz: 1, buz: 2, fuz: 3},
wibble: {magic_word: "xyzzy"}
} # =>
# => When you pipe it into SeeingIsBelieving::VERSION # => "3.0.0.beta.1"
{ foo: 42,
bar: {baz: 1, buz: 2, fuz: 3},
wibble: {magic_word: "xyzzy"}
} # => {:foo=>42, :bar=>{:baz=>1, :buz=>2, :fuz=>3}, :wibble=>{:magic_word=>"xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}} |
I've used this to record a couple episodes now, and it's working great! I In order to use it in emacs I simply changed the command for rcodetools.el Minor request: could you make it recognize "#=>" as well as "# =>"? And Avdi Grimm On Tue, Sep 23, 2014 at 12:11 PM, Josh Cheek notifications@github.com
|
Thanks, I'll try it out next time I record! Avdi Grimm On Sat, Sep 27, 2014 at 8:01 PM, Josh Cheek notifications@github.com
|
If you're hitting annoying issues with versions of Ruby / Parser, I released beta4 which has an update that should fix this. A few other bugs will go away, too. Not all of them, though. |
Hi, @avdi. beta5 is out. It should be stable enough to release as v3.0, but I'm going to wait a bit anyway, b/c I'd like to polish up some editor integrations so it's easier for people to be excited about it. If you wouldn't mind using it and letting me know if you hit any issues, I'd appreciate it. Some things to look forward to
No Broken WindowsIf you uncover any on this version, please let me know. I think it is in a good spot right now and would like to keep it bug-free. Deprecations:These all still work, so-as not to break the interface. But since it's a major version change, I took the opportunity to choose more descriptive names for these flags.
Here are some things I'd probably do if you or anyone implied they wanted them
|
This sounds spectacular! I've installed it on my RubyTapas VM so I'll be Thank you!! Avdi Grimm On Sun, Jan 18, 2015 at 3:57 PM, Josh Cheek notifications@github.com
|
Closing this since v3 is released. |
first off, this project is super, super cool. I'm now evaluating it to see if it would be a viable replacement for xmpfilter in RubyTapas.
One feature that I use a lot in xmpfilter is the difference between annotating the end of a line and annotating on the next line. In xmpfilter, if you annotate the following line, it switches to using
pp
indented output instead ofinspect
output. This is handy for showing the contents of large or nested data structures.Here's an example using
xmpfilter
:Is this a possibility in SIB?
The text was updated successfully, but these errors were encountered: