textbringer 0.2.8 → 0.2.9

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: 7c42284ec820a6074794ed19f174f9ac393d5caa316f8408db5c5e43d5e87041
4
- data.tar.gz: 95d805f94fbce11d2858c44a2fd275af3b8cdbfe6aed396a7807ac8543282d31
3
+ metadata.gz: 7239f854b8c82327c4ee8f1afc538f57d14dc083d51580ac79cf3b8b899ab251
4
+ data.tar.gz: be654b2f51c7e445826caadca3324feb3c13fce6c350fcb044768170311baaec
5
5
  SHA512:
6
- metadata.gz: a849309d4b2d77f350619fced9d26555598777fcde6f42d26439576c0933316a796027c9bc82fa427c4f698cbe581fb3b3428db8cd09ea2b7ecdaf0b6f690e47
7
- data.tar.gz: 186933b3607392f5b28d32ab22df7324f960821fb8abb651403db281973e92bd1715d8d0e7841d0a1e1bc57ed50659f28095684e9c7a199e44bc118190aa4c23
6
+ metadata.gz: 33d3d5398d6c35b76666cefc846e02930106520bfb8ac76f1ec32b1e9abf76f5a0cdde7fa425e3b46bdfe334daf6d6678a9cbf787564588068029bfb325a2288
7
+ data.tar.gz: c475825d5801f90bb1d5f960a811a195a8a7e7d5573e5bbe7c67ade0ab47d69d5055ac3831c23b4691b41bdcd98a489ae9d51027ef7feb14ec9ef4906b409b5e
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.2.9
2
+
3
+ * Add the following new commands:
4
+ * list_buffers
5
+ * jit_pause
6
+ * jit_resume
7
+
1
8
  ## 0.2.8
2
9
 
3
10
  * Highlight control characters.
@@ -31,6 +31,7 @@ require_relative "textbringer/modes/ruby_mode"
31
31
  require_relative "textbringer/modes/c_mode"
32
32
  require_relative "textbringer/modes/backtrace_mode"
33
33
  require_relative "textbringer/modes/completion_list_mode"
34
+ require_relative "textbringer/modes/buffer_list_mode"
34
35
  require_relative "textbringer/modes/help_mode"
35
36
  require_relative "textbringer/plugin"
36
37
  require_relative "textbringer/controller"
@@ -58,13 +58,15 @@ module Textbringer
58
58
  end
59
59
  }
60
60
 
61
- @@detect_encoding_proc = DEFAULT_DETECT_ENCODING
61
+ if !defined?(@@detect_encoding_proc)
62
+ @@detect_encoding_proc = DEFAULT_DETECT_ENCODING
62
63
 
63
- @@table = {}
64
- @@list = []
65
- @@current = nil
66
- @@minibuffer = nil
67
- @@global_mark_ring = nil
64
+ @@table = {}
65
+ @@list = []
66
+ @@current = nil
67
+ @@minibuffer = nil
68
+ @@global_mark_ring = nil
69
+ end
68
70
 
69
71
  def self.auto_detect_encodings
70
72
  @@auto_detect_encodings
@@ -1104,14 +1106,15 @@ module Textbringer
1104
1106
  @match_offsets = []
1105
1107
  method = forward ? :index : :rindex
1106
1108
  adjust_gap(0, point_max)
1109
+ s = @contents[0...@gap_start]
1107
1110
  if @binary
1108
1111
  offset = pos
1109
1112
  else
1110
- offset = @contents[0...pos].force_encoding(Encoding::UTF_8).size
1111
- @contents.force_encoding(Encoding::UTF_8)
1113
+ offset = s.byteslice(0, pos).force_encoding(Encoding::UTF_8).size
1114
+ s.force_encoding(Encoding::UTF_8)
1112
1115
  end
1113
1116
  begin
1114
- i = @contents.send(method, re, offset)
1117
+ i = s.send(method, re, offset)
1115
1118
  if i
1116
1119
  m = Regexp.last_match
1117
1120
  if m.nil?
@@ -1143,8 +1146,6 @@ module Textbringer
1143
1146
  else
1144
1147
  nil
1145
1148
  end
1146
- ensure
1147
- @contents.force_encoding(Encoding::ASCII_8BIT)
1148
1149
  end
1149
1150
  end
1150
1151
 
