Skip to content

Commit 5eaa4c7

Browse files
tompngmatzbot
authored andcommitted
[ruby/reline] Remove unused things from reline/unicode.rb
(ruby/reline#759) * Remove garbage(nil) from Reline::Unicode.split_by_width result * Remove unused width from Reline::Unicode vi_ ed_ em_ method return value * Remove unused height from Unicode.split_by_width return value * Rename split_by_width to split_line_by_width and add legacy split_by_width for IRB ruby/reline@f32446ebc4
1 parent bce1bd1 commit 5eaa4c7

File tree

3 files changed

+171
-95
lines changed

3 files changed

+171
-95
lines changed

lib/reline/line_editor.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ def multiline_off
300300
end
301301
end
302302

303-
private def split_by_width(str, max_width, offset: 0)
304-
Reline::Unicode.split_by_width(str, max_width, encoding, offset: offset)
303+
private def split_line_by_width(str, max_width, offset: 0)
304+
Reline::Unicode.split_line_by_width(str, max_width, encoding, offset: offset)
305305
end
306306

307307
def current_byte_pointer_cursor
@@ -391,8 +391,8 @@ def wrapped_prompt_and_input_lines
391391
if (cached = cached_wraps[[prompt, line]])
392392
next cached
393393
end
394-
*wrapped_prompts, code_line_prompt = split_by_width(prompt, width).first.compact
395-
wrapped_lines = split_by_width(line, width, offset: calculate_width(code_line_prompt, true)).first.compact
394+
*wrapped_prompts, code_line_prompt = split_line_by_width(prompt, width)
395+
wrapped_lines = split_line_by_width(line, width, offset: calculate_width(code_line_prompt, true))
396396
wrapped_prompts.map { |p| [p, ''] } + [[code_line_prompt, wrapped_lines.first]] + wrapped_lines.drop(1).map { |c| ['', c] }
397397
end
398398
end
@@ -440,7 +440,7 @@ def render_line_differential(old_items, new_items)
440440
def wrapped_cursor_position
441441
prompt_width = calculate_width(prompt_list[@line_index], true)
442442
line_before_cursor = whole_lines[@line_index].byteslice(0, @byte_pointer)
443-
wrapped_line_before_cursor = split_by_width(' ' * prompt_width + line_before_cursor, screen_width).first.compact
443+
wrapped_line_before_cursor = split_line_by_width(' ' * prompt_width + line_before_cursor, screen_width)
444444
wrapped_cursor_y = wrapped_prompt_and_input_lines[0...@line_index].sum(&:size) + wrapped_line_before_cursor.size - 1
445445
wrapped_cursor_x = calculate_width(wrapped_line_before_cursor.last)
446446
[wrapped_cursor_x, wrapped_cursor_y]
@@ -465,7 +465,7 @@ def render_finished
465465
render_differential([], 0, 0)
466466
lines = @buffer_of_lines.size.times.map do |i|
467467
line = Reline::Unicode.strip_non_printing_start_end(prompt_list[i]) + modified_lines[i]
468-
wrapped_lines, = split_by_width(line, screen_width)
468+
wrapped_lines = split_line_by_width(line, screen_width)
469469
wrapped_lines.last.empty? ? "#{line} " : line
470470
end
471471
@output.puts lines.map { |l| "#{l}\r\n" }.join
@@ -1582,7 +1582,7 @@ def finish
15821582
alias_method :backward_char, :ed_prev_char
15831583

15841584
private def vi_first_print(key)
1585-
@byte_pointer, = Reline::Unicode.vi_first_print(current_line)
1585+
@byte_pointer = Reline::Unicode.vi_first_print(current_line)
15861586
end
15871587

15881588
private def ed_move_to_beg(key)
@@ -1961,23 +1961,23 @@ def finish
19611961

19621962
private def em_next_word(key)
19631963
if current_line.bytesize > @byte_pointer
1964-
byte_size, _ = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
1964+
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
19651965
@byte_pointer += byte_size
19661966
end
19671967
end
19681968
alias_method :forward_word, :em_next_word
19691969

19701970
private def ed_prev_word(key)
19711971
if @byte_pointer > 0
1972-
byte_size, _ = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
1972+
byte_size = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
19731973
@byte_pointer -= byte_size
19741974
end
19751975
end
19761976
alias_method :backward_word, :ed_prev_word
19771977

19781978
private def em_delete_next_word(key)
19791979
if current_line.bytesize > @byte_pointer
1980-
byte_size, _ = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
1980+
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
19811981
line, word = byteslice!(current_line, @byte_pointer, byte_size)
19821982
set_current_line(line)
19831983
@kill_ring.append(word)
@@ -1987,7 +1987,7 @@ def finish
19871987

19881988
private def ed_delete_prev_word(key)
19891989
if @byte_pointer > 0
1990-
byte_size, _ = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
1990+
byte_size = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
19911991
line, word = byteslice!(current_line, @byte_pointer - byte_size, byte_size)
19921992
set_current_line(line, @byte_pointer - byte_size)
19931993
@kill_ring.append(word, true)
@@ -2027,7 +2027,7 @@ def finish
20272027

20282028
private def em_capitol_case(key)
20292029
if current_line.bytesize > @byte_pointer
2030-
byte_size, _, new_str = Reline::Unicode.em_forward_word_with_capitalization(current_line, @byte_pointer)
2030+
byte_size, new_str = Reline::Unicode.em_forward_word_with_capitalization(current_line, @byte_pointer)
20312031
before = current_line.byteslice(0, @byte_pointer)
20322032
after = current_line.byteslice((@byte_pointer + byte_size)..-1)
20332033
set_current_line(before + new_str + after, @byte_pointer + new_str.bytesize)
@@ -2037,7 +2037,7 @@ def finish
20372037

20382038
private def em_lower_case(key)
20392039
if current_line.bytesize > @byte_pointer
2040-
byte_size, = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
2040+
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
20412041
part = current_line.byteslice(@byte_pointer, byte_size).grapheme_clusters.map { |mbchar|
20422042
mbchar =~ /[A-Z]/ ? mbchar.downcase : mbchar
20432043
}.join
@@ -2050,7 +2050,7 @@ def finish
20502050

20512051
private def em_upper_case(key)
20522052
if current_line.bytesize > @byte_pointer
2053-
byte_size, = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
2053+
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
20542054
part = current_line.byteslice(@byte_pointer, byte_size).grapheme_clusters.map { |mbchar|
20552055
mbchar =~ /[a-z]/ ? mbchar.upcase : mbchar
20562056
}.join
@@ -2063,7 +2063,7 @@ def finish
20632063

20642064
private def em_kill_region(key)
20652065
if @byte_pointer > 0
2066-
byte_size, _ = Reline::Unicode.em_big_backward_word(current_line, @byte_pointer)
2066+
byte_size = Reline::Unicode.em_big_backward_word(current_line, @byte_pointer)
20672067
line, deleted = byteslice!(current_line, @byte_pointer - byte_size, byte_size)
20682068
set_current_line(line, @byte_pointer - byte_size)
20692069
@kill_ring.append(deleted, true)
@@ -2094,7 +2094,7 @@ def finish
20942094

20952095
private def vi_next_word(key, arg: 1)
20962096
if current_line.bytesize > @byte_pointer
2097-
byte_size, _ = Reline::Unicode.vi_forward_word(current_line, @byte_pointer, @drop_terminate_spaces)
2097+
byte_size = Reline::Unicode.vi_forward_word(current_line, @byte_pointer, @drop_terminate_spaces)
20982098
@byte_pointer += byte_size
20992099
end
21002100
arg -= 1
@@ -2103,7 +2103,7 @@ def finish
21032103

21042104
private def vi_prev_word(key, arg: 1)
21052105
if @byte_pointer > 0
2106-
byte_size, _ = Reline::Unicode.vi_backward_word(current_line, @byte_pointer)
2106+
byte_size = Reline::Unicode.vi_backward_word(current_line, @byte_pointer)
21072107
@byte_pointer -= byte_size
21082108
end
21092109
arg -= 1
@@ -2112,7 +2112,7 @@ def finish
21122112

21132113
private def vi_end_word(key, arg: 1, inclusive: false)
21142114
if current_line.bytesize > @byte_pointer
2115-
byte_size, _ = Reline::Unicode.vi_forward_end_word(current_line, @byte_pointer)
2115+
byte_size = Reline::Unicode.vi_forward_end_word(current_line, @byte_pointer)
21162116
@byte_pointer += byte_size
21172117
end
21182118
arg -= 1
@@ -2127,7 +2127,7 @@ def finish
21272127

21282128
private def vi_next_big_word(key, arg: 1)
21292129
if current_line.bytesize > @byte_pointer
2130-
byte_size, _ = Reline::Unicode.vi_big_forward_word(current_line, @byte_pointer)
2130+
byte_size = Reline::Unicode.vi_big_forward_word(current_line, @byte_pointer)
21312131
@byte_pointer += byte_size
21322132
end
21332133
arg -= 1
@@ -2136,7 +2136,7 @@ def finish
21362136

21372137
private def vi_prev_big_word(key, arg: 1)
21382138
if @byte_pointer > 0
2139-
byte_size, _ = Reline::Unicode.vi_big_backward_word(current_line, @byte_pointer)
2139+
byte_size = Reline::Unicode.vi_big_backward_word(current_line, @byte_pointer)
21402140
@byte_pointer -= byte_size
21412141
end
21422142
arg -= 1
@@ -2145,7 +2145,7 @@ def finish
21452145

21462146
private def vi_end_big_word(key, arg: 1, inclusive: false)
21472147
if current_line.bytesize > @byte_pointer
2148-
byte_size, _ = Reline::Unicode.vi_big_forward_end_word(current_line, @byte_pointer)
2148+
byte_size = Reline::Unicode.vi_big_forward_end_word(current_line, @byte_pointer)
21492149
@byte_pointer += byte_size
21502150
end
21512151
arg -= 1

0 commit comments

Comments
 (0)