textbringer 0.2.5 → 0.2.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43ad091e53d7d19724cd9e0cbeddcd71faa3cef5
4
- data.tar.gz: 42455b6be377fee9ca997b77addbfa5fdf85dd9c
3
+ metadata.gz: 7a7999df616ed4ffd10a360bdf4f05981ca689e5
4
+ data.tar.gz: ec1adb45ac78222f521317d019a2c6f34d2bdbf3
5
5
  SHA512:
6
- metadata.gz: f54811a073bff5d7583a50dde84b90e91620b6b9e6401ce694746edbad846f6bc2ae6bfdb466306f2ce28ac8221cf5914b827a31ecef077a43d5f27ac0465af6
7
- data.tar.gz: 3241db0e8134b199e991a15a9affcad48894d823aad3becea9b48cfce05c99217604fbcbcb76f2d2f4d789146a08462cb94b06413d6bdd73f943ed284312fd68
6
+ metadata.gz: a42aebf208fc3570b68f068909665e185958c77d0f038cc60bc6d4e470b373245d56290712cc8e13065fce2c16eb02094b8f36bcbd5710ef7ee7423bc9019080
7
+ data.tar.gz: 974172125b75ae24a3156303988697d4cec95c9d1c1db61a3825cf66edbf522ffbcd774f9ef0d708edcd52e7a82ed68461a8d0b560ff2bc4bbbe441e208ee576
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.2.6
2
+
3
+ * Add the following new commands:
4
+ * fill_paragraph
5
+ * fill_region
6
+ * open_line
7
+ * Complete encoding names in set_buffer_file_encoding and
8
+ revert_buffer_with_encoding.
9
+
1
10
  ## 0.2.5
2
11
 
3
12
  * Add next_tick!.
data/README.md CHANGED
@@ -9,6 +9,10 @@
9
9
  Textbringer is a member of a demon race that takes on the form of an Emacs-like
10
10
  text editor.
11
11
 
12
+ ## Screenshot
13
+
14
+ ![Screenshot](screenshot.png)
15
+
12
16
  ## Demo
13
17
 
14
18
  * FizzBuzz: https://asciinema.org/a/103357
@@ -37,7 +41,11 @@ Install ncursesw before installing curses.gem, on which textbringer depends.
37
41
 
38
42
  $ textbringer
39
43
 
