textbringer 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7239f854b8c82327c4ee8f1afc538f57d14dc083d51580ac79cf3b8b899ab251
4
- data.tar.gz: be654b2f51c7e445826caadca3324feb3c13fce6c350fcb044768170311baaec
3
+ metadata.gz: 7f61a01528e59c0b8185339a9120fd528602e4df0c8db6b859a3756043309ac2
4
+ data.tar.gz: cd1eef029b832c4fcdd9b7bdf709c29c3e60676d79f7084028ac2c683ca7ef82
5
5
  SHA512:
6
- metadata.gz: 33d3d5398d6c35b76666cefc846e02930106520bfb8ac76f1ec32b1e9abf76f5a0cdde7fa425e3b46bdfe334daf6d6678a9cbf787564588068029bfb325a2288
7
- data.tar.gz: c475825d5801f90bb1d5f960a811a195a8a7e7d5573e5bbe7c67ade0ab47d69d5055ac3831c23b4691b41bdcd98a489ae9d51027ef7feb14ec9ef4906b409b5e
6
+ metadata.gz: 501f358854f97ca17dafdbd3d908d1a29a2ea32f103a596958b48e1f11c7397178334e75dfa369ac779e7df77d92958632790c77d2ffd520e6959a6a071e32a6
7
+ data.tar.gz: d1c443c92cd12df433bdee6df2af8d211ebca023946c268386f813c3292bcc195f4f9cd2b6e17e010ff1d168e31d8ba3da92c75c181644585fe3fdb15d21b532
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.0
2
+
3
+ * toggle_test_command supports RSpec now.
4
+ * Improve auto indentation in the Ruby mode.
5
+
1
6
  ## 0.2.9
2
7
 
