redcar 0.3.4.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. data/CHANGES +45 -0
  2. data/README.md +2 -1
  3. data/ROADMAP.md +0 -1
  4. data/Rakefile +10 -4
  5. data/bin/redcar +2 -2
  6. data/lib/openssl/build.properties +7 -0
  7. data/lib/plugin_manager/lib/plugin_manager.rb +10 -0
  8. data/lib/plugin_manager/lib/plugin_manager/plugin_definition.rb +1 -13
  9. data/lib/redcar.rb +12 -8
  10. data/lib/redcar/installer.rb +16 -15
  11. data/lib/redcar/ruby_extensions.rb +146 -1
  12. data/lib/redcar/runner.rb +16 -7
  13. data/lib/redcar/usage.rb +4 -7
  14. data/lib/redcar_quick_start.rb +5 -5
  15. data/lib/regex_replace.rb +0 -7
  16. data/plugins/application/features/step_definitions/command_steps.rb +5 -0
  17. data/plugins/application/features/step_definitions/dialog_steps.rb +5 -0
  18. data/plugins/application/features/step_definitions/filter_list_dialog_steps.rb +38 -0
  19. data/plugins/application/features/step_definitions/window_steps.rb +1 -1
  20. data/plugins/application/features/support/env.rb +44 -8
  21. data/plugins/application/lib/application.rb +32 -33
  22. data/plugins/application/lib/application/command.rb +32 -2
  23. data/plugins/application/lib/application/command/executor.rb +2 -12
  24. data/plugins/application/lib/application/dialog.rb +14 -14
  25. data/plugins/application/lib/application/event_spewer.rb +32 -0
  26. data/plugins/application/lib/application/menu.rb +5 -5
  27. data/plugins/application/lib/application/menu/builder.rb +5 -0
  28. data/plugins/application/lib/application/menu/lazy_menu.rb +24 -0
  29. data/plugins/application/lib/application/notebook.rb +4 -3
  30. data/plugins/application/lib/application/tab.rb +6 -2
  31. data/plugins/application/lib/application/window.rb +8 -4
  32. data/plugins/application/spec/application/menu/builder_spec.rb +17 -1
  33. data/plugins/application/spec/application/notebook_spec.rb +1 -1
  34. data/plugins/application_swt/build.xml +74 -0
  35. data/plugins/application_swt/lib/application_swt.rb +79 -0
  36. data/plugins/application_swt/lib/application_swt/cucumber_patches.rb +6 -1
  37. data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +25 -17
  38. data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +50 -12
  39. data/plugins/application_swt/lib/application_swt/html_tab.rb +20 -0
  40. data/plugins/application_swt/lib/application_swt/menu.rb +26 -2
  41. data/plugins/application_swt/lib/application_swt/notebook.rb +10 -12
  42. data/plugins/application_swt/lib/application_swt/window.rb +11 -11
  43. data/plugins/application_swt/src/com/redcareditor/application_swt/CocoaUIEnhancer.java +313 -0
  44. data/plugins/auto_completer/lib/auto_completer.rb +74 -67
  45. data/plugins/auto_completer/lib/auto_completer/current_document_completion_source.rb +19 -0
  46. data/plugins/auto_completer/lib/auto_completer/document_controller.rb +2 -2
  47. data/plugins/auto_completer/lib/auto_completer/word_list.rb +8 -1
  48. data/plugins/auto_indenter/features/ruby_style_indentation.feature +24 -0
  49. data/plugins/auto_indenter/features/step_definitions/indentation_steps.rb +6 -0
  50. data/plugins/auto_indenter/features/support/env.rb +2 -0
  51. data/plugins/auto_indenter/lib/auto_indenter.rb +86 -0
  52. data/plugins/auto_indenter/lib/auto_indenter/analyzer.rb +91 -0
  53. data/plugins/auto_indenter/lib/auto_indenter/commands.rb +34 -0
  54. data/plugins/auto_indenter/lib/auto_indenter/document_controller.rb +67 -12
  55. data/plugins/auto_indenter/lib/auto_indenter/rules.rb +41 -0
  56. data/plugins/auto_indenter/spec/auto_indenter/analyzer_spec.rb +151 -0
  57. data/plugins/auto_indenter/spec/spec_helper.rb +5 -0
  58. data/plugins/auto_pairer/lib/auto_pairer.rb +1 -0
  59. data/plugins/auto_pairer/lib/auto_pairer/document_controller.rb +43 -42
  60. data/plugins/auto_pairer/lib/auto_pairer/pairs_for_scope.rb +1 -5
  61. data/plugins/core/lib/core.rb +12 -1
  62. data/plugins/core/lib/core/observable.rb +7 -7
  63. data/plugins/core/lib/core/persistent_cache.rb +14 -2
  64. data/plugins/core/lib/core/plugin.rb +7 -0
  65. data/plugins/core/lib/core/resource.rb +78 -0
  66. data/plugins/core/lib/core/task.rb +62 -0
  67. data/plugins/core/lib/core/task_queue.rb +72 -0
  68. data/plugins/core/spec/core/resource_spec.rb +124 -0
  69. data/plugins/core/spec/core/task_queue_spec.rb +202 -0
  70. data/plugins/core/spec/spec_helper.rb +23 -1
  71. data/plugins/declarations/TODO +3 -0
  72. data/plugins/declarations/lib/declarations.rb +144 -0
  73. data/plugins/declarations/lib/declarations/completion_source.rb +22 -0
  74. data/plugins/declarations/lib/declarations/file.rb +68 -0
  75. data/plugins/declarations/lib/declarations/parser.rb +94 -0
  76. data/plugins/declarations/lib/declarations/select_tag_dialog.rb +44 -0
  77. data/plugins/declarations/plugin.rb +7 -0
  78. data/plugins/declarations/spec/declarations/file_spec.rb +62 -0
  79. data/plugins/declarations/spec/fixtures/federalist.rb +15 -0
  80. data/plugins/declarations/spec/spec_helper.rb +4 -0
  81. data/plugins/edit_view/features/indentation_commands.feature +40 -0
  82. data/plugins/edit_view/features/line_delimiter.feature +40 -0
  83. data/plugins/edit_view/features/step_definitions/editing_steps.rb +16 -4
  84. data/plugins/edit_view/features/step_definitions/notebook_steps.rb +1 -1
  85. data/plugins/edit_view/features/step_definitions/tab_steps.rb +1 -1
  86. data/plugins/edit_view/features/step_definitions/window_steps.rb +5 -1
  87. data/plugins/edit_view/features/support/env.rb +3 -5
  88. data/plugins/edit_view/features/undo_and_redo.feature +21 -0
  89. data/plugins/edit_view/lib/edit_view.rb +57 -4
  90. data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +19 -3
  91. data/plugins/edit_view/lib/edit_view/document.rb +46 -11
  92. data/plugins/edit_view/lib/edit_view/document/indentation.rb +35 -0
  93. data/plugins/edit_view/lib/edit_view/modified_tabs_checker.rb +35 -0
  94. data/plugins/edit_view/lib/edit_view/tab_settings.rb +13 -3
  95. data/plugins/edit_view/spec/edit_view/document/indentation_spec.rb +112 -0
  96. data/plugins/edit_view/spec/edit_view/document_spec.rb +22 -0
  97. data/plugins/edit_view/spec/spec_helper.rb +1 -0
  98. data/plugins/edit_view_swt/lib/edit_view_swt.rb +59 -7
  99. data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +3 -3
  100. data/plugins/edit_view_swt/lib/edit_view_swt/word_movement.rb +2 -2
  101. data/plugins/edit_view_swt/vendor/java-mateview.rb +3 -2
  102. data/plugins/encryption/encryption.rb +13 -6
  103. data/plugins/execute_current_tab/lib/execute_current_tab.rb +25 -15
  104. data/plugins/html_view/assets/redcar.css +32 -1
  105. data/plugins/html_view/lib/html_view.rb +23 -3
  106. data/plugins/html_view/lib/html_view/html_tab.rb +4 -0
  107. data/plugins/my_plugin/lib/my_plugin.rb +4 -12
  108. data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +1 -0
  109. data/plugins/plugin_manager_ui/views/index.html.erb +30 -37
  110. data/plugins/project/features/find_file.feature +75 -0
  111. data/plugins/project/features/open_and_save_files.feature +7 -7
  112. data/plugins/project/features/open_directory_tree.feature +11 -3
  113. data/plugins/project/features/refresh_directory_tree.feature +7 -1
  114. data/plugins/project/features/step_definitions/directory_steps.rb +11 -1
  115. data/plugins/project/features/step_definitions/file_steps.rb +10 -0
  116. data/plugins/project/features/support/env.rb +6 -1
  117. data/plugins/project/features/watch_for_modified_files.feature +79 -0
  118. data/plugins/project/lib/project.rb +72 -306
  119. data/plugins/project/lib/project/commands.rb +128 -0
  120. data/plugins/project/lib/project/dir_mirror.rb +5 -1
  121. data/plugins/project/lib/project/drb_service.rb +21 -31
  122. data/plugins/project/lib/project/file_list.rb +76 -0
  123. data/plugins/project/lib/project/file_mirror.rb +13 -1
  124. data/plugins/project/lib/project/find_file_dialog.rb +22 -52
  125. data/plugins/project/lib/project/manager.rb +210 -0
  126. data/plugins/project/lib/project/recent_directories.rb +16 -3
  127. data/plugins/project/plugin.rb +1 -1
  128. data/plugins/project/spec/fixtures/myproject/README +2 -0
  129. data/plugins/project/spec/fixtures/myproject/lib/foo_lib.rb +1 -0
  130. data/plugins/project/spec/fixtures/myproject/spec/foo_spec.rb +1 -0
  131. data/plugins/project/{features → spec}/fixtures/winter.txt +0 -0
  132. data/plugins/project/spec/project/dir_mirror_spec.rb +1 -12
  133. data/plugins/project/spec/project/file_list_spec.rb +140 -0
  134. data/plugins/project/spec/spec_helper.rb +20 -0
  135. data/plugins/redcar/plugin.rb +1 -0
  136. data/plugins/redcar/redcar.rb +254 -84
  137. data/plugins/redcar_debug/lib/redcar_debug.rb +58 -11
  138. data/plugins/redcar_debug/vendor/jruby-prof/README +46 -0
  139. data/plugins/redcar_debug/vendor/jruby-prof/Rakefile +36 -0
  140. data/plugins/redcar_debug/vendor/jruby-prof/build.xml +31 -0
  141. data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.html +22677 -0
  142. data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.txt +589 -0
  143. data/plugins/redcar_debug/vendor/jruby-prof/example/flat.txt +28 -0
  144. data/plugins/redcar_debug/vendor/jruby-prof/example/graph.html +1670 -0
  145. data/plugins/redcar_debug/vendor/jruby-prof/example/graph.txt +125 -0
  146. data/plugins/redcar_debug/vendor/jruby-prof/example/pidigits.rb +92 -0
  147. data/plugins/redcar_debug/vendor/jruby-prof/example/test.rb +28 -0
  148. data/plugins/redcar_debug/vendor/jruby-prof/example/test2.rb +29 -0
  149. data/plugins/redcar_debug/vendor/jruby-prof/example/test_exception.rb +28 -0
  150. data/plugins/redcar_debug/vendor/jruby-prof/example/test_overhead.rb +43 -0
  151. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof.rb +66 -0
  152. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/abstract_printer.rb +21 -0
  153. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/flat_text_printer.rb +35 -0
  154. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_html_printer.rb +123 -0
  155. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_text_printer.rb +45 -0
  156. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/invocation_set.rb +34 -0
  157. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/method.rb +107 -0
  158. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/profile_invocation.rb +43 -0
  159. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/simple_tree_printer.rb +27 -0
  160. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/tree_html_printer.rb +144 -0
  161. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/Invocation.java +14 -0
  162. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/JRubyProf.java +94 -0
  163. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/ProfEventHook.java +49 -0
  164. data/plugins/redcar_debug/vendor/jruby-prof/templates/graph_row.html.erb +18 -0
  165. data/plugins/redcar_debug/vendor/jruby-prof/test/basic_test.rb +291 -0
  166. data/plugins/redcar_debug/views/history.html.erb +33 -0
  167. data/plugins/redcar_debug/views/index.html.erb +33 -0
  168. data/plugins/repl/lib/repl/internal_mirror.rb +3 -15
  169. data/plugins/repl/spec/repl/internal_mirror_spec.rb +2 -2
  170. data/plugins/snippets/lib/snippets.rb +0 -1
  171. data/plugins/snippets/lib/snippets/document_controller.rb +7 -1
  172. data/plugins/task_manager/lib/task_manager.rb +28 -0
  173. data/plugins/task_manager/plugin.rb +11 -0
  174. data/plugins/task_manager/views/index.html.erb +67 -0
  175. data/plugins/textmate/lib/textmate.rb +17 -21
  176. data/plugins/textmate/lib/textmate/plist.rb +1 -2
  177. data/plugins/textmate/lib/textmate/preference.rb +5 -1
  178. data/plugins/textmate/lib/textmate/snippet.rb +6 -1
  179. data/plugins/tree_view_swt/lib/tree_view_swt.rb +0 -6
  180. data/textmate/Bundles/Cucumber.tmbundle/Preferences/Comments.tmPreferences +1 -1
  181. data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Cucumber_Plain_Text_Feature_Completions.tmPreferences +30 -0
  182. data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Symbol_list___Scenario.tmPreferences +19 -0
  183. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Plain_Text_Feature.tmLanguage +221 -0
  184. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Steps.tmLanguage +424 -0
  185. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/plaintext_template.erb +19 -77
  186. data/textmate/Bundles/Cucumber.tmbundle/info.plist +1 -20
  187. data/textmate/Bundles/Perl.tmbundle/Syntaxes/Perl.plist +1 -1
  188. data/textmate/Themes/Emacs Strict.tmTheme +241 -0
  189. data/textmate/Themes/IR_White.tmTheme +792 -0
  190. data/textmate/Themes/Monokai.tmTheme +291 -0
  191. data/textmate/Themes/WhysPoignant.tmTheme +191 -0
  192. metadata +92 -7
  193. data/plugins/application/features/main_window.feature +0 -8
  194. data/plugins/project/lib/project/project_command.rb +0 -5
  195. data/textmate/Bundles/Cucumber.tmbundle/Snippets/Scenario.tmSnippet +0 -22
  196. data/textmate/Bundles/Cucumber.tmbundle/Snippets/Story.tmSnippet +0 -25