@@ -107,7 +107,7 @@ module Textbringer
107
107
  using FillExtension
108
108
 
109
109
  define_command(:fill_region,
110
- doc: "Fill paragraph.") do
110
+ doc: "Fill region.") do
111
111
  |s = Buffer.current.point, e = Buffer.current.mark|
112
112
  Buffer.current.fill_region(s, e)
113
113
  end
@@ -330,5 +330,13 @@ module Textbringer
330
330
  initial_value: CONFIG[:grep_command] + " ")|
331
331
  shell_execute(cmd, buffer_name: "*grep*", mode: BacktraceMode)
332
332
  end
333
+
334
+ define_command(:jit_pause) do
335
+ RubyVM::MJIT.pause
336
+ end
337
+
338
+ define_command(:jit_resume) do
339
+ RubyVM::MJIT.resume
340
+ end
333
341
  end
334
342
  end
@@ -82,6 +82,20 @@ module Textbringer
82
82
  end
83
83
  end
84
84
 
85
+ define_command(:list_buffers, doc: <<~EOD) do
86
+ List the existing buffers.
87
+ EOD
88
+ buffer = Buffer.find_or_new("*Buffer List*",
89
+ undo_limit: 0, read_only: true)
90
+ buffer.apply_mode(BufferListMode)
91
+ buffer.read_only_edit do
92
+ buffer.clear
93
+ buffer.insert(Buffer.list.map(&:name).join("\n"))
94
+ buffer.beginning_of_buffer
95
+ end
96
+ switch_to_buffer(buffer)
97
+ end
98
+
85
99
  define_command(:bury_buffer, doc: <<~EOD) do
86
100
  Put buffer at the end of the buffer list.
87
101
  EOD
@@ -158,6 +158,7 @@ module Textbringer
158
158
  GLOBAL_MAP.define_key("\C-z", :suspend_textbringer)
159
159
  GLOBAL_MAP.define_key("\C-x\C-f", :find_file)
160
160
  GLOBAL_MAP.define_key("\C-xb", :switch_to_buffer)
161
+ GLOBAL_MAP.define_key("\C-x\C-b", :list_buffers)
161
162
  GLOBAL_MAP.define_key("\C-x\C-s", :save_buffer)
162
163
  GLOBAL_MAP.define_key("\C-x\C-w", :write_file)
163
164
  GLOBAL_MAP.define_key("\C-xk", :kill_buffer)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ class BufferListMode < Mode
5
+ BUFFER_LIST_MODE_MAP = Keymap.new
6
+ BUFFER_LIST_MODE_MAP.define_key("\C-m", :this_window_command)
7
+
8
+ def initialize(buffer)
9
+ super(buffer)
10
+ buffer.keymap = BUFFER_LIST_MODE_MAP
11
+ end
12
+
13
+ define_local_command(:this_window,
14
+ doc: "Change the current account.") do
15
+ name = @buffer.save_excursion {
16
+ @buffer.beginning_of_line
17
+ @buffer.looking_at?(/.*/)
18
+ @buffer.match_string(0)
19
+ }
20
+ switch_to_buffer(name)
21
+ end
22
+ end
23
+ end
@@ -151,7 +151,7 @@ module Textbringer
151
151
  prefix = File.exist?("Gemfile") ? "bundle exec " : ""
152
152
  prefix + "rake"
153
153
  elsif @buffer.file_name
154
- "ruby " + @buffer.file_name
154
+ ruby_install_name + " " + @buffer.file_name
155
155
  else
156
156
  nil
157
157
  end
@@ -200,6 +200,27 @@ module Textbringer
200
200
 
201
201
  private
202
202
 
203
+ INDENT_BEG_RE = /^([ \t]*)((class|module|def|if|unless|case|while|until|for|begin|end)\b|\})/
204
+
205
+ def space_width(s)
206
+ s.gsub(/\t/, " " * @buffer[:tab_width]).size
207
+ end
208
+
209
+ def beginning_of_indentation
210
+ loop do
211
+ @buffer.re_search_backward(INDENT_BEG_RE)
212
+ space = @buffer.match_string(1)
213
+ s = @buffer.substring(@buffer.point_min, @buffer.point)
214
+ if PartialLiteralAnalyzer.in_literal?(s)
215
+ next
216
+ end
217
+ return space_width(space)
218
+ end
219
+ rescue SearchError
220
+ @buffer.beginning_of_buffer
221
+ 0
222
+ end
223
+
203
224
  def calculate_indentation
