Class: Textbringer::ProgrammingMode

Inherits:
FundamentalMode show all
Defined in:
lib/textbringer/modes/programming_mode.rb,
sig/lib/textbringer/mode.rbs,
sig/lib/textbringer/modes/programming_mode.rbs

Direct Known Subclasses

CMode, RubyMode

Constant Summary

Constants inherited from Mode

Mode::DEFAULT_SYNTAX_TABLE

Constants included from Commands

Commands::CLIPBOARD_AVAILABLE, Commands::COMPLETION_POPUP_STATUS, Commands::CTAGS, Commands::EMAIL_REGEXP, Commands::HELP_RING, Commands::ISEARCH_STATUS, Commands::ISPELL_STATUS, Commands::ISPELL_WORD_REGEXP, Commands::KEYBOARD_MACROS, Commands::LSP_DOCUMENT_VERSIONS, Commands::LSP_STATUS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS, Commands::URI_REGEXP

Constants included from Utils

Utils::COMPLETION, Utils::EXPRESSION_COMPLETOR, Utils::EXPRESSION_COMPLETOR_OPTIONS, Utils::HOOKS

Instance Attribute Summary

Attributes inherited from Mode

#buffer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FundamentalMode

#symbol_pattern

Methods inherited from Mode

define_local_command, define_syntax, #highlight, list, #name, #syntax_table

Methods included from Commands

[], #buffer_uri, #command_help, command_table, #completion_popup_done, completion_popup_mode_active?, #completion_popup_pre_command_hook, #completion_popup_start, #current_prefix_arg, define_command, #ensure_ispell_active, #execute_keyboard_macro, #get_tags, #insert_completion, #isearch_done, #isearch_mode, #isearch_mode?, #isearch_pre_command_hook, #isearch_prompt, #isearch_repeat, #isearch_repeat_backward, #isearch_repeat_forward, #isearch_search, #ispell_done, #ispell_forward, #ispell_mode, #keymap_bindings, list, #lsp_after_set_visited_file_name_hook, #lsp_close_signature_window, #lsp_completion_context, #lsp_find_file_hook, #lsp_open_document, #lsp_position, #lsp_setup_buffer_hooks, #lsp_show_signature_window, #lsp_signature_pre_command_hook, #lsp_text_document_sync_kind, #lsp_utf16_length, #match_beginning, #match_end, #match_string, #message_misspelled, #number_prefix_arg, #prefix_numeric_value, #read_input_method_name, #read_keyboard_macro, #read_register, #read_theme_name, #replace_match, undefine_command, #universal_argument_mode

Methods included from Utils

add_hook, background, complete_for_minibuffer, delete_completions_window, foreground, foreground!, get_hooks, message, read_buffer, read_char, read_command_name, read_encoding, read_event, read_expression, read_file_name, read_from_minibuffer, read_key_sequence, read_object, read_single_char, received_keyboard_quit?, remove_hook, ruby_install_name, run_hooks, run_hooks_in, self_insert_and_exit_minibuffer, set_transient_map, show_exception, sit_for, sleep_for, with_clean_env, y_or_n?, yes_or_no?

Constructor Details

#initialize(buffer) ⇒ ProgrammingMode

Returns a new instance of ProgrammingMode.

Parameters:



35
36
37
38
# File 'lib/textbringer/modes/programming_mode.rb', line 35

def initialize(buffer)
  super(buffer)
  buffer.keymap = PROGRAMMING_MODE_MAP
end

Class Method Details

.define_generic_commandSymbol

Parameters:

  • (Symbol)
  • (String)

Returns:

  • (Symbol)


18
# File 'sig/lib/textbringer/mode.rbs', line 18

def self.define_generic_command: (Symbol, **String) -> Symbol

.inheritedHash[untyped, untyped]

Parameters:

  • (Class)

Returns:

  • (Hash[untyped, untyped])


20
# File 'sig/lib/textbringer/mode.rbs', line 20

def self.inherited: (Class) -> Hash[untyped, untyped]

Instance Method Details

#calculate_indentationnil

Returns:

  • (nil)

Raises:



122
123
124
# File 'lib/textbringer/modes/programming_mode.rb', line 122

def calculate_indentation
  raise EditorError, "indent_line is not defined in the current mode"
end

#comment_startObject



116
117
118
# File 'lib/textbringer/modes/programming_mode.rb', line 116

def comment_start
  nil
end

#indent_lineBoolean #indent_linenil

Return true if modified.

Overloads:

  • #indent_lineBoolean

    Returns:

    • (Boolean)
  • #indent_linenil

    Returns:

    • (nil)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/textbringer/modes/programming_mode.rb', line 41

def indent_line
  result = false
  level = calculate_indentation
  return result if level.nil? || level < 0
  @buffer.save_excursion do
    @buffer.beginning_of_line
    @buffer.composite_edit do
      if @buffer.looking_at?(/[ \t]+/)
        s = @buffer.match_string(0)
        break if /\t/ !~ s && s.size == level
        @buffer.delete_region(@buffer.match_beginning(0),
                              @buffer.match_end(0))
      else
        break if level == 0
      end
      @buffer.indent_to(level)
    end
    result = true
  end
  pos = @buffer.point
  @buffer.beginning_of_line
  @buffer.forward_char while /[ \t]/ =~ @buffer.char_after
  if @buffer.point < pos
    @buffer.goto_char(pos)
  end
  result
end

#indent_new_comment_lineTextbringer::Buffer

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/textbringer/modes/programming_mode.rb', line 100

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

#indent_region(s = @buffer.mark, e = @buffer.point) ⇒ nil

Parameters:

  • (Integer)
  • (Integer)

Returns:

  • (nil)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/textbringer/modes/programming_mode.rb', line 84

def indent_region(s = @buffer.mark, e = @buffer.point)
  s, e = Buffer.region_boundaries(s, e)
  end_mark = @buffer.new_mark(e)
  begin
    @buffer.save_excursion do
      @buffer.goto_char(s)
      until @buffer.end_of_buffer? || @buffer.point_after_mark?(end_mark)
        indent_line
        @buffer.forward_line
      end
    end
  ensure
    end_mark.delete
  end
end

#reindent_then_newline_and_indentnil

Returns:

  • (nil)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/textbringer/modes/programming_mode.rb', line 69

def reindent_then_newline_and_indent
  @buffer.composite_edit do
    indent_line
    @buffer.save_excursion do
      pos = @buffer.point
      @buffer.beginning_of_line
      if /\A[ \t]+\z/.match?(@buffer.substring(@buffer.point, pos))
        @buffer.delete_region(@buffer.point, pos)
      end
    end
    @buffer.insert("\n")
    indent_line
  end
end