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 +4 -4
- data/CHANGES.md +7 -0
- data/lib/textbringer.rb +1 -0
- data/lib/textbringer/buffer.rb +12 -11
- data/lib/textbringer/commands/fill.rb +1 -1
- data/lib/textbringer/commands/misc.rb +8 -0
- data/lib/textbringer/commands/windows.rb +14 -0
- data/lib/textbringer/keymap.rb +1 -0
- data/lib/textbringer/modes/buffer_list_mode.rb +23 -0
- data/lib/textbringer/modes/ruby_mode.rb +59 -10
- data/lib/textbringer/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7239f854b8c82327c4ee8f1afc538f57d14dc083d51580ac79cf3b8b899ab251
|
4
|
+
data.tar.gz: be654b2f51c7e445826caadca3324feb3c13fce6c350fcb044768170311baaec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33d3d5398d6c35b76666cefc846e02930106520bfb8ac76f1ec32b1e9abf76f5a0cdde7fa425e3b46bdfe334daf6d6678a9cbf787564588068029bfb325a2288
|
7
|
+
data.tar.gz: c475825d5801f90bb1d5f960a811a195a8a7e7d5573e5bbe7c67ade0ab47d69d5055ac3831c23b4691b41bdcd98a489ae9d51027ef7feb14ec9ef4906b409b5e
|
data/CHANGES.md
CHANGED
data/lib/textbringer.rb
CHANGED
@@ -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"
|
data/lib/textbringer/buffer.rb
CHANGED
@@ -58,13 +58,15 @@ module Textbringer
|
|
58
58
|
end
|
59
59
|
}
|
60
60
|
|
61
|
-
@@detect_encoding_proc
|
61
|
+
if !defined?(@@detect_encoding_proc)
|
62
|
+
@@detect_encoding_proc = DEFAULT_DETECT_ENCODING
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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 =
|
1111
|
-
|
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 =
|
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
|
|
@@ -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
|
data/lib/textbringer/keymap.rb
CHANGED
@@ -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
|
-
"
|
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
|
-
|
211
|
-
|
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
|
data/lib/textbringer/version.rb
CHANGED
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.
|
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-
|
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:
|
263
|
+
rubygems_version: 3.0.0.beta1
|
263
264
|
signing_key:
|
264
265
|
specification_version: 4
|
265
266
|
summary: An Emacs-like text editor
|