40
- You can quit the editor by C-x C-c.
44
+ You can quit the editor by `Ctrl-x Ctrl-c`.
45
+
46
+ Many commands and key bindings are similar to [Emacs](https://www.gnu.org/software/emacs/).
47
+
48
+ Type `F1 b` or `Alt+x describe_bindings RET` to see key bindings.
41
49
 
42
50
  ## Configuration
43
51
 
data/lib/textbringer.rb CHANGED
@@ -22,6 +22,7 @@ require_relative "textbringer/commands/ctags"
22
22
  require_relative "textbringer/commands/clipboard"
23
23
  require_relative "textbringer/commands/register"
24
24
  require_relative "textbringer/commands/keyboard_macro"
25
+ require_relative "textbringer/commands/fill"
25
26
  require_relative "textbringer/commands/help"
26
27
  require_relative "textbringer/mode"
27
28
  require_relative "textbringer/modes/fundamental_mode"
@@ -931,10 +931,11 @@ module Textbringer
931
931
  end
932
932
  end
933
933
 
934
- def replace(s)
934
+ def replace(str, start: point_min, end: point_max)
935
935
  composite_edit do
936
- delete_region(point_min, point_max)
937
- insert(s)
936
+ delete_region(start, binding.local_variable_get(:end))
937
+ goto_char(start)
938
+ insert(str)
938
939
  end
939
940
  end
940
941
 
@@ -119,6 +119,14 @@ module Textbringer
119
119
  Buffer.current.newline
120
120
  end
121
121
 
122
+ define_command(:open_line,
123
+ doc: "Insert a newline leaving point before it.") do
124
+ buffer = Buffer.current
125
+ buffer.save_excursion do
126
+ buffer.newline
127
+ end
128
+ end
129
+
122
130
  define_command(:delete_region,
123
131
  doc: "Delete the region without copying.") do
124
132
  Buffer.current.delete_region
@@ -63,7 +63,7 @@ module Textbringer
63
63
  using the specified encoding.
64
64
  If the specified encoding is not valid, fall back to ASCII-8BIT.
65
65
  EOD
66
- |encoding = read_from_minibuffer("File encoding: ")|
66
+ |encoding = read_encoding("File encoding: ")|
67
67
  unless yes_or_no?("Revert buffer from file?")
68
68
  message("Cancelled")
69
69
  next
@@ -104,8 +104,8 @@ module Textbringer
104
104
 
105
105
  define_command(:set_buffer_file_encoding,
106
106
  doc: "Set the file encoding of the current buffer.") do
107
- |enc = read_from_minibuffer("File encoding: ",
108
- default: Buffer.current.file_encoding.name)|
107
+ |enc = read_encoding("File encoding: ",
108
+ default: Buffer.current.file_encoding.name)|
109
109
  Buffer.current.file_encoding = enc
110
110
  end
111
111
 
@@ -121,7 +121,9 @@ module Textbringer
121
121
  end
122
122
 
123
123
  define_command(:chdir, doc: "Change the current working directory.") do
124
- |dir_name = read_file_name("Change directory: ")|
124
+ |dir_name = read_file_name("Change directory: ",
125
+ default: Buffer.current.file_name &&
126
+ File.dirname(Buffer.current.file_name))|
125
127
  Dir.chdir(dir_name)
126
128
  end
127
129
  end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module FillExtension
5
+ refine Buffer do
6
+ def fill_region(s = Buffer.current.point, e = Buffer.current.mark)
7
+ s, e = Buffer.region_boundaries(s, e)
8
+ save_excursion do
9
+ str = substring(s, e)
10
+ goto_char(s)
11
+ pos = point
12
+ beginning_of_line
13
+ column = Buffer.display_width(substring(point, pos))
14
+ replace(fill_string(str, column), start: s, end: e)
15
+ end
16
+ end
17
+
18
+ def fill_paragraph
19
+ beginning_of_line
20
+ while !beginning_of_buffer? &&
21
+ !looking_at?(/^[ \t]*$/)
22
+ backward_line
23
+ end
24
+ while looking_at?(/^[ \t]*$/)
25
+ forward_line
26
+ end
27
+ s = point
28
+ begin
29
+ forward_line
30
+ end while !end_of_buffer? && !looking_at?(/^[ \t]*$/)
31
+ if beginning_of_line?
32
+ backward_char
33
+ end
34
+ fill_region(s, point)
35
+ end
36
+
37
+ private
38
+
39
+ def fill_string(str, column)
40
+ input = StringIO.new(str)
41
+ output = String.new
42
+ fill_column = CONFIG[:fill_column]
43
+ prev_c = nil
44
+ while c = input.getc
45
+ if c == "\n"
46
+ if column < fill_column && !input.eof?
47
+ if /(?=[\u{0000}-\u{00FF}])[[:graph:]]/ =~ prev_c
48
+ column = insert_space_between_words(input, output, column)
49
+ end
50
+ next
51
+ end
52
+ column = insert_newline(output)
53
+ else
54
+ w = Buffer.display_width(c)
55
+ if column + w > fill_column || column >= fill_column
56
+ if /\w/ =~ prev_c && /\w/ =~ c
57
+ column = insert_newline_before_word(output, column)
58
+ else
59
+ column = insert_newline(output)
60
+ end
61
+ end
62
+ column = insert_char(output, column, c, w)
63
+ end
64
+ prev_c = c
65
+ end
66
+ output
67
+ end
68
+
69
+ def insert_space_between_words(input, output, column)
70
+ c = input.getc
71
+ input.ungetc(c)
72
+ if /(?=[\u{0000}-\u{00FF}])[[:graph:]]/ =~ c
73
+ output << " "
74
+ column + 1
75
+ else
76
+ column
77
+ end
78
+ end
79
+
80
+ def insert_newline_before_word(output, column)
81
+ if output.sub!(/(?:([^\w \t\n])|(\w)[ \t]+)(\w*)\z/, "\\1\\2\n")
82
+ output << $3
83
+ Buffer.display_width($3)
84
+ else
85
+ column
86
+ end
87
+ end
88
+
89
+ def insert_newline(output)
90
+ output.sub!(/[ \t]\z/, "")
91
+ output << "\n"
92
+ 0
93
+ end
94
+
95
+ def insert_char(output, column, c, w)
96
+ if column == 0 && /[ \t]/ =~ c
97
+ column
98
+ else
99
+ output << c
100
+ column + w
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ module Commands
107
+ using FillExtension
108
+
109
+ define_command(:fill_region,
110
+ doc: "Fill paragraph.") do
111
+ |s = Buffer.current.point, e = Buffer.current.mark|
112
+ Buffer.current.fill_region(s, e)
113
+ end
114
+
115
+ define_command(:fill_paragraph,
116
+ doc: "Fill paragraph.") do
117
+ Buffer.current.fill_paragraph
118
+ end
119
+ end
120
+ end
@@ -16,6 +16,7 @@ module Textbringer
16
16
  highlight_buffer_size_limit: 102400,
17
17
  shell_file_name: ENV["SHELL"],
18
18
  shell_command_switch: "-c",
19
- grep_command: "grep -nH -e"
19
+ grep_command: "grep -nH -e",
20
+ fill_column: 70
20
21
  }
