textbringer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/lib/textbringer/buffer.rb +41 -24
- data/lib/textbringer/commands/files.rb +23 -0
- data/lib/textbringer/keymap.rb +1 -0
- data/lib/textbringer/version.rb +1 -1
- data/lib/textbringer/window.rb +11 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 906c3f715935cd762c39a92b8d92a9a7021179b4
|
4
|
+
data.tar.gz: 5ba42d51b5af2086d2e9a839e07d4960f2f2f270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fd110a1970b6d0237c36365f8d1ff7eac130e881d5adcb7f0c0a4132bc5cdece78208397c87de0808c24c5538fea5ae492431b75b3220a132eb60b47736c42b
|
7
|
+
data.tar.gz: e80b7040d0bcd2c7af8f166545f31f9c5573488fd8e5ad2c0d3d1ab838d2afcc9ed7bb7af44567e1806439e23ec9664c0280cd6b87f449f5830641386a4300a4
|
data/CHANGES.md
CHANGED
data/lib/textbringer/buffer.rb
CHANGED
@@ -195,29 +195,11 @@ module Textbringer
|
|
195
195
|
file_encoding: CONFIG[:default_file_encoding],
|
196
196
|
file_mtime: nil, new_file: true, undo_limit: UNDO_LIMIT,
|
197
197
|
read_only: false)
|
198
|
-
|
199
|
-
when Encoding::UTF_8, Encoding::ASCII_8BIT
|
200
|
-
@contents = s.frozen? ? s.dup : s
|
201
|
-
else
|
202
|
-
@contents = s.encode(Encoding::UTF_8)
|
203
|
-
end
|
204
|
-
@contents.force_encoding(Encoding::ASCII_8BIT)
|
198
|
+
set_contents(s, file_encoding)
|
205
199
|
@name = name
|
206
200
|
@file_name = file_name
|
207
201
|
self.file_encoding = file_encoding
|
208
202
|
@file_mtime = file_mtime
|
209
|
-
case @contents
|
210
|
-
when /(?<!\r)\n/
|
211
|
-
@file_format = :unix
|
212
|
-
when /\r(?!\n)/
|
213
|
-
@file_format = :mac
|
214
|
-
@contents.gsub!(/\r/, "\n")
|
215
|
-
when /\r\n/
|
216
|
-
@file_format = :dos
|
217
|
-
@contents.gsub!(/\r/, "")
|
218
|
-
else
|
219
|
-
@file_format = CONFIG[:default_file_format]
|
220
|
-
end
|
221
203
|
@new_file = new_file
|
222
204
|
@undo_limit = undo_limit
|
223
205
|
@point = 0
|
@@ -346,21 +328,33 @@ module Textbringer
|
|
346
328
|
end
|
347
329
|
|
348
330
|
def self.open(file_name, name: File.basename(file_name))
|
349
|
-
|
331
|
+
buffer = Buffer.new(name: name,
|
332
|
+
file_name: file_name, new_file: false)
|
333
|
+
buffer.revert
|
334
|
+
buffer.read_only = !File.writable?(file_name)
|
335
|
+
buffer
|
336
|
+
end
|
337
|
+
|
338
|
+
def revert(enc = nil)
|
339
|
+
if @file_name.nil?
|
340
|
+
raise EditorError, "Buffer has no file name"
|
341
|
+
end
|
342
|
+
clear
|
343
|
+
s, mtime = File.open(@file_name,
|
350
344
|
external_encoding: Encoding::ASCII_8BIT,
|
351
345
|
binmode: true) { |f|
|
352
346
|
f.flock(File::LOCK_SH)
|
353
347
|
[f.read, f.mtime]
|
354
348
|
}
|
355
|
-
enc
|
349
|
+
enc ||= @@detect_encoding_proc.call(s) || Encoding::ASCII_8BIT
|
356
350
|
s.force_encoding(enc)
|
357
351
|
unless s.valid_encoding?
|
358
352
|
enc = Encoding::ASCII_8BIT
|
359
353
|
s.force_encoding(enc)
|
360
354
|
end
|
361
|
-
|
362
|
-
|
363
|
-
|
355
|
+
set_contents(s, enc)
|
356
|
+
@file_mtime = mtime
|
357
|
+
@modified = false
|
364
358
|
end
|
365
359
|
|
366
360
|
def save(file_name = @file_name)
|
@@ -1300,6 +1294,29 @@ module Textbringer
|
|
1300
1294
|
|
1301
1295
|
private
|
1302
1296
|
|
1297
|
+
def set_contents(s, enc)
|
1298
|
+
case s.encoding
|
1299
|
+
when Encoding::UTF_8, Encoding::ASCII_8BIT
|
1300
|
+
@contents = s.frozen? ? s.dup : s
|
1301
|
+
else
|
1302
|
+
@contents = s.encode(Encoding::UTF_8)
|
1303
|
+
end
|
1304
|
+
@contents.force_encoding(Encoding::ASCII_8BIT)
|
1305
|
+
self.file_encoding = enc
|
1306
|
+
case @contents
|
1307
|
+
when /(?<!\r)\n/
|
1308
|
+
@file_format = :unix
|
1309
|
+
when /\r(?!\n)/
|
1310
|
+
@file_format = :mac
|
1311
|
+
@contents.gsub!(/\r/, "\n")
|
1312
|
+
when /\r\n/
|
1313
|
+
@file_format = :dos
|
1314
|
+
@contents.gsub!(/\r/, "")
|
1315
|
+
else
|
1316
|
+
@file_format = CONFIG[:default_file_format]
|
1317
|
+
end
|
1318
|
+
end
|
1319
|
+
|
1303
1320
|
def adjust_gap(min_size = 0, pos = @point)
|
1304
1321
|
if @gap_start < pos
|
1305
1322
|
len = user_to_gap(pos) - @gap_end
|
@@ -48,6 +48,29 @@ module Textbringer
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
define_command(:revert_buffer, doc: <<~EOD) do
|
52
|
+
Revert the contents of the current buffer from the file on disk.
|
53
|
+
EOD
|
54
|
+
unless yes_or_no?("Revert buffer from file?")
|
55
|
+
message("Cancelled")
|
56
|
+
next
|
57
|
+
end
|
58
|
+
Buffer.current.revert
|
59
|
+
end
|
60
|
+
|
61
|
+
define_command(:revert_buffer_with_encoding, doc: <<~EOD) do
|
62
|
+
Revert the contents of the current buffer from the file on disk
|
63
|
+
using the specified encoding.
|
64
|
+
If the specified encoding is not valid, fall back to ASCII-8BIT.
|
65
|
+
EOD
|
66
|
+
|encoding = read_from_minibuffer("File encoding: ")|
|
67
|
+
unless yes_or_no?("Revert buffer from file?")
|
68
|
+
message("Cancelled")
|
69
|
+
next
|
70
|
+
end
|
71
|
+
Buffer.current.revert(encoding)
|
72
|
+
end
|
73
|
+
|
51
74
|
define_command(:save_buffer, doc: "Save the current buffer to a file.") do
|
52
75
|
if Buffer.current.file_name.nil?
|
53
76
|
Buffer.current.file_name = read_file_name("File to save in: ")
|
data/lib/textbringer/keymap.rb
CHANGED
@@ -158,6 +158,7 @@ module Textbringer
|
|
158
158
|
GLOBAL_MAP.define_key("\C-xk", :kill_buffer)
|
159
159
|
GLOBAL_MAP.define_key("\C-x\C-mf", :set_buffer_file_encoding)
|
160
160
|
GLOBAL_MAP.define_key("\C-x\C-mn", :set_buffer_file_format)
|
161
|
+
GLOBAL_MAP.define_key("\C-x\C-mr", :revert_buffer_with_encoding)
|
161
162
|
GLOBAL_MAP.define_key("\e.", :find_tag)
|
162
163
|
GLOBAL_MAP.define_key("\ex", :execute_command)
|
163
164
|
GLOBAL_MAP.define_key("\e:", :eval_expression)
|
data/lib/textbringer/version.rb
CHANGED
data/lib/textbringer/window.rb
CHANGED
@@ -261,6 +261,7 @@ module Textbringer
|
|
261
261
|
@bottom_of_window = nil
|
262
262
|
@point_mark = nil
|
263
263
|
@deleted = false
|
264
|
+
@raw_key_buffer = []
|
264
265
|
@key_buffer = []
|
265
266
|
end
|
266
267
|
|
@@ -349,14 +350,14 @@ module Textbringer
|
|
349
350
|
end
|
350
351
|
|
351
352
|
def wait_input(msecs)
|
352
|
-
|
353
|
-
return @key_buffer.first
|
353
|
+
if !@raw_key_buffer.empty? || !@key_buffer.empty?
|
354
|
+
return @raw_key_buffer.first || @key_buffer.first
|
354
355
|
end
|
355
356
|
@window.timeout = msecs
|
356
357
|
begin
|
357
358
|
c = @window.get_char
|
358
359
|
if c
|
359
|
-
|
360
|
+
@raw_key_buffer.push(c)
|
360
361
|
end
|
361
362
|
c
|
362
363
|
ensure
|
@@ -365,14 +366,14 @@ module Textbringer
|
|
365
366
|
end
|
366
367
|
|
367
368
|
def has_input?
|
368
|
-
|
369
|
+
if !@raw_key_buffer.empty? || !@key_buffer.empty?
|
369
370
|
return true
|
370
371
|
end
|
371
372
|
@window.nodelay = true
|
372
373
|
begin
|
373
374
|
c = @window.get_char
|
374
375
|
if c
|
375
|
-
|
376
|
+
@raw_key_buffer.push(c)
|
376
377
|
end
|
377
378
|
!c.nil?
|
378
379
|
ensure
|
@@ -782,7 +783,11 @@ module Textbringer
|
|
782
783
|
PDCurses.PDC_save_key_modifiers(1) if PDCurses.dll_loaded?
|
783
784
|
begin
|
784
785
|
need_retry = false
|
785
|
-
|
786
|
+
if @raw_key_buffer.empty?
|
787
|
+
key = @window.get_char
|
788
|
+
else
|
789
|
+
key = @raw_key_buffer.shift
|
790
|
+
end
|
786
791
|
if PDCurses.dll_loaded?
|
787
792
|
mods = PDCurses.PDC_get_key_modifiers
|
788
793
|
if key.is_a?(String) && key.ascii_only?
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shugo Maeda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -286,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
286
|
version: '0'
|
287
287
|
requirements: []
|
288
288
|
rubyforge_project:
|
289
|
-
rubygems_version: 2.6.
|
289
|
+
rubygems_version: 2.6.11
|
290
290
|
signing_key:
|
291
291
|
specification_version: 4
|
292
292
|
summary: An Emacs-like text editor
|