textbringer-minibuffer-extension 1
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 +7 -0
- data/.gitignore +11 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +12 -0
- data/lib/textbringer/minibuffer_extension/commands.rb +74 -0
- data/lib/textbringer/minibuffer_extension/completion_cycling.rb +111 -0
- data/lib/textbringer/minibuffer_extension/cycling_completion_list_mode.rb +31 -0
- data/lib/textbringer/minibuffer_extension/history.rb +24 -0
- data/lib/textbringer/minibuffer_extension/keymap.rb +10 -0
- data/lib/textbringer/minibuffer_extension/utils_extension.rb +117 -0
- data/lib/textbringer/minibuffer_extension/version.rb +7 -0
- data/lib/textbringer/minibuffer_extension.rb +9 -0
- data/lib/textbringer_plugin.rb +3 -0
- data/textbringer-minibuffer-extension.gemspec +33 -0
- metadata +112 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 80aa383081c6f047cb35a6399ce675bb3e17b0e5ba841a96c4573d18d49826a5
|
|
4
|
+
data.tar.gz: b45edea4eda4ea837935a964db6198273e0ffffaa78fd8c316f523fac4062395
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 447c6a9624e1665d182d06e3c93cfdfe1fa747938702937ae2f45d36f0a9f35cbbe1d8fec4a4b383b5f79015239852d4d5a1ca737eff752fb8b2372ee69ad1f7
|
|
7
|
+
data.tar.gz: 3ae39ad150f0bfb126e73904f55f8db713b4d82c94a30b70e2f33a318933fbefbe5a8ff0b1e3a7606f790ab82e89cb5049a5153df93490ed269442cb1deb3c07
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# textbringer-minibuffer-extension
|
|
2
|
+
|
|
3
|
+
Minibuffer extensions for [Textbringer](https://github.com/shugo/textbringer).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Minibuffer History
|
|
8
|
+
|
|
9
|
+
Navigate through minibuffer input history using:
|
|
10
|
+
|
|
11
|
+
- `M-p` / `Up` - Previous history element
|
|
12
|
+
- `M-n` / `Down` - Next history element
|
|
13
|
+
|
|
14
|
+
History is automatically saved for:
|
|
15
|
+
- File names (`:file`)
|
|
16
|
+
- Buffer names (`:buffer`)
|
|
17
|
+
- Command names (`:command`)
|
|
18
|
+
|
|
19
|
+
### Tab Completion Cycling
|
|
20
|
+
|
|
21
|
+
zsh-style tab completion cycling for minibuffer:
|
|
22
|
+
|
|
23
|
+
- **1st TAB** - Complete to the common prefix and show candidates in `*Completions*` buffer
|
|
24
|
+
- **2nd TAB** (when no further prefix progress) - Start cycling through candidates
|
|
25
|
+
- **Subsequent TABs** - Cycle to the next candidate (wraps around at the end)
|
|
26
|
+
- **Shift-TAB** - Cycle backward through candidates
|
|
27
|
+
- **Any other key** - Reset cycling state
|
|
28
|
+
|
|
29
|
+
The currently selected candidate is highlighted in the `*Completions*` buffer.
|
|
30
|
+
|
|
31
|
+
This replaces the default `complete_minibuffer` command on the TAB key.
|
|
32
|
+
|
|
33
|
+
### Context-Aware Arrow Keys
|
|
34
|
+
|
|
35
|
+
The Up/Down arrow keys intelligently switch behavior based on context:
|
|
36
|
+
|
|
37
|
+
- **During completion cycling** - Up/Down move backward/forward through candidates (same as Shift-TAB/TAB)
|
|
38
|
+
- **Otherwise** - Up/Down navigate through minibuffer history (same as M-p/M-n)
|
|
39
|
+
|
|
40
|
+
This allows seamless navigation: start cycling with TAB, then use arrow keys to fine-tune your selection.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
### Via git clone
|
|
45
|
+
|
|
46
|
+
Clone this repository to your Textbringer plugins directory:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/kurod1492/textbringer-minibuffer-extension.git ~/.textbringer/plugins/textbringer-minibuffer-extension
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Via rake install
|
|
53
|
+
|
|
54
|
+
After checking out the repo, run `bundle install` to install dependencies.
|
|
55
|
+
|
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
You can customize the history behavior in your `~/.textbringer.rb`:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
# Maximum number of history entries (default: 100)
|
|
64
|
+
CONFIG[:history_length] = 100
|
|
65
|
+
|
|
66
|
+
# Remove duplicate entries (default: true)
|
|
67
|
+
CONFIG[:history_delete_duplicates] = true
|
|
68
|
+
|
|
69
|
+
# Optional: Add C-p/C-n keybindings for history navigation
|
|
70
|
+
MINIBUFFER_LOCAL_MAP.define_key(?\C-p, :previous_history_element)
|
|
71
|
+
MINIBUFFER_LOCAL_MAP.define_key(?\C-n, :next_history_element)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << "test"
|
|
8
|
+
t.libs << "lib"
|
|
9
|
+
t.test_files = FileList["test/**/*_test.rb", "test/**/test_*.rb"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task default: :test
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textbringer
|
|
4
|
+
module Commands
|
|
5
|
+
define_command(:previous_history_element,
|
|
6
|
+
doc: "Get previous element from minibuffer history.") do
|
|
7
|
+
history = Buffer.minibuffer[:history]
|
|
8
|
+
if history.nil?
|
|
9
|
+
raise EditorError, "No history"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
list = history.is_a?(Symbol) ? MinibufferHistory.get(history) : history
|
|
13
|
+
if list.empty?
|
|
14
|
+
raise EditorError, "Beginning of history; no preceding item"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
index = Buffer.minibuffer[:history_index]
|
|
18
|
+
|
|
19
|
+
# Save current input on first navigation
|
|
20
|
+
if index < 0
|
|
21
|
+
Buffer.minibuffer[:history_input] = Buffer.minibuffer.to_s
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
new_index = index + 1
|
|
25
|
+
if new_index >= list.size
|
|
26
|
+
raise EditorError, "Beginning of history; no preceding item"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Buffer.minibuffer[:history_index] = new_index
|
|
30
|
+
Buffer.minibuffer.clear
|
|
31
|
+
Buffer.minibuffer.insert(list[new_index])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
define_command(:minibuffer_up,
|
|
35
|
+
doc: "Navigate up in minibuffer: cycle backward if cycling, else previous history.") do
|
|
36
|
+
unless cycle_candidates_directly(-1)
|
|
37
|
+
previous_history_element
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
define_command(:minibuffer_down,
|
|
42
|
+
doc: "Navigate down in minibuffer: cycle forward if cycling, else next history.") do
|
|
43
|
+
unless cycle_candidates_directly(1)
|
|
44
|
+
next_history_element
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
define_command(:next_history_element,
|
|
49
|
+
doc: "Get next element from minibuffer history.") do
|
|
50
|
+
history = Buffer.minibuffer[:history]
|
|
51
|
+
if history.nil?
|
|
52
|
+
raise EditorError, "No history"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
index = Buffer.minibuffer[:history_index]
|
|
56
|
+
if index < 0
|
|
57
|
+
raise EditorError, "End of history; no default available"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
new_index = index - 1
|
|
61
|
+
Buffer.minibuffer[:history_index] = new_index
|
|
62
|
+
Buffer.minibuffer.clear
|
|
63
|
+
|
|
64
|
+
if new_index < 0
|
|
65
|
+
# Restore original input
|
|
66
|
+
input = Buffer.minibuffer[:history_input]
|
|
67
|
+
Buffer.minibuffer.insert(input) if input
|
|
68
|
+
else
|
|
69
|
+
list = history.is_a?(Symbol) ? MinibufferHistory.get(history) : history
|
|
70
|
+
Buffer.minibuffer.insert(list[new_index])
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textbringer
|
|
4
|
+
module Commands
|
|
5
|
+
CYCLING_COMMANDS = [
|
|
6
|
+
:cycle_complete_minibuffer,
|
|
7
|
+
:cycle_complete_minibuffer_backward,
|
|
8
|
+
:minibuffer_up,
|
|
9
|
+
:minibuffer_down
|
|
10
|
+
].freeze
|
|
11
|
+
|
|
12
|
+
define_command(:cycle_complete_minibuffer,
|
|
13
|
+
doc: "Complete minibuffer input with cycling support.") do
|
|
14
|
+
cycle_complete_minibuffer_internal(1)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
define_command(:cycle_complete_minibuffer_backward,
|
|
18
|
+
doc: "Complete minibuffer input with backward cycling.") do
|
|
19
|
+
cycle_complete_minibuffer_internal(-1)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# 既存の candidates を使って cycling だけを行う(last_command チェックなし)
|
|
23
|
+
def cycle_candidates_directly(direction)
|
|
24
|
+
minibuffer = Buffer.minibuffer
|
|
25
|
+
candidates = minibuffer[:cycle_candidates]
|
|
26
|
+
return false unless candidates && candidates.size > 1
|
|
27
|
+
cycle_index = minibuffer[:cycle_index]
|
|
28
|
+
new_index = (cycle_index + direction) % candidates.size
|
|
29
|
+
minibuffer[:cycle_index] = new_index
|
|
30
|
+
complete_minibuffer_with_string(candidates[new_index])
|
|
31
|
+
update_completions_with_selection(candidates, new_index)
|
|
32
|
+
true
|
|
33
|
+
end
|
|
34
|
+
private :cycle_candidates_directly
|
|
35
|
+
|
|
36
|
+
def cycle_complete_minibuffer_internal(direction)
|
|
37
|
+
minibuffer = Buffer.minibuffer
|
|
38
|
+
completion_proc = minibuffer[:completion_proc]
|
|
39
|
+
return unless completion_proc
|
|
40
|
+
ignore_case = minibuffer[:completion_ignore_case]
|
|
41
|
+
current_text = minibuffer.to_s
|
|
42
|
+
|
|
43
|
+
candidates = minibuffer[:cycle_candidates]
|
|
44
|
+
if CYCLING_COMMANDS.include?(Controller.current.last_command) &&
|
|
45
|
+
candidates && candidates.size > 1
|
|
46
|
+
cycle_candidates_directly(direction)
|
|
47
|
+
else
|
|
48
|
+
xs = completion_proc.call(current_text)
|
|
49
|
+
update_completions(xs)
|
|
50
|
+
if xs.empty?
|
|
51
|
+
message("No match", sit_for: 1)
|
|
52
|
+
minibuffer[:cycle_candidates] = nil
|
|
53
|
+
return
|
|
54
|
+
end
|
|
55
|
+
if xs.size == 1
|
|
56
|
+
complete_minibuffer_with_string(xs[0])
|
|
57
|
+
minibuffer[:cycle_candidates] = nil
|
|
58
|
+
return
|
|
59
|
+
end
|
|
60
|
+
y, *ys = xs
|
|
61
|
+
s = y.size.downto(1).lazy.map { |i| y[0, i] }.find { |i|
|
|
62
|
+
ci = ignore_case ? i.downcase : i
|
|
63
|
+
ys.all? { |j|
|
|
64
|
+
cj = ignore_case ? j.downcase : j
|
|
65
|
+
cj.start_with?(ci)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if s
|
|
69
|
+
complete_minibuffer_with_string(s)
|
|
70
|
+
end
|
|
71
|
+
completed_text = minibuffer.to_s
|
|
72
|
+
if completed_text == current_text
|
|
73
|
+
minibuffer[:cycle_candidates] = xs
|
|
74
|
+
start_index = direction == 1 ? 0 : xs.size - 1
|
|
75
|
+
minibuffer[:cycle_index] = start_index
|
|
76
|
+
complete_minibuffer_with_string(xs[start_index])
|
|
77
|
+
update_completions_with_selection(xs, start_index)
|
|
78
|
+
else
|
|
79
|
+
minibuffer[:cycle_candidates] = xs
|
|
80
|
+
minibuffer[:cycle_index] = -1
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
private :cycle_complete_minibuffer_internal
|
|
85
|
+
|
|
86
|
+
def update_completions_with_selection(xs, selected_index)
|
|
87
|
+
if COMPLETION[:completions_window].nil?
|
|
88
|
+
Window.list.last.split
|
|
89
|
+
COMPLETION[:completions_window] = Window.list.last
|
|
90
|
+
end
|
|
91
|
+
completions = Buffer.find_or_new("*Completions*", undo_limit: 0)
|
|
92
|
+
if !completions.mode.is_a?(CyclingCompletionListMode)
|
|
93
|
+
completions.apply_mode(CyclingCompletionListMode)
|
|
94
|
+
end
|
|
95
|
+
CyclingCompletionListMode.set_selected_pattern(xs[selected_index])
|
|
96
|
+
completions.read_only = false
|
|
97
|
+
begin
|
|
98
|
+
completions.clear
|
|
99
|
+
xs.each do |x|
|
|
100
|
+
completions.insert("#{x}\n")
|
|
101
|
+
end
|
|
102
|
+
completions.beginning_of_buffer
|
|
103
|
+
selected_index.times { completions.next_line }
|
|
104
|
+
COMPLETION[:completions_window].buffer = completions
|
|
105
|
+
ensure
|
|
106
|
+
completions.read_only = true
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
private :update_completions_with_selection
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textbringer
|
|
4
|
+
Face.define :completion_selected, reverse: true
|
|
5
|
+
|
|
6
|
+
class CyclingCompletionListMode < CompletionListMode
|
|
7
|
+
@syntax_table = {}
|
|
8
|
+
define_syntax :completion_selected, /\z\A/
|
|
9
|
+
define_syntax :link, /^.+$/
|
|
10
|
+
|
|
11
|
+
def self.set_selected_pattern(candidate)
|
|
12
|
+
@syntax_table[:completion_selected] = /^#{Regexp.escape(candidate)}$/
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def choose_completion
|
|
16
|
+
unless Window.echo_area.active?
|
|
17
|
+
raise EditorError, "Minibuffer is not active"
|
|
18
|
+
end
|
|
19
|
+
s = @buffer.save_excursion {
|
|
20
|
+
@buffer.beginning_of_line
|
|
21
|
+
@buffer.looking_at?(/^(.*)/)
|
|
22
|
+
@buffer.match_string(1)
|
|
23
|
+
}
|
|
24
|
+
if s && s.size > 0
|
|
25
|
+
Window.current = Window.echo_area
|
|
26
|
+
complete_minibuffer_with_string(s)
|
|
27
|
+
delete_completions_window
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textbringer
|
|
4
|
+
MINIBUFFER_HISTORY = Hash.new { |h, k| h[k] = [] }
|
|
5
|
+
|
|
6
|
+
CONFIG[:history_length] = 100
|
|
7
|
+
CONFIG[:history_delete_duplicates] = true
|
|
8
|
+
|
|
9
|
+
module MinibufferHistory
|
|
10
|
+
class << self
|
|
11
|
+
def get(name)
|
|
12
|
+
MINIBUFFER_HISTORY[name]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add(name, value)
|
|
16
|
+
return if value.nil? || value.empty?
|
|
17
|
+
list = MINIBUFFER_HISTORY[name]
|
|
18
|
+
list.delete(value) if CONFIG[:history_delete_duplicates]
|
|
19
|
+
list.unshift(value)
|
|
20
|
+
list.pop while list.size > CONFIG[:history_length]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textbringer
|
|
4
|
+
MINIBUFFER_LOCAL_MAP.define_key("\M-p", :previous_history_element)
|
|
5
|
+
MINIBUFFER_LOCAL_MAP.define_key("\M-n", :next_history_element)
|
|
6
|
+
MINIBUFFER_LOCAL_MAP.define_key(:up, :minibuffer_up)
|
|
7
|
+
MINIBUFFER_LOCAL_MAP.define_key(:down, :minibuffer_down)
|
|
8
|
+
MINIBUFFER_LOCAL_MAP.define_key(?\t, :cycle_complete_minibuffer)
|
|
9
|
+
MINIBUFFER_LOCAL_MAP.define_key(:btab, :cycle_complete_minibuffer_backward)
|
|
10
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textbringer
|
|
4
|
+
module Utils
|
|
5
|
+
alias_method :read_from_minibuffer_without_history, :read_from_minibuffer
|
|
6
|
+
|
|
7
|
+
def read_from_minibuffer(prompt, completion_proc: nil, default: nil,
|
|
8
|
+
initial_value: nil, completion_ignore_case: false,
|
|
9
|
+
keymap: MINIBUFFER_LOCAL_MAP,
|
|
10
|
+
history: nil)
|
|
11
|
+
if Window.echo_area.active?
|
|
12
|
+
raise EditorError,
|
|
13
|
+
"Command attempted to use minibuffer while in minibuffer"
|
|
14
|
+
end
|
|
15
|
+
old_buffer = Buffer.current
|
|
16
|
+
old_minibuffer_selected = Window.minibuffer_selected
|
|
17
|
+
Window.minibuffer_selected = Window.current
|
|
18
|
+
old_completion_proc = Buffer.minibuffer[:completion_proc]
|
|
19
|
+
old_completion_ignore_case = Buffer.minibuffer[:completion_ignore_case]
|
|
20
|
+
old_history = Buffer.minibuffer[:history]
|
|
21
|
+
old_history_index = Buffer.minibuffer[:history_index]
|
|
22
|
+
old_history_input = Buffer.minibuffer[:history_input]
|
|
23
|
+
old_current_prefix_arg = Controller.current.current_prefix_arg
|
|
24
|
+
old_minibuffer_map = Buffer.minibuffer.keymap
|
|
25
|
+
Buffer.minibuffer.keymap = keymap
|
|
26
|
+
Buffer.minibuffer[:completion_proc] = completion_proc
|
|
27
|
+
Buffer.minibuffer[:completion_ignore_case] = completion_ignore_case
|
|
28
|
+
Buffer.minibuffer[:history] = history
|
|
29
|
+
Buffer.minibuffer[:history_index] = -1
|
|
30
|
+
Buffer.minibuffer[:history_input] = nil
|
|
31
|
+
Buffer.minibuffer[:cycle_candidates] = nil
|
|
32
|
+
Buffer.minibuffer[:cycle_index] = nil
|
|
33
|
+
Window.echo_area.active = true
|
|
34
|
+
begin
|
|
35
|
+
Window.current = Window.echo_area
|
|
36
|
+
Buffer.minibuffer.clear
|
|
37
|
+
Buffer.minibuffer.insert(initial_value) if initial_value
|
|
38
|
+
if default
|
|
39
|
+
prompt = prompt.sub(/:/, " (default #{default}):")
|
|
40
|
+
end
|
|
41
|
+
Window.echo_area.prompt = prompt
|
|
42
|
+
Window.echo_area.redisplay
|
|
43
|
+
Window.update
|
|
44
|
+
recursive_edit
|
|
45
|
+
s = Buffer.minibuffer.to_s
|
|
46
|
+
result = if default && s.empty?
|
|
47
|
+
default
|
|
48
|
+
else
|
|
49
|
+
s
|
|
50
|
+
end
|
|
51
|
+
# Add to history if using symbol-based history
|
|
52
|
+
if history.is_a?(Symbol) && result && !result.empty?
|
|
53
|
+
MinibufferHistory.add(history, result)
|
|
54
|
+
end
|
|
55
|
+
result
|
|
56
|
+
ensure
|
|
57
|
+
Window.echo_area.clear
|
|
58
|
+
Window.echo_area.redisplay
|
|
59
|
+
Window.update
|
|
60
|
+
Window.echo_area.active = false
|
|
61
|
+
Window.current = Window.minibuffer_selected
|
|
62
|
+
Window.current.buffer = Buffer.current = old_buffer
|
|
63
|
+
Window.minibuffer_selected = old_minibuffer_selected
|
|
64
|
+
Buffer.minibuffer[:completion_ignore_case] = old_completion_ignore_case
|
|
65
|
+
Buffer.minibuffer[:completion_proc] = old_completion_proc
|
|
66
|
+
Buffer.minibuffer[:history] = old_history
|
|
67
|
+
Buffer.minibuffer[:history_index] = old_history_index
|
|
68
|
+
Buffer.minibuffer[:history_input] = old_history_input
|
|
69
|
+
Buffer.minibuffer[:cycle_candidates] = nil
|
|
70
|
+
Buffer.minibuffer[:cycle_index] = nil
|
|
71
|
+
Buffer.minibuffer.keymap = old_minibuffer_map
|
|
72
|
+
Buffer.minibuffer.disable_input_method
|
|
73
|
+
Controller.current.current_prefix_arg = old_current_prefix_arg
|
|
74
|
+
delete_completions_window
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
alias_method :read_file_name_without_history, :read_file_name
|
|
79
|
+
|
|
80
|
+
def read_file_name(prompt, default: nil, history: :file)
|
|
81
|
+
f = ->(s) {
|
|
82
|
+
s = File.expand_path(s) if s.start_with?("~")
|
|
83
|
+
Dir.glob(s + "*").map { |file|
|
|
84
|
+
if File.directory?(file)
|
|
85
|
+
file + "/"
|
|
86
|
+
else
|
|
87
|
+
file
|
|
88
|
+
end
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
initial_value = default&.dup || Dir.pwd + "/"
|
|
92
|
+
ignore_case = CONFIG[:read_file_name_completion_ignore_case]
|
|
93
|
+
file = read_from_minibuffer(prompt, completion_proc: f,
|
|
94
|
+
initial_value: initial_value,
|
|
95
|
+
completion_ignore_case: ignore_case,
|
|
96
|
+
history: history)
|
|
97
|
+
File.expand_path(file)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
alias_method :read_buffer_without_history, :read_buffer
|
|
101
|
+
|
|
102
|
+
def read_buffer(prompt, default: Buffer.other.name, history: :buffer)
|
|
103
|
+
f = ->(s) { complete_for_minibuffer(s, Buffer.names) }
|
|
104
|
+
read_from_minibuffer(prompt, completion_proc: f, default: default,
|
|
105
|
+
history: history)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
alias_method :read_command_name_without_history, :read_command_name
|
|
109
|
+
|
|
110
|
+
def read_command_name(prompt, history: :command)
|
|
111
|
+
f = ->(s) {
|
|
112
|
+
complete_for_minibuffer(s.tr("-", "_"), Commands.list.map(&:to_s))
|
|
113
|
+
}
|
|
114
|
+
read_from_minibuffer(prompt, completion_proc: f, history: history)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "minibuffer_extension/version"
|
|
4
|
+
require_relative "minibuffer_extension/history"
|
|
5
|
+
require_relative "minibuffer_extension/commands"
|
|
6
|
+
require_relative "minibuffer_extension/cycling_completion_list_mode"
|
|
7
|
+
require_relative "minibuffer_extension/completion_cycling"
|
|
8
|
+
require_relative "minibuffer_extension/utils_extension"
|
|
9
|
+
require_relative "minibuffer_extension/keymap"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "textbringer/minibuffer_extension/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "textbringer-minibuffer-extension"
|
|
9
|
+
spec.version = Textbringer::MinibufferExtension::VERSION
|
|
10
|
+
spec.authors = ["Akihiro Kurotani"]
|
|
11
|
+
spec.email = ["kurod1492@gmail.com"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "Minibuffer extensions for Textbringer."
|
|
14
|
+
spec.description = "Provides minibuffer history navigation and other enhancements for Textbringer."
|
|
15
|
+
spec.homepage = "https://github.com/kurod1492/textbringer-minibuffer-extension"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
spec.metadata = { "rubygems_mfa_required" => "true" }
|
|
18
|
+
|
|
19
|
+
spec.required_ruby_version = ">= 3.2"
|
|
20
|
+
|
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
|
23
|
+
end
|
|
24
|
+
spec.bindir = "exe"
|
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_runtime_dependency "textbringer", ">= 1.4"
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler"
|
|
31
|
+
spec.add_development_dependency "rake", ">= 12.0"
|
|
32
|
+
spec.add_development_dependency "test-unit"
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: textbringer-minibuffer-extension
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Akihiro Kurotani
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: textbringer
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.4'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.4'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: bundler
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '12.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '12.0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: test-unit
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
description: Provides minibuffer history navigation and other enhancements for Textbringer.
|
|
69
|
+
email:
|
|
70
|
+
- kurod1492@gmail.com
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- ".gitignore"
|
|
76
|
+
- Gemfile
|
|
77
|
+
- LICENSE.txt
|
|
78
|
+
- README.md
|
|
79
|
+
- Rakefile
|
|
80
|
+
- lib/textbringer/minibuffer_extension.rb
|
|
81
|
+
- lib/textbringer/minibuffer_extension/commands.rb
|
|
82
|
+
- lib/textbringer/minibuffer_extension/completion_cycling.rb
|
|
83
|
+
- lib/textbringer/minibuffer_extension/cycling_completion_list_mode.rb
|
|
84
|
+
- lib/textbringer/minibuffer_extension/history.rb
|
|
85
|
+
- lib/textbringer/minibuffer_extension/keymap.rb
|
|
86
|
+
- lib/textbringer/minibuffer_extension/utils_extension.rb
|
|
87
|
+
- lib/textbringer/minibuffer_extension/version.rb
|
|
88
|
+
- lib/textbringer_plugin.rb
|
|
89
|
+
- textbringer-minibuffer-extension.gemspec
|
|
90
|
+
homepage: https://github.com/kurod1492/textbringer-minibuffer-extension
|
|
91
|
+
licenses:
|
|
92
|
+
- MIT
|
|
93
|
+
metadata:
|
|
94
|
+
rubygems_mfa_required: 'true'
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '3.2'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubygems_version: 4.0.7
|
|
110
|
+
specification_version: 4
|
|
111
|
+
summary: Minibuffer extensions for Textbringer.
|
|
112
|
+
test_files: []
|