textbringer 27 → 28

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.
@@ -78,6 +78,25 @@ module Textbringer
78
78
  self.class.mode_name
79
79
  end
80
80
 
81
+ # The string that starts a line comment in this mode, or nil if the
82
+ # mode has no line comments.
83
+ def comment_start
84
+ nil
85
+ end
86
+
87
+ # A regexp matching what begins a comment line: the indentation, the
88
+ # comment leader, and the blanks after it. indent_new_comment_line
89
+ # repeats the match on the new line, and fill_paragraph uses it to
90
+ # tell comment lines from code and to keep the leader on each filled
91
+ # line. nil if the mode has no comment lines. Modes whose block
92
+ # comments continue with a leader of their own, as C's do with " * ",
93
+ # override this.
94
+ def comment_prefix_regexp
95
+ if comment_start
96
+ /[ \t]*#{Regexp.quote(comment_start)}+[ \t]*/
97
+ end
98
+ end
99
+
81
100
  def syntax_table
82
101
  self.class.syntax_table
83
102
  end
@@ -38,6 +38,12 @@ module Textbringer
38
38
  "//"
39
39
  end
40
40
 
41
+ # "//" comments, and the " * " lines of a block comment. The "/*"
42
+ # and " */" lines are not matched, so they bound the paragraph.
43
+ def comment_prefix_regexp
44
+ /[ \t]*(?:\/\/+|\*+(?![*\/]))[ \t]*/
45
+ end
46
+
41
47
  def initialize(buffer)
42
48
  super(buffer)
43
49
  @buffer[:indent_level] = CONFIG[:c_indent_level]
@@ -98,13 +98,14 @@ module Textbringer
98
98
  end
99
99
 
100
100
  def indent_new_comment_line
101
- if comment_start.nil?
101
+ re = comment_prefix_regexp
102
+ if re.nil?
102
103
  @buffer.newline
103
104
  return
104
105
  end
105
106
  s = @buffer.save_excursion {
106
107
  @buffer.beginning_of_line
107
- if @buffer.looking_at?(/[ \t]*#{comment_start}+[ \t]*/)
108
+ if @buffer.looking_at?(re)
108
109
  @buffer.match_string(0)
109
110
  else
110
111
  ""
@@ -113,10 +114,6 @@ module Textbringer
113
114
  @buffer.insert("\n" + s)
114
115
  end
115
116
 
116
- def comment_start
117
- nil
118
- end
119
-
120
117
  private
121
118
 
122
119
  def calculate_indentation
@@ -153,6 +153,7 @@ module Textbringer
153
153
  KEYWORD_BEGIN_UPCASE: :keyword, KEYWORD_BREAK: :keyword,
154
154
  KEYWORD_CASE: :keyword, KEYWORD_CLASS: :keyword, KEYWORD_DEF: :keyword,
155
155
  KEYWORD_DEFINED: :keyword, KEYWORD_DO: :keyword,
156
+ KEYWORD_DO_BLOCK: :keyword, KEYWORD_DO_LAMBDA: :keyword,
156
157
  KEYWORD_DO_LOOP: :keyword, KEYWORD_ELSE: :keyword,
157
158
  KEYWORD_ELSIF: :keyword, KEYWORD_END: :keyword,
158
159
  KEYWORD_END_UPCASE: :keyword, KEYWORD_ENSURE: :keyword,
@@ -182,7 +183,7 @@ module Textbringer
182
183
  SYMBOL_BEGIN: :string, REGEXP_BEGIN: :string, REGEXP_END: :string,
183
184
  PERCENT_LOWER_I: :string, PERCENT_UPPER_I: :string,
184
185
  PERCENT_LOWER_W: :string, PERCENT_UPPER_W: :string,
185
- PERCENT_LOWER_X: :string,
186
+ PERCENT_LOWER_X: :string, XSTRING_BEGIN: :string,
186
187
  HEREDOC_START: :string, HEREDOC_END: :string,
187
188
  LABEL: :property,
188
189
 
@@ -225,10 +226,12 @@ module Textbringer
225
226
  # Punctuation
226
227
  DOT: :punctuation, COLON_COLON: :punctuation,
227
228
  SEMICOLON: :punctuation, COMMA: :punctuation,
228
- PARENTHESIS_LEFT: :punctuation, PARENTHESIS_RIGHT: :punctuation,
229
+ PARENTHESIS_LEFT: :punctuation, PARENTHESIS_LEFT_GROUPING: :punctuation,
230
+ PARENTHESIS_RIGHT: :punctuation,
229
231
  BRACKET_LEFT: :punctuation, BRACKET_LEFT_ARRAY: :punctuation,
230
232
  BRACKET_RIGHT: :punctuation,
231
- BRACE_LEFT: :punctuation, BRACE_RIGHT: :punctuation,
233
+ BRACE_LEFT: :punctuation, BRACE_LEFT_HASH: :punctuation,
234
+ BRACE_LEFT_ARGUMENT: :punctuation, BRACE_RIGHT: :punctuation,
232
235
  QUESTION_MARK: :punctuation, COLON: :punctuation,
233
236
  LAMBDA_BEGIN: :punctuation,
234
237
 
@@ -268,6 +271,17 @@ module Textbringer
268
271
  LAMBDA_BEGIN: :BRACE_RIGHT,
269
272
  }
270
273
 
274
+ # Newer versions of Prism split some token types. Map them to the
275
+ # original types for indentation.
276
+ NORMALIZED_TOKEN_TYPES = {
277
+ BRACE_LEFT_HASH: :BRACE_LEFT,
278
+ BRACE_LEFT_ARGUMENT: :BRACE_LEFT,
279
+ PARENTHESIS_LEFT_GROUPING: :PARENTHESIS_LEFT,
280
+ KEYWORD_DO_BLOCK: :KEYWORD_DO,
281
+ KEYWORD_DO_LAMBDA: :KEYWORD_DO,
282
+ NEWLINE_TERMINATOR: :NEWLINE,
283
+ }.freeze
284
+
271
285
  INDENT_BEG_RE = /^([ \t]*)(class|module|def|if|unless|case|while|until|for|begin)\b/
272
286
 
273
287
  def space_width(s)
@@ -292,6 +306,7 @@ module Textbringer
292
306
  Prism.lex(source).value.filter_map { |token, _state|
293
307
  type = token.type
294
308
  next if type == :EOF
309
+ type = NORMALIZED_TOKEN_TYPES.fetch(type, type)
295
310
  loc = token.location
296
311
  [[loc.start_line, loc.start_column], type, token.value]
297
312
  }
@@ -1,3 +1,3 @@
1
1
  module Textbringer
2
- VERSION = "27"
2
+ VERSION = "28"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textbringer
3
3
  version: !ruby/object:Gem::Version
4
- version: '27'
4
+ version: '28'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
@@ -503,7 +503,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
503
503
  - !ruby/object:Gem::Version
504
504
  version: '0'
505
505
  requirements: []
506
- rubygems_version: 4.0.16
506
+ rubygems_version: 4.0.20
507
507
  specification_version: 4
508
508
  summary: An Emacs-like text editor
509
509
  test_files: []