1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
Commit graph

9 commits

Author SHA1 Message Date
Conrad Irwin
6f54733e1d Fix indentation of "true if foo" [Fixes #355] 2011-11-27 10:40:31 -08:00
Conrad Irwin
b96a26c094 re-re-fix super... (I added a test this time :p) 2011-10-27 23:46:18 -07:00
Conrad Irwin
a1d148199f Indent begin-rescue-end properly 2011-10-25 20:57:19 -07:00
Conrad Irwin
ab0dbfbe6d Handle unless and until in indent 2011-10-09 21:35:02 -07:00
Conrad Irwin
7694cfeaaa Indent case statements 2011-10-09 01:39:42 -07:00
Conrad Irwin
bdf0c908c8 Fix single-line "if"s 2011-10-09 00:04:54 -07:00
Yorick Peterse
e2db26574f Pry::Indent now handles single line statements.
Previously certain lines of code would break the indentation process. For
example, the following code would result in incorrect indentation:

    def hello; end
    puts "Hello world"

This would result in the following:

    def hello; end
      puts "Hello world"

I've worked around this issue by adding a new method
(Pry::Indent#skip_indentation?) that does a lookahead on the list of tokens to
determine if a line should be indented or not. It's probably not the most
efficient way of doing it but it makes it quite easy to add more tokens to the
list without adding a lot more complexity.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
2011-10-08 15:32:49 +02:00
Yorick Peterse
42e943733b Compatibility with 1.8 and friends.
Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
2011-10-06 11:17:08 +02:00
Yorick Peterse
e9c2f383eb Pry now indents code similar to IRB.
Code is indented using the class Pry::Indent. This class uses an internal stack
that contains the indentation levels for each line of code. Certain keywords
such as "class" or "def" will add data to this stack so that the next line is
indented, other keywords such as "end" or "}" will remove data from the stack,
causing the next line to be un-indented.

Pry::Indent is hooked into Pry#retrieve_line as well as Pry#readline. This means
that both input strings as well as the ones displayed by "show-method" are
indented. Sadly due to the way Readline works input strings are indented similar
to IRB. This means that instead of the following:

    > class User
    >   def initialize
    >   end
    > end

You'll get the following:

    > class User
    >   def initialize
    >     end
    >   end

While annoying there doesn't seem to be a way to work around this issue. Luckily
the "show-method" command indents your code properly.

By default indentation is turned on. This can be turned off (or back on) using
the configuration item Pry.config.indent. However, if you turn this option off
after a method is defined "show-method" will still show it with indentation as
indentation happens on input rather than only when code is displayed.

For more information see Pry::Indent#indent in lib/pry/indent.rb.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
2011-10-05 19:04:44 +02:00