@@ -0,0 +1,34 @@
1
+
2
+ module Redcar
3
+ class AutoIndenter
4
+
5
+ class IndentCommand < Redcar::EditTabCommand
6
+
7
+ def execute
8
+ if doc.selection?
9
+ selection = true
10
+ start_line, end_line = *[doc.selection_line, doc.cursor_line].sort
11
+ else
12
+ selection = false
13
+ start_line = end_line = doc.cursor_line
14
+ end
15
+ rules = AutoIndenter.rules_for_scope(doc.cursor_scope)
16
+ analyzer = Analyzer.new(rules, doc, doc.edit_view.tab_width, doc.edit_view.soft_tabs?)
17
+ indentation = doc.indentation
18
+ start_line.upto(end_line) do |line_ix|
19
+ indentation.set_level(line_ix, analyzer.calculate_for_line(line_ix, false))
20
+ end
21
+
22
+ return unless selection
23
+
24
+ start_offset = doc.offset_at_line(start_line)
25
+ if end_line == doc.line_count - 1
26
+ end_offset = doc.length
27
+ else
28
+ end_offset = doc.offset_at_line(end_line + 1)
29
+ end
30
+ doc.set_selection_range(start_offset, end_offset)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -3,24 +3,79 @@ module Redcar
3
3
  class AutoIndenter