3
8
  * Add the following new commands:
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Textbringer
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/textbringer.svg)](https://badge.fury.io/rb/textbringer)
4
- [![Dependency Status](https://gemnasium.com/shugo/textbringer.svg)](https://gemnasium.com/shugo/textbringer)
5
4
  [![Build Status](https://travis-ci.org/shugo/textbringer.svg?branch=master)](https://travis-ci.org/shugo/textbringer)
6
5
  [![Build status](https://ci.appveyor.com/api/projects/status/n20vtpfgcgii5jtc?svg=true)](https://ci.appveyor.com/project/shugo31737/textbringer)
7
6
  [![codecov](https://codecov.io/gh/shugo/textbringer/branch/master/graph/badge.svg)](https://codecov.io/gh/shugo/textbringer)
@@ -160,39 +160,14 @@ module Textbringer
160
160
  def toggle_test
161
161
  case @buffer.file_name
162
162
  when %r'(.*)/test/(.*/)?test_(.*?)\.rb\z'
163
- base = $1
164
- namespace = $2
165
- name = $3
166
- if namespace
167
- paths = Dir.glob("#{base}/{lib,app}/**/#{namespace}#{name}.rb")
168
- if !paths.empty?
169
- find_file(paths.first)
170
- return
171
- end
172
- end
173
- paths = Dir.glob("#{base}/{lib,app}/**/#{name}.rb")
174
- if !paths.empty?
175
- find_file(paths.first)
176
- return
177
- end
178
- raise EditorError, "Test subject not found"
163
+ path = find_test_target_path($1, $2, $3)
164
+ find_file(path)
165
+ when %r'(.*)/spec/(.*/)?(.*?)_spec\.rb\z'
166
+ path = find_test_target_path($1, $2, $3)
167
+ find_file(path)
179
168
  when %r'(.*)/(?:lib|app)/(.*/)?(.*?)\.rb\z'
180
- base = $1
181
- namespace = $2
182
- name = $3
183
- if namespace
184
- paths = Dir.glob("#{base}/test/**/#{namespace}test_#{name}.rb")
185
- if !paths.empty?
186
- find_file(paths.first)
187
- return
188
- end
189
- end
190
- paths = Dir.glob("#{base}/test/**/test_#{name}.rb")
191
- if !paths.empty?
192
- find_file(paths.first)
193
- return
194
- end
195
- raise EditorError, "Test not found"
169
+ path = find_test_path($1, $2, $3)
170
+ find_file(path)
196
171
  else
197
172
  raise EditorError, "Unknown file type"
198
173
  end
@@ -227,6 +202,7 @@ module Textbringer
227
202
  end
228
203
  @buffer.save_excursion do
229
204
  @buffer.beginning_of_line
205
+ start_with_period = @buffer.looking_at?(/[ \t]*\./)
230
206
  bol_pos = @buffer.point
231
207
  base_indentation = beginning_of_indentation
232
208
  start_pos = @buffer.point
@@ -240,8 +216,9 @@ module Textbringer
240
216
  event == :on_tstring_content
241
217
  return nil
242
218
  end
243
- line, column, event, = find_nearest_beginning_token(tokens)
244
- if event == :on_lparen
219
+ i = find_nearest_beginning_token(tokens)
220
+ (line, column), event, = i ? tokens[i] : nil
221
+ if event == :on_lparen && tokens.dig(i + 1, 1) != :on_ignored_nl
245
222
  return column + 1
246
223
  end
247
224
  if line
@@ -272,10 +249,11 @@ module Textbringer
272
249
  _, last_event, last_text = tokens.reverse_each.find { |_, e, _|
273
250
  e != :on_sp && e != :on_nl && e != :on_ignored_nl
274
251
  }
275
- if (last_event == :on_op && last_text != "|") ||
252
+ if start_with_period ||
253
+ (last_event == :on_op && last_text != "|") ||
276
254
  last_event == :on_period ||
277
- (last_event == :on_comma &&
278
- event != :on_lbrace && event != :on_lbracket)
255
+ (last_event == :on_comma && event != :on_lbrace &&
256
+ event != :on_lparen && event != :on_lbracket)
279
257
  indentation += @buffer[:indent_level]
280
258
  end
281
259
  indentation
@@ -291,7 +269,7 @@ module Textbringer
291
269
  def find_nearest_beginning_token(tokens)
292
270
  stack = []
293
271
  (tokens.size - 1).downto(0) do |i|
294
- (line, column), event, text = tokens[i]
272
+ (line, ), event, text = tokens[i]
295
273
  case event
296
274
  when :on_kw
297
275
  _, prev_event, _ = tokens[i - 1]
@@ -305,7 +283,7 @@ module Textbringer
305
283
  next if t && !(t[1] == :on_op && t[2] == "=")
306
284
  end
307
285
  if stack.empty?
308
- return line, column, event, text
286
+ return i
309
287
  end
310
288
  if stack.last != "end"
311
289
  raise EditorError, "#{@buffer.name}:#{line}: Unmatched #{text}"
@@ -318,7 +296,7 @@ module Textbringer
318
296
  stack.push(text)
319
297
  when :on_lbrace, :on_lparen, :on_lbracket, :on_tlambeg
320
298
  if stack.empty?
321
- return line, column, event, text
299
+ return i
322
300
  end
323
301
  if stack.last != BLOCK_END[text]
324
302
  raise EditorError, "#{@buffer.name}:#{line}: Unmatched #{text}"
@@ -329,6 +307,34 @@ module Textbringer
329
307
  return nil
330
308
  end
331
309
 
310
+ def find_test_target_path(base, namespace, name)
311
+ patterns = []
312
+ if namespace
313
+ patterns.push("#{base}/{lib,app}/**/#{namespace}#{name}.rb")
314
+ end
315
+ patterns.push("#{base}/{lib,app}/**/#{name}.rb")
316
+ find_first_path(patterns) or raise EditorError, "Test target not found"
317
+ end
318
+
319
+ def find_test_path(base, namespace, name)
320
+ patterns = []
321
+ if namespace
322
+ patterns.push("#{base}/test/**/#{namespace}test_#{name}.rb")
323
+ patterns.push("#{base}/spec/**/#{namespace}#{name}_spec.rb")
324
+ end
325
+ patterns.push("#{base}/test/**/test_#{name}.rb")
326
+ patterns.push("#{base}/spec/**/#{name}_spec.rb")
327
+ find_first_path(patterns) or raise EditorError, "Test not found"
328
+ end
329
+
330
+ def find_first_path(patterns)
331
+ patterns.each do |pattern|
332
+ paths = Dir.glob(pattern)
333
+ return paths.first if !paths.empty?
334
+ end
335
+ nil
336
+ end
337
+
332
338
  class PartialLiteralAnalyzer < Ripper
333
339
  def self.in_literal?(src)
334
340
  new(src).in_literal?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Textbringer
4
- VERSION = "0.2.9"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textbringer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-22 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -260,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  version: '0'
261
261
  requirements: []
262
262
  rubyforge_project:
263
- rubygems_version: 3.0.0.beta1
263
+ rubygems_version: 2.7.6
264
264
  signing_key:
265
265
  specification_version: 4
266
266
  summary: An Emacs-like text editor