204
225
  if @buffer.current_line == 1
205
226
  return 0
@@ -207,8 +228,10 @@ module Textbringer
207
228
  @buffer.save_excursion do
208
229
  @buffer.beginning_of_line
209
230
  bol_pos = @buffer.point
210
- tokens = Ripper.lex(@buffer.substring(@buffer.point_min,
211
- @buffer.point))
231
+ base_indentation = beginning_of_indentation
232
+ start_pos = @buffer.point
233
+ start_line = @buffer.current_line
234
+ tokens = Ripper.lex(@buffer.substring(start_pos, bol_pos))
212
235
  _, event, text = tokens.last
213
236
  if event == :on_tstring_beg ||
214
237
  event == :on_heredoc_beg ||
@@ -222,7 +245,7 @@ module Textbringer
222
245
  return column + 1
223
246
  end
224
247
  if line
225
- @buffer.goto_line(line)
248
+ @buffer.goto_line(start_line - 1 + line)
226
249
  while !@buffer.beginning_of_buffer?
227
250
  if @buffer.save_excursion {
228
251
  @buffer.backward_char
@@ -235,18 +258,17 @@ module Textbringer
235
258
  end
236
259
  end
237
260
  @buffer.looking_at?(/[ \t]*/)
238
- base_indentation = @buffer.match_string(0).
239
- gsub(/\t/, " " * @buffer[:tab_width]).size
240
- else
241
- base_indentation = 0
261
+ base_indentation = space_width(@buffer.match_string(0))
242
262
  end
243
263
  @buffer.goto_char(bol_pos)
244
- if line.nil? ||
245
- @buffer.looking_at?(/[ \t]*([}\])]|(end|else|elsif|when|rescue|ensure)\b)/)
264
+ if line.nil?
246
265
  indentation = base_indentation
247
266
  else
248
267
  indentation = base_indentation + @buffer[:indent_level]
249
268
  end
269
+ if @buffer.looking_at?(/[ \t]*([}\])]|(end|else|elsif|when|rescue|ensure)\b)/)
270
+ indentation -= @buffer[:indent_level]
271
+ end
250
272
  _, last_event, last_text = tokens.reverse_each.find { |_, e, _|
251
273
  e != :on_sp && e != :on_nl && e != :on_ignored_nl
252
274
  }
@@ -306,5 +328,32 @@ module Textbringer
306
328
  end
307
329
  return nil
308
330
  end
331
+
332
+ class PartialLiteralAnalyzer < Ripper
333
+ def self.in_literal?(src)
334
+ new(src).in_literal?
335
+ end
336
+
337
+ def in_literal?
338
+ @literal_level = 0
339
+ parse
340
+ @literal_level > 0
341
+ end
342
+
343
+ private
344
+
345
+ %w(embdoc heredoc tstring regexp
346
+ symbols qsymbols words qwords).each do |name|
347
+ define_method("on_#{name}_beg") do |token|
348
+ @literal_level += 1
349
+ end
350
+ end
351
+
352
+ %w(embdoc heredoc tstring regexp).each do |name|
353
+ define_method("on_#{name}_end") do |token|
354
+ @literal_level -= 1
355
+ end
356
+ end
357
+ end
309
358
  end
310
359
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Textbringer
4
- VERSION = "0.2.8"
4
+ VERSION = "0.2.9"
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.8
4
+ version: 0.2.9
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-05-03 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -226,6 +226,7 @@ files:
226
226
  - lib/textbringer/keymap.rb
227
227
  - lib/textbringer/mode.rb
228
228
  - lib/textbringer/modes/backtrace_mode.rb
229
+ - lib/textbringer/modes/buffer_list_mode.rb
229
230
  - lib/textbringer/modes/c_mode.rb
230
231
  - lib/textbringer/modes/completion_list_mode.rb
231
232
  - lib/textbringer/modes/fundamental_mode.rb
@@ -259,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
260
  version: '0'
260
261
  requirements: []
261
262
  rubyforge_project:
262
- rubygems_version: 2.7.6
263
+ rubygems_version: 3.0.0.beta1
263
264
  signing_key:
264
265
  specification_version: 4
265
266
  summary: An Emacs-like text editor