4
4
  class DocumentController
5
5
  include Redcar::Document::Controller
6
+ include Redcar::Document::Controller::ModificationCallbacks
6
7
  include Redcar::Document::Controller::NewlineCallback
7
8
 
8
- def after_newline(line_ix)
9
- if line_ix > 0
10
- previous_line = document.get_line(line_ix - 1).gsub(document.delim, "")
11
- whitespace_prefix = whitespace_prefix(previous_line)
12
- offset = document.offset_at_line(line_ix)
13
- document.insert(offset, whitespace_prefix)
14
- if document.cursor_offset == offset
15
- document.cursor_offset = offset + whitespace_prefix.length
9
+ def disable
10
+ increase_ignore
11
+ result = yield
12
+ decrease_ignore
13
+ result
14
+ end
15
+
16
+ def ignore?
17
+ @ignore
18
+ end
19
+
20
+ def increase_ignore
21
+ @ignore ||= 0
22
+ @ignore += 1
23
+ end
24
+
25
+ def decrease_ignore
26
+ @ignore -= 1
27
+ @ignore = nil if @ignore == 0
28
+ end
29
+
30
+ def before_modify(start_offset, end_offset, text)
31
+ return if ignore? or in_snippet?
32
+
33
+ @start_offset, @end_offset, @text = start_offset, end_offset, text
34
+ line = document.get_line(document.cursor_line)
35
+ rules = AutoIndenter.rules_for_scope(document.cursor_scope)
36
+ @flags = get_flags(line, rules)
37
+ end
38
+
39
+ def in_snippet?
40
+ snippet_controller = document.controllers(Snippets::DocumentController).first and
41
+ snippet_controller.in_snippet?
42
+ end
43
+
44
+ def get_flags(line, rules)
45
+ [rules.increase_indent?(line), rules.decrease_indent?(line), rules.indent_next_line?(line), rules.unindented_line?(line)]
46
+ end
47
+
48
+ def after_modify
49
+ return if ignore? or in_snippet?
50
+ start_line_ix = document.line_at_offset(@start_offset)
51
+ end_line_ix = document.line_at_offset([[@start_offset + @text.length, document.length - 1].min, 0].max)
52
+ if start_line_ix == end_line_ix
53
+ rules = AutoIndenter.rules_for_scope(document.cursor_scope)
54
+ line = document.get_line(start_line_ix)
55
+ if get_flags(line, rules) != @flags
56
+ edit_view = document.edit_view
57
+ analyzer = Analyzer.new(rules, document, edit_view.tab_width, edit_view.soft_tabs?)
58
+ increase_ignore
59
+ document.indentation.set_level(start_line_ix, analyzer.calculate_for_line(start_line_ix, true))
60
+ decrease_ignore
16
61
  end
17
62
  end
18
63
  end
19
64
 
20
- private
21
-
22
- def whitespace_prefix(string)
23
- string[/^(\s*)(?:[^\s]|$)/, 1]
65
+ def after_newline(line_ix)
66
+ return if ignore? or in_snippet?
67
+ rules = AutoIndenter.rules_for_scope(document.cursor_scope)
68
+ if line_ix > 0
69
+ indentation = document.indentation
70
+ current_level = indentation.get_level(line_ix - 1)
71
+ edit_view = document.edit_view
72
+ analyzer = Analyzer.new(rules, document, edit_view.tab_width, edit_view.soft_tabs?)
73
+ increase_ignore
74
+ indentation.set_level(line_ix, analyzer.calculate_for_line(line_ix, true))
75
+ decrease_ignore
76
+ prefix = indentation.whitespace_prefix(line_ix)
77
+ document.cursor_offset = document.offset_at_line(line_ix) + prefix.length
78
+ end
24
79
  end
25
80
  end
26
81
  end
@@ -0,0 +1,41 @@
1
+
2
+ module Redcar
3
+ class AutoIndenter
4
+ class Rules
5
+ def initialize(increase_indent_pattern,
6
+ decrease_indent_pattern,
7
+ indent_next_line_pattern=nil,
8
+ unindented_line_pattern=nil)
9
+ @increase_indent_pattern = increase_indent_pattern
10
+ @decrease_indent_pattern = decrease_indent_pattern
11
+ @indent_next_line_pattern = indent_next_line_pattern
12
+ @unindented_line_pattern = unindented_line_pattern
13
+ end
14
+
15
+ def increase_indent?(line)
16
+ if @increase_indent_pattern
17
+ !!(line =~ @increase_indent_pattern)
18
+ end
19
+ end
20
+
21
+ def decrease_indent?(line)
22
+ if @decrease_indent_pattern
23
+ !!(line =~ @decrease_indent_pattern)
24
+ end
25
+ end
26
+
27
+ def indent_next_line?(line)
28
+ if @indent_next_line_pattern
29
+ !!(line =~ @indent_next_line_pattern)
30
+ end
31
+ end
32
+
33
+ def unindented_line?(line)
34
+ if @unindented_line_pattern
35
+ !!(line =~ @unindented_line_pattern)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,151 @@
1
+
2
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
+
4
+ include Redcar
5
+
6
+ describe AutoIndenter::Analyzer do
7
+ class FakeDocument
8
+ def initialize(string, tab_width, soft_tabs)
9
+ @string = string
10
+ @tab_width, @soft_tab = tab_width, soft_tabs
11
+ end
12
+
13
+ def get_line(ix)
14
+ lines[ix] + "\n"
15
+ end
16
+
17
+ def lines
18
+ @string.split("\n")
19
+ end
20
+
21
+ def indentation
22
+ Document::Indentation.new(self, @tab_width, @soft_tabs)
23
+ end
24
+ end
25
+
26
+ describe "with indentation rules like Ruby's" do
27
+ def should_indent(src, options)
28
+ simple_rules = AutoIndenter::Rules.new(/def/, /end/)
29
+ analyzer = AutoIndenter::Analyzer.new(simple_rules, FakeDocument.new(src, 2, true), 2, true)
30
+ analyzer.calculate_for_line(options[:line]).should == options[:indent]
31
+ end
32
+
33
+ it "should indent after an increase indent line" do
34
+ should_indent(<<RUBY, :line => 1, :indent => 1)
35
+ def foo
36
+ # should be indented
37
+ RUBY
38
+ end
39
+
40
+ it "should decrease indent for a decrease indent line" do
41
+ should_indent(<<RUBY, :line => 1, :indent => 1)
42
+ p :adsf
43
+ end # should be dedented
44
+ p :adsf
45
+ RUBY
46
+ end
47
+
48
+ it "should set indent to match previous line" do
49
+ should_indent(<<RUBY, :line => 3, :indent => 0)
50
+ def foo
51
+
52
+ end
53
+ p :asdf # should be dedented
54
+ RUBY
55
+ end
56
+
57
+ it "should set indent to match previous line if an increase cancels out a decrease" do
58
+ should_indent(<<RUBY, :line => 1, :indent => 0)
59
+ def foo
60
+ end # should be dedented
61
+ RUBY
62
+ end
63
+ end
64
+
65
+ describe "with indentation rules like C's" do
66
+ def should_indent(options)
67
+ simple_rules = AutoIndenter::Rules.new(
68
+ /\{/,
69
+ /\}/,
70
+ /^(?!.*;\s*\/\/).*[^\s;{}]\s*$/,
71
+ /^\s*(\/\/|#).*$/
72
+ )
73
+ analyzer = AutoIndenter::Analyzer.new(simple_rules, FakeDocument.new(source, 4, false), 4, false)
74
+ analyzer.calculate_for_line(options[:line]).should == options[:indent]
75
+ end
76
+
77
+ def source
78
+ t=<<-CSOURCE
79
+ int main (int argc, char const* argv[]) {
80
+ while(true) {
81
+ if(something())
82
+ break;
83
+ #if 3
84
+ play_awful_music();
85
+ #else
86
+ play_nice_music();
87
+ #endif
88
+ }
89
+ return 0;
90
+ }
91
+
92
+ if (foo)
93
+ break;
94
+
95
+ if (foo)
96
+ {
97
+ d;
98
+
99
+ CSOURCE
100
+ end
101
+
102
+ it "should set indentation on the first line to 0" do
103
+ should_indent(:line => 0, :indent => 0)
104
+ end
105
+
106
+ it "should increase indent" do
107
+ should_indent(:line => 1, :indent => 1)
108
+ end
109
+
110
+ it "should increase indent (2)" do
111
+ should_indent(:line => 2, :indent => 2)
112
+ end
113
+
114
+ it "should indent next line" do
115
+ should_indent(:line => 3, :indent => 3)
116
+ should_indent(:line => 14, :indent => 1)
117
+ end
118
+
119
+ it "should leave unindented lines as they are" do
120
+ should_indent(:line => 4, :indent => 0)
121
+ should_indent(:line => 6, :indent => 2)
122
+ should_indent(:line => 8, :indent => 0)
123
+ end
124
+
125
+ it "should return to indent after unindented line" do
126
+ should_indent(:line => 7, :indent => 2)
127
+ end
128
+
129
+ it "should return to indent after unindented line, and next-line indent before that" do
130
+ should_indent(:line => 5, :indent => 2)
131
+ end
132
+
133
+ it "should decrease indent" do
134
+ should_indent(:line => 9, :indent => 1)
135
+ should_indent(:line => 11, :indent => 0)
136
+ end
137
+
138
+ it "should match indent" do
139
+ should_indent(:line => 10, :indent => 1)
140
+ end
141
+
142
+ it "should not indent next lines if the next line matches the increase indent" do
143
+ should_indent(:line => 17, :indent => 0)
144
+ end
145
+
146
+ it "should still increase the indent after an increase indent line after an increase next line" do
147
+ should_indent(:line => 18, :indent => 1)
148
+ end
149
+ end
150
+ end
151
+
@@ -0,0 +1,5 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ require 'redcar'
4
+ Redcar.environment = :test
5
+ Redcar.load
@@ -9,3 +9,4 @@ module Redcar
9
9
  end
10
10
  end
11
11
  end
12
+
@@ -93,50 +93,51 @@ module Redcar
93
93
  def after_modify
94
94
  return if ignore?
95
95
  @done = nil
96
-
97
- # Deleted start of a mark pair
98
- if @end_offset == @start_offset + 1 and !@ignore_delete
99
- mark_pair = find_mark_pair_by_start(@start_offset)
100
- if mark_pair
96
+ document.controllers(AutoIndenter::DocumentController).first.disable do
97
+ # Deleted start of a mark pair
98
+ if @end_offset == @start_offset + 1 and !@ignore_delete
99
+ mark_pair = find_mark_pair_by_start(@start_offset)
100
+ if mark_pair
101
+ @ignore_delete = true
102
+ document.delete(mark_pair.end_mark.get_offset, 1)
103
+ @ignore_delete = false
104
+ @mark_pairs.delete(mark_pair)
105
+ @deletion = nil
106
+ end
107
+ end
108
+
109
+ # Type over ends
110
+ if @type_over_end
111
+ @type_over_end = false
101
112
  @ignore_delete = true
102
- document.delete(mark_pair.end_mark.get_offset, 1)
103
- @ignore_delete = false
104
- @mark_pairs.delete(mark_pair)
105
- @deletion = nil
113
+ document.delete(@end_offset, 1)
114
+ @ignore_delete = nil
115
+ document.cursor_offset += 1
116
+ #@buffer.parser.start_parsing
117
+ @done = true
118
+ end
119
+
120
+ # Insert matching ends
121
+ if @insert_end and !@ignore_insert
122
+ @ignore_insert = true
123
+ endtext = @rules[@text]
124
+ document.insert(@start_offset + 1, endtext)
125
+ mark1 = document.create_mark(@start_offset - 1, :right)
126
+ mark2 = document.create_mark(@start_offset, :right)
127
+ add_mark_pair(MarkPair.new(mark1, mark2, @text, endtext))
128
+ @ignore_insert = false
129
+ #@buffer.parser.start_parsing
130
+ @insert_end = false
131
+ end
132
+
133
+ if @selected_text and !@ignore_insert
134
+ @ignore_insert = true
135
+ offset = document.cursor_offset
136
+ document.insert(@start_offset, @selected_text)
137
+ document.cursor_offset = offset + @selected_text.length + 1
138
+ @ignore_insert = false
139
+ @selected_text = nil
106
140
  end
107
- end
108
-
109
- # Type over ends
110
- if @type_over_end
111
- @type_over_end = false
112
- @ignore_delete = true
113
- document.delete(@end_offset, 1)
114
- @ignore_delete = nil
115
- document.cursor_offset += 1
116
- #@buffer.parser.start_parsing
117
- @done = true
118
- end
119
-
120
- # Insert matching ends
121
- if @insert_end and !@ignore_insert
122
- @ignore_insert = true
123
- endtext = @rules[@text]
124
- document.insert(@start_offset + 1, endtext)
125
- mark1 = document.create_mark(@start_offset - 1, :right)
126
- mark2 = document.create_mark(@start_offset, :right)
127
- add_mark_pair(MarkPair.new(mark1, mark2, @text, endtext))
128
- @ignore_insert = false
129
- #@buffer.parser.start_parsing
130
- @insert_end = false
131
- end
132
-
133
- if @selected_text and !@ignore_insert
134
- @ignore_insert = true
135
- offset = document.cursor_offset
136
- document.insert(@start_offset, @selected_text)
137
- document.cursor_offset = offset + @selected_text.length + 1
138
- @ignore_insert = false
139
- @selected_text = nil
140
141
  end
141
142
  false
142
143
  end
@@ -5,10 +5,7 @@ module Redcar
5
5
  @autopair_rules ||= begin
6
6
  rules = Hash.new {|h, k| h[k] = {}}
7
7
  @autopair_default = nil
8
- start = Time.now
9
- pair_settings = Textmate.all_settings.select do |setting|
10
- setting.is_a?(Textmate::SmartTypingPairsSetting)
11
- end
8
+ pair_settings = Textmate.settings(Textmate::SmartTypingPairsSetting)
12
9
  pair_settings.each do |setting|
13
10
  if setting.scope
14
11
  rules[setting.scope] = Hash[*setting.pairs.flatten]
@@ -19,7 +16,6 @@ module Redcar
19
16
  if @autopair_default
20
17
  @autopair_default1 = @autopair_default.invert
21
18
  end
22
- puts "loaded autopair rules in #{Time.now - start}s"
23
19
  rules.default = nil
24
20
  rules
25
21
  end