Sha256: eec29c98819261ef82ba44281cba064498a7f6e057e0fdc0485c872f0a578fc5
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true module Textbringer class ProgrammingMode < FundamentalMode # abstract mode undefine_command(:programming_mode) define_generic_command :indent_line define_generic_command :newline_and_reindent define_generic_command :forward_definition define_generic_command :backward_definition define_generic_command :compile define_generic_command :toggle_test PROGRAMMING_MODE_MAP = Keymap.new PROGRAMMING_MODE_MAP.define_key("\t", :indent_line_command) PROGRAMMING_MODE_MAP.define_key("\n", :newline_and_reindent_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-ct", :toggle_test_command) def initialize(buffer) super(buffer) buffer.keymap = PROGRAMMING_MODE_MAP end def newline_and_reindent n = 1 if indent_line n += 1 end @buffer.save_excursion do pos = @buffer.point @buffer.beginning_of_line if /\A\s+\z/ =~ @buffer.substring(@buffer.point, pos) @buffer.delete_region(@buffer.point, pos) n += 1 end end @buffer.insert("\n") if indent_line n += 1 end @buffer.merge_undo(n) if n > 1 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
textbringer-0.1.6 | lib/textbringer/modes/programming_mode.rb |
textbringer-0.1.5 | lib/textbringer/modes/programming_mode.rb |
textbringer-0.1.4 | lib/textbringer/modes/programming_mode.rb |