completion on assignment expression

3 views
Skip to first unread message

Chihiro Ito

unread,
Feb 24, 2008, 11:31:34 AM2/24/08
to rush, the Ruby Shell
Hi.

I'm using rush on cygwin. It seems to work fine and is extremely
useful. thanks.

btw, I modified shell.rb as follows because I want path-completion on
assignment (or any) expression.

--- shell.rb.orig 2008-02-25 00:40:28.550195200 +0900
+++ shell.rb 2008-02-25 00:52:41.213713600 +0900
@@ -90,7 +90,10 @@
end

def path_parts(input) # :nodoc:
- input.match(/^(.+)\[(['"])([^\]]+)$/).to_a.slice(1, 3) rescue
[ nil, nil, nil ]
+ match = input.match(/(\w+)\[(['"])([^\]]+)$/)
+ match.to_a.slice(1, 3).push(match.pre_match)
+ rescue
+ [ nil, nil, nil, nil ]
end

# Try to do tab completion on dir square brackets accessors.
@@ -103,7 +106,7 @@
# It does work remotely, though, which is pretty sweet.
def completion_proc
proc do |input|
- possible_var, quote, partial_path = path_parts(input)
+ possible_var, quote, partial_path, pre = path_parts(input)
if possible_var and possible_var.match(/^[a-z0-9_]+$/)
full_path = eval("#{possible_var}.full_path", @pure_binding)
rescue nil
box = eval("#{possible_var}.box", @pure_binding) rescue nil
@@ -112,7 +115,7 @@
return dir.entries.select do |e|
e.name.match(/^#{partial_path}/)
end.map do |e|
- possible_var + '[' + quote + e.name + (e.dir? ? "/" : "")
+ (pre || '') + possible_var + '[' + quote + e.name + (e.dir? ?
"/" : "")
end
end
end

Adam Wiggins

unread,
Feb 24, 2008, 4:50:18 PM2/24/08
to ruby-...@googlegroups.com
On 2/24/08, Chihiro Ito <source...@gmail.com> wrote:
I'm using rush on cygwin.

Wow, cool that it works - wouldn't have expected that.

btw, I modified shell.rb as follows because I want path-completion on
assignment (or any) expression.

Ack, you've found the worst dark corner in the code - that method is both really ugly and not speced at all. :)

I tried applying your patch, but I couldn't tell what it does.  Can you give an example use case?

Adam

Chihiro Ito

unread,
Feb 25, 2008, 9:31:25 AM2/25/08
to rush, the Ruby Shell
I posted simple use case and a new patch at the following thread.

http://groups.google.com/group/ruby-shell/browse_thread/thread/8e93174c9430b3b3/6ccc3c6ac2ccdef2

If you have already integrated the old patch, sorry for your extra
work.

On 2月25日, 午前6:50, "Adam Wiggins" <a...@heroku.com> wrote:

Jeff Barret

unread,
Mar 28, 2008, 12:04:36 PM3/28/08
to rush, the Ruby Shell
http://wikipedlla.com/completion_on_assignment_expression
> Hi.
> I'm using rush on cygwin. It seems to work fine and is extremely
> useful. thanks.
> btw, I modified shell.rb as follows because I want path-completion on
> assignment (or any) expression.
> --- shell.rb.orig &nbsp; &nbsp; &nbsp; 2008-02-25 00:40:28.550195200 +0900
> +++ shell.rb &nbsp; &nbsp;2008-02-25 00:52:41.213713600 +0900
> @@ -90,7 +90,10 @@
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def path_parts(input) &nbsp; # :nodoc:
> - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.match(/^(.+)\[(['&quot;])([^\]]+)$/).to_a.slice(1, 3) rescue
> [ nil, nil, nil ]
> + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; match = input.match(/(\w+)\[(['&quot;])([^\]]+)$/)
> + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; match.to_a.slice(1, 3).push(match.pre_match)
> + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rescue
> + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ nil, nil, nil, nil ]
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Try to do tab completion on dir square brackets accessors.
> @@ -103,7 +106,7 @@
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # It does work remotely, though, which is pretty sweet.
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def completion_proc
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc do |input|
> - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; possible_var, quote, partial_path = path_parts(input)
> + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; possible_var, quote, partial_path, pre = path_parts(input)
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if possible_var and possible_var.match(/^[a-z0-9_]+$/)
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; full_path = eval(&quot;#{possible_var}.full_path&quot;, @pure_binding)
> rescue nil
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box = eval(&quot;#{possible_var}.box&quot;, @pure_binding) rescue nil
> @@ -112,7 +115,7 @@
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return dir.entries.select do |e|
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.name.match(/^#{partial_path}/)
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end.map do |e|
> - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; possible_var + '[' + quote + e.name + (e.dir? ? &quot;/&quot; : &quot;&quot;)
> + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (pre || '') + possible_var + '[' + quote + e.name + (e.dir? ?
> &quot;/&quot; : &quot;&quot;)
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end
>
Reply all
Reply to author
Forward
0 new messages