21
22
  end
@@ -135,6 +135,7 @@ module Textbringer
135
135
  GLOBAL_MAP.define_key("\C-t", :transpose_chars)
136
136
  GLOBAL_MAP.define_key("\C-j", :newline)
137
137
  GLOBAL_MAP.define_key("\C-m", :newline)
138
+ GLOBAL_MAP.define_key("\C-o", :open_line)
138
139
  GLOBAL_MAP.define_key("\em", :back_to_indentation)
139
140
  GLOBAL_MAP.define_key("\e^", :delete_indentation)
140
141
  GLOBAL_MAP.define_key("\C-l", :recenter)
@@ -180,6 +181,7 @@ module Textbringer
180
181
  GLOBAL_MAP.define_key("\C-x)", :end_keyboard_macro)
181
182
  GLOBAL_MAP.define_key("\C-xe", :end_and_call_keyboard_macro)
182
183
  GLOBAL_MAP.define_key(:f4, :end_or_call_keyboard_macro)
184
+ GLOBAL_MAP.define_key("\eq", :fill_paragraph)
183
185
  GLOBAL_MAP.define_key([:f1, "b"], :describe_bindings)
184
186
  GLOBAL_MAP.define_key([:f1, "f"], :describe_command)
185
187
  GLOBAL_MAP.define_key([:f1, "k"], :describe_key)
@@ -12,7 +12,11 @@ module Textbringer
12
12
  files = Gem.find_latest_files("textbringer_plugin.rb", false) +
13
13
  Dir.glob(File.join(directory, "*/**/textbringer_plugin.rb"))
14
14
  files.each do |file|
15
- load(file)
15
+ begin
16
+ load(file)
17
+ rescue Exception => e
18
+ show_exception(e)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -194,7 +194,8 @@ module Textbringer
194
194
  end
195
195
  }
196
196
  }
197
- file = read_from_minibuffer(prompt, completion_proc: f, default: default)
197
+ file = read_from_minibuffer(prompt, completion_proc: f,
198
+ initial_value: default)
198
199
  File.expand_path(file)
199
200
  end
200
201
 
@@ -214,6 +215,13 @@ module Textbringer
214
215
  read_from_minibuffer(prompt, completion_proc: f)
215
216
  end
216
217
 
218
+ def read_encoding(prompt, **opts)
219
+ f = ->(s) {
220
+ complete_for_minibuffer(s.upcase, Encoding.list.map(&:name))
221
+ }
222
+ read_from_minibuffer(prompt, completion_proc: f, **opts)
223
+ end
224
+
217
225
  def yes_or_no?(prompt)
218
226
  loop {
219
227
  s = read_from_minibuffer(prompt + " (yes or no) ")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Textbringer
4
- VERSION = "0.2.5"
4
+ VERSION = "0.2.6"
5
5
  end
data/screenshot.png ADDED
Binary file
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.5
4
+ version: 0.2.6
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-07-08 00:00:00.000000000 Z
11
+ date: 2017-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -209,6 +209,7 @@ files:
209
209
  - lib/textbringer/commands/ctags.rb
210
210
  - lib/textbringer/commands/dabbrev.rb
211
211
  - lib/textbringer/commands/files.rb
212
+ - lib/textbringer/commands/fill.rb
212
213
  - lib/textbringer/commands/help.rb
213
214
  - lib/textbringer/commands/isearch.rb
214
215
  - lib/textbringer/commands/keyboard_macro.rb
@@ -236,6 +237,7 @@ files:
236
237
  - lib/textbringer/utils.rb
237
238
  - lib/textbringer/version.rb
238
239
  - lib/textbringer/window.rb
240
+ - screenshot.png
239
241
  - textbringer.gemspec
240
242
  homepage: https://github.com/shugo/textbringer
241
243
  licenses: