nvim 1.6.1 → 1.7.0

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
  SHA256:
3
- metadata.gz: d91e5ad07b2fd0ea6dd1da251df0e55dad1312b3ac4fa585cae59658dbccf666
4
- data.tar.gz: bde8ff51d7a22f70aca3c58f83051b32357f0d56603bdbd7ce209ce6acf94de9
3
+ metadata.gz: ec0d28da100b26fcaca45acb51d863eb7683978b06dab4345f265d8c75d5b28a
4
+ data.tar.gz: c086178c5dcfd31520dfc13142a2827ae5b36edd5340f3037baf1246c6e3af03
5
5
  SHA512:
6
- metadata.gz: c5d55983ed98e326fe1a5a6c15e764ac0a3aff858dadf3538c6edcee5339d7fb117b33984d80334d2fb18d7f8fbd505d89ca854aec09bbbf6513c07b5f9c48ee
7
- data.tar.gz: c7dc22c69ddcb550b1d1a412963788b33f77337f5520ea87bc4bf2edabed162bcd59402e605eac6a46109c1953994024f88211c2d21af12efb9722e3eab36422
6
+ metadata.gz: a1d1de3dd0b50f63ba7f62335e6d6e0d1f061c9771e59848ca1d231049f4e668212a3f2fdc4b7b26ec4be0d78041b3142b0d8d4ba14bbd4ab06d8325f7c841f7
7
+ data.tar.gz: 17d86d71201706daeb1fca9691bdfea2ac4b064bdeafc2deeef0f394559acc405072f04699cb01363984d14d5238f794d14218be2c6be15240df0502d10ddacc
data/INFO.yaml CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
 
5
5
  nvim:
6
- version: 1.6.1
6
+ version: 1.7.0
7
7
  license: BSD-2-Clause+
8
8
  authors:
9
9
  - Bertram Scharpf
data/README.md CHANGED
@@ -224,7 +224,7 @@ Further, the variables `$range` and `$lines` will be set.
224
224
  2 bar
225
225
  3 baz
226
226
  ~
227
- :%ruby puts $range.inspect, $lines.inspect
227
+ :%ruby puts $range, $lines
228
228
  ```
229
229
 
230
230
  The legacy variables `$curbuf` and `$curwin` are supported.
@@ -417,15 +417,20 @@ rubyfile <neovim/tools/copy>
417
417
  '<,'>ruby tmuxbuf $lines
418
418
  ```
419
419
 
420
- Make a hex dump.
420
+ Maybe you like to install the
421
+ [Nxxd](https://github.com/BertramScharpf/ruby-nxxd) gem.
421
422
 
422
423
  ```vim
423
- ruby <<EOT
424
- require "neovim/foreign/nxxd"
425
- bn = $curbuf.get_name
426
- $vim.command :enew!
427
- File.open bn do |b| Nxxd::Dump.new.run b do |l| $vim.put [l], "l", false, true end end
428
- EOT
424
+ rubyfile <nxxd>
425
+ ruby r = (0...0x80).to_a.map { |c| c.chr }.join
426
+ ruby puts Nxxd::Dump.new.run r
427
+ ```
428
+
429
+ Or even:
430
+
431
+ ```vim
432
+ rubyfile <nxxd>
433
+ HexDump /etc/localtime
429
434
  ```
430
435
 
431
436
 
@@ -433,4 +438,5 @@ EOT
433
438
 
434
439
  * (C) 2024,2025 Bertram Scharpf <software@bertram-scharpf.de>
435
440
  * License: [BSD-2-Clause+](./LICENSE)
441
+ * Repository: [ruby-nvim](https://github.com/BertramScharpf/ruby-nvim)
436
442
 
data/Rakefile CHANGED
@@ -51,7 +51,7 @@ end
51
51
 
52
52
 
53
53
  task :diffdeps do
54
- %w(mplight nxxd).each { |gem|
54
+ %w(mplight).each { |gem|
55
55
  c = `gem contents #{gem}`
56
56
  unless $?.success? then
57
57
  puts "Gem #{gem} not installed. Cannot compare."
data/lib/neovim/client.rb CHANGED
@@ -114,5 +114,64 @@ module Neovim
114
114
 
115
115
  end
116
116
 
117
+ class Lines
118
+
119
+ include Enumerable
120
+
121
+ def initialize client, range
122
+ case client
123
+ when Buffer then @client, @buffer = client.client, client.index
124
+ else @client, @buffer = client, 0
125
+ end
126
+ @i, @last = range.begin, range.end
127
+ end
128
+
129
+ def to_s
130
+ (@client.buf_get_lines @buffer, @i-1, @last, true).join $/
131
+ end
132
+
133
+ def method_missing sym, *args, **kwargs, &block
134
+ to_a.send sym, *args, **kwargs, &block
135
+ end
136
+
137
+ def each
138
+ while @i <= @last do
139
+ @inc = 1
140
+ l, = @client.buf_get_lines @buffer, @i-1, @i, true
141
+ yield l
142
+ @i += @inc
143
+ end
144
+ ensure
145
+ @i = nil
146
+ end
147
+ alias each_line each
148
+
149
+ def each_with_no
150
+ each do |l|
151
+ yield l, @i
152
+ end
153
+ end
154
+
155
+ def map!
156
+ each do |l|
157
+ h = l.hash
158
+ m = yield l, @i
159
+ r =
160
+ case m
161
+ when String then m.lines unless m.hash == h
162
+ when Enumerable then m.map { |l| l.to_s }
163
+ when nil, false then []
164
+ end
165
+ if r then
166
+ r.each { |l| l.chomp! }
167
+ @client.buf_set_lines @buffer, @i-1, @i, true, r
168
+ @inc = r.length
169
+ @last += @inc-1
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+
117
176
  end
118
177
 
data/lib/neovim/info.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "neovim/meta.rb"
2
2
  Neovim::INFO = Neovim::Meta.new "nvim",
3
- version: "1.6.1",
3
+ version: "1.7.0",
4
4
  license: "BSD-2-Clause+",
5
5
  authors: ["Bertram Scharpf"],
6
6
  email: "software@bertram-scharpf.de",
data/lib/neovim/remote.rb CHANGED
@@ -191,7 +191,7 @@ module Neovim
191
191
  if @responses.key? message.request_id then
192
192
  @responses[ message.request_id] = message
193
193
  else
194
- log :warning, "Dropped response", message.request_id
194
+ log :warning, "Dropped response", rid: message.request_id
195
195
  end
196
196
  when Message::Request, Message::Notification then
197
197
  h = find_handler message.method_name
@@ -100,18 +100,13 @@ module Neovim
100
100
 
101
101
  def set_globals client, range
102
102
  set_global_client client do
103
- lines = get_lines client, range
104
- $range, $lines = range, lines
105
- yield lines
103
+ $range, $lines = range, (Lines.new client, range)
104
+ yield $lines
106
105
  end
107
106
  ensure
108
107
  $range, $lines = nil, nil
109
108
  end
110
109
 
111
- def get_lines client, range
112
- client.buf_get_lines 0, range.begin-1, range.end, true
113
- end
114
-
115
110
  def plugin_provider &block
116
111
  run_dsl DslProvider, &block
117
112
  end
@@ -123,11 +118,13 @@ module Neovim
123
118
  dsl.setup do |client|
124
119
  r = client.get_var "ruby_require" rescue nil
125
120
  case r
126
- when Array then r = r.notempty?
127
- when nil then nil
128
- else r = [r]
121
+ when String then r = r.split
122
+ when Array then
123
+ when Hash then r = r.keys
124
+ when nil then nil
125
+ else r = [r.to_s]
129
126
  end
130
- if r then
127
+ if r.notempty? then
131
128
  WriteOut.redirect client do # Protect the RPC interface against erroneous output.
132
129
  r.each do |l|
133
130
  require l
@@ -164,11 +161,10 @@ module Neovim
164
161
  code.rstrip!
165
162
  if code =~ /\A\|?(-)?\z/ then # | is a workaround because Neovim doesn't allow empty code (the ultimate Quine).
166
163
  no_out = $1
167
- set_global_client client do
164
+ set_globals client, fst..lst do |lines|
168
165
  client.command "#{lst}"
169
- code = (get_lines client, fst..lst).join $/
170
166
  WriteBuf.redirect client do
171
- r = script_binding.eval code, "ruby_run"
167
+ r = script_binding.eval lines.to_s, "ruby_run"
172
168
  unless no_out or r.nil? then
173
169
  script_binding.local_variable_set :_, r
174
170
  puts "#=> #{r.inspect}"
@@ -219,20 +215,10 @@ module Neovim
219
215
  # This is called by the +:rubydo+ command.
220
216
  dsl.rpc :ruby_do_range do |client,fst,lst,code|
221
217
  set_globals client, fst..lst do |lines|
222
- i = fst
223
- lines.each do |l|
224
- h = l.hash
218
+ lines.map! do |l,i|
225
219
  (script_binding.eval 'proc do |l,i| $_, $. = l, i end').call l, i
226
220
  script_binding.eval code, "ruby_do_range"
227
- m = script_binding.eval '$_'
228
- if m.hash != h then
229
- m = m.lines
230
- m.each { |x| x.chomp! }
231
- client.buf_set_lines 0, i-1, i, true, m
232
- i += m.length
233
- else
234
- i += 1
235
- end
221
+ script_binding.eval '$_'
236
222
  end
237
223
  end
238
224
  nil
@@ -63,9 +63,9 @@ module Kernel
63
63
 
64
64
  def cmd_write cmd, data
65
65
  case data
66
- when Array then data = data.join $/
67
- when String then nil
68
- else data = data.to_s
66
+ when Enumerable then data = data.join $/
67
+ when String then nil
68
+ else data = data.to_s
69
69
  end
70
70
  IO.popen cmd, "w" do |t| t.write data end
71
71
  end
data/nvim.gemspec CHANGED
@@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
25
25
  if false then
26
26
  spec.add_dependency "supplement", "~> 2.18"
27
27
  spec.add_dependency "mplight", "~> 1.0"
28
- spec.add_dependency "nxxd", "~> 1.0"
29
28
  end
30
29
 
31
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nvim
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-02 00:00:00.000000000 Z
10
+ date: 2025-02-05 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  email: software@bertram-scharpf.de
13
13
  executables:
@@ -46,7 +46,6 @@ files:
46
46
  - lib/neovim/connection.rb
47
47
  - lib/neovim/foreign/mplight.rb
48
48
  - lib/neovim/foreign/mplight/bufferio.rb
49
- - lib/neovim/foreign/nxxd.rb
50
49
  - lib/neovim/foreign/supplement.rb
51
50
  - lib/neovim/foreign/supplement/socket.rb
52
51
  - lib/neovim/handler.rb
@@ -80,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
79
  - !ruby/object:Gem::Version
81
80
  version: '0'
82
81
  requirements: []
83
- rubygems_version: 3.6.2
82
+ rubygems_version: 3.6.3
84
83
  specification_version: 4
85
84
  summary: Yet another Ruby client for Neovim
86
85
  test_files: []
@@ -1,216 +0,0 @@
1
- #
2
- # neovim/foreign/nxxd.rb -- Hex Dump Tool
3
- #
4
-
5
- # The purpose of this is simply to reduce dependencies.
6
-
7
- begin
8
- require "nxxd"
9
- rescue LoadError
10
-
11
- # ----------------------------------------------------------------
12
- #
13
- # nxxd.rb -- Hex Dump Tool
14
- #
15
-
16
-
17
- module Nxxd
18
-
19
- module ReadChunks
20
-
21
- private
22
-
23
- def read_chunks input
24
- case input
25
- when String then
26
- i = 0
27
- while i < input.bytesize do
28
- b = input.byteslice i, @line_size
29
- yield b
30
- i += @line_size
31
- end
32
- else
33
- loop do
34
- b = input.read @line_size
35
- break unless b
36
- yield b
37
- break if b.length < @line_size
38
- end
39
- end
40
- end
41
-
42
- end
43
-
44
- class Dump
45
-
46
- include ReadChunks
47
-
48
- LINE_SIZE = 16
49
- ADDR_FMT = "%%0%dx:"
50
-
51
- def initialize full: nil, upper: false, line_size: nil, addr_len: nil, input: nil
52
- @full = full
53
- @input = input
54
- @line_size = line_size||LINE_SIZE
55
- @addr_fmt = ADDR_FMT % (addr_len||8)
56
- @nib_fmt = "%02x"
57
- if upper then
58
- @addr_fmt.upcase!
59
- @nib_fmt.upcase!
60
- end
61
- end
62
-
63
- def run input
64
- addr = 0
65
- prev, repeat = nil, false
66
- yield "# #@input" if @input
67
- read_chunks input do |b|
68
- if b == prev and not @full then
69
- unless repeat then
70
- yield "*"
71
- repeat = true
72
- end
73
- else
74
- r = @addr_fmt % addr
75
- r << " "
76
- h = b.unpack "C*"
77
- sp = false
78
- @line_size.times {
79
- x = h.shift
80
- r << (x ? @nib_fmt % x : " ")
81
- r << " " if sp
82
- sp = !sp
83
- }
84
- r << " " << (b.gsub /[^ -~]/, ".")
85
- yield r
86
- prev, repeat = b, false
87
- end
88
- addr += b.size
89
- end
90
- yield @addr_fmt % addr
91
- nil
92
- end
93
-
94
-
95
- class <<self
96
-
97
- def reverse input, output = nil
98
- output ||= ""
99
- o = String === output ? (WriteChunksString.new output) : output
100
- o.set_encoding Encoding::ASCII_8BIT
101
- r, repeat = nil, false
102
- input.each_line { |l|
103
- l.chomp!
104
- case l
105
- when /^\s*(?:#|$)/ then nil
106
- when /^\*/ then repeat = true
107
- when /^(?:(\h+):)?\s*((?:\h\h ?)*)/ then
108
- addr, nibs = $~.captures
109
- if addr then
110
- addr = $1.to_i 0x10
111
- if repeat then
112
- loop do
113
- s = addr - o.tell
114
- break if s <= 0
115
- o.write s >= r.length ? r : r[ 0, s]
116
- end
117
- repeat = false
118
- else
119
- end
120
- o.seek addr
121
- end
122
- r = (nibs.scan /\h\h/).map { |x| x.to_i 0x10 }.pack "C*"
123
- o.write r
124
- else
125
- raise "Uninterpretable hex dump: #{l.chomp}"
126
- end
127
- }
128
- output
129
- end
130
-
131
- end
132
-
133
- end
134
-
135
- class DumpNums
136
-
137
- include ReadChunks
138
-
139
- LINE_SIZE = 12
140
-
141
- def initialize upper: false, line_size: nil, capitals: nil, input: nil
142
- @line_size = line_size||LINE_SIZE
143
- @nib_fmt = "%#04x"
144
- @nib_fmt.upcase! if upper
145
- if input then
146
- @varname = input.dup
147
- @varname.insert 0, "__" if @varname =~ /\A\d/
148
- @varname.gsub! /[^a-zA-Z0-9]/, "_"
149
- @varname.upcase! if capitals
150
- end
151
- end
152
-
153
- def run input, &block
154
- if @varname then
155
- yield "unsigned char #@varname[] = {"
156
- len = run_plain input, &block
157
- yield "};"
158
- yield "unsigned int #@varname\_len = %d;" % len
159
- else
160
- run_plain input, &block
161
- end
162
- nil
163
- end
164
-
165
- private
166
-
167
- def run_plain input
168
- prev, len = nil, 0
169
- read_chunks input do |b|
170
- if prev then
171
- prev << ","
172
- yield prev
173
- end
174
- prev = " " + ((b.unpack "C*").map { |x| @nib_fmt % x }.join ", ")
175
- len += b.bytesize
176
- end
177
- yield prev if prev
178
- len
179
- end
180
-
181
- end
182
-
183
- class WriteChunksString
184
- def initialize str
185
- @str = str
186
- end
187
- def set_encoding enc
188
- @str.force_encoding enc
189
- end
190
- def tell ; @pos || @str.length ; end
191
- def seek pos
192
- s = pos - @str.length
193
- if s >= 0 then
194
- s.times { @str << "\0".b }
195
- else
196
- @pos = pos
197
- end
198
- end
199
- def write b
200
- if @pos then
201
- l = b.length
202
- @str[ @pos, l] = b
203
- @pos += l
204
- @pos = nil if @pos >= @str.length
205
- else
206
- @str << b
207
- end
208
- end
209
- end
210
-
211
- end
212
-
213
- # ----------------------------------------------------------------
214
-
215
- end
216
-