Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Handle <<

* Handle commands that don't lead with +/-, etc
  • Loading branch information...
commit cfbed6a778ab4d13136352e3b5dca245d110e2df 1 parent 1df2e97
Kurt Werle authored
Showing with 19 additions and 11 deletions.
  1. +18 −10 lib/redcar-xiki.rb
  2. +1 −1  lib/redcar-xiki/version.rb
28 lib/redcar-xiki.rb
View
@@ -11,11 +11,13 @@ class Execute < ::Redcar::DocumentCommand
COMMAND_PARENT = '+'
COMMAND_CLOSED_PARENT = '-'
COMMAND_SHELL = '$'
-
+ COMMAND_SKIP_PARENT = '<<'
+
COMMANDS = [COMMAND_PATH, COMMAND_PARENT, COMMAND_CLOSED_PARENT, COMMAND_SHELL]
- COMMAND_REGEX = "([#{COMMANDS * '\\'}]) (.+)\s*$"
-
+ COMMAND_REGEX = "([#{COMMANDS * '\\'}] |#{COMMAND_SKIP_PARENT} |)(\\S.+)\s*$"
+$stdout << "regex: #{COMMAND_REGEX}\n"
+
def current_line_text
doc.get_line(doc.cursor_line)
end
@@ -26,16 +28,16 @@ def current_line_text
def build_up_menu(line, indent, menu_array)
menu_array = Array(menu_array)
return menu_array unless indent.length > 0 # If we're on the left edge, we have no parent
-# $stdout << "working on: #{menu_array * ', '}\n"
+$stdout << "working on: #{menu_array * ', '}\n"
target_indent = indent.sub(/ $/,'') # The indent needs to be less than the previous one
while (line = line - 1) >= 0
-# $stdout << "line: #{line} #{doc.offset_at_line(line)}\n"
+$stdout << "line: #{line} #{doc.offset_at_line(line)}\n"
line_text = doc.get_line(line) # let's get some text
-# $stdout << "line0: #{line_text}\n"
+$stdout << "line0: #{line_text}\n"
target_match = line_text.match(/(^#{target_indent})#{COMMAND_REGEX}/) # Trying to match "<some spaces>+ <menu>"
-# $stdout << "line1: #{target_match}\n"
+$stdout << "line1: #{target_match}\n"
return process_match(line, target_indent, menu_array, target_match) if target_match
-# $stdout << "line2: #{line_text}\n"
+$stdout << "line2: #{line_text}\n"
next if line_text.match(/^#{target_indent}[ |]/) # next one up if it has more spaces or starts with a |
end
return menu_array
@@ -43,7 +45,13 @@ def build_up_menu(line, indent, menu_array)
def process_match(line_number, indent, menu_array, match)
indent, command, text = match.captures
+$stdout << "process_match command #{command} text #{text} menu_array #{menu_array * ','}\n"
return [text.gsub(/^@/, '')] + menu_array if text.start_with?('@')
+ if command.strip == COMMAND_SKIP_PARENT
+ ary = build_up_menu(line_number, indent, [])
+ ary.pop
+ return ary + [text] + menu_array
+ end
return build_up_menu(line_number, indent, [text] + menu_array)
end
@@ -62,13 +70,13 @@ def execute()
unless text.end_with? '/'
text << '/'
end
- doc.replace_line(doc.cursor_line, "#{indent}#{command} #{text}")
+ doc.replace_line(doc.cursor_line, ["#{indent}#{command}", "#{text}"].reject{|s| s.nil? || s == ''} * '')
text = process_match(doc.cursor_line, indent, [], matches)
response = `xiki #{text}`
response.gsub!(/^/, indent + ' ')
doc.insert(doc.offset_at_line_end(doc.cursor_line), "\n") unless current_line_text.end_with?("\n")
doc.insert(doc.offset_at_line_end(doc.cursor_line), response)
-# $stdout << "text: #{text}\n"
+$stdout << "text: #{text}\n"
end
end
2  lib/redcar-xiki/version.rb
View
@@ -1,5 +1,5 @@
module Redcar
module Xiki
- VERSION = "0.0.3"
+ VERSION = "0.0.4"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.