lib/textbringer/modes/programming_mode.rb in textbringer-1.0.1 vs lib/textbringer/modes/programming_mode.rb in textbringer-1.0.2

- old
+ new

@@ -8,20 +8,22 @@ define_generic_command :indent_region define_generic_command :forward_definition define_generic_command :backward_definition define_generic_command :compile define_generic_command :toggle_test + define_generic_command :indent_new_comment_line - PROGRAMMING_MODE_MAP = Keymap.new + define_keymap :PROGRAMMING_MODE_MAP PROGRAMMING_MODE_MAP.define_key("\t", :indent_line_command) PROGRAMMING_MODE_MAP.define_key("\C-m", :reindent_then_newline_and_indent_command) - PROGRAMMING_MODE_MAP.define_key("\e\C-\\", :indent_region_command) + PROGRAMMING_MODE_MAP.define_key("\M-\C-\\", :indent_region_command) PROGRAMMING_MODE_MAP.define_key("\C-c\C-n", :forward_definition_command) PROGRAMMING_MODE_MAP.define_key("\C-c\C-p", :backward_definition_command) PROGRAMMING_MODE_MAP.define_key("\C-c\C-c", :compile_command) PROGRAMMING_MODE_MAP.define_key("\C-c\C-t", :toggle_test_command) + PROGRAMMING_MODE_MAP.define_key("\ej", :indent_new_comment_line_command) def initialize(buffer) super(buffer) buffer.keymap = PROGRAMMING_MODE_MAP end @@ -82,9 +84,29 @@ end end ensure end_mark.delete end + end + + def indent_new_comment_line + if comment_start.nil? + @buffer.newline + return + end + s = @buffer.save_excursion { + @buffer.beginning_of_line + if @buffer.looking_at?(/[ \t]*#{comment_start}+[ \t]*/) + @buffer.match_string(0) + else + "" + end + } + @buffer.insert("\n" + s) + end + + def comment_start + nil end private def calculate_indentation