summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2021-10-31 11:30:25 +0100
committerJames Ross-Gowan <rossy@jrg.systems>2021-11-01 23:42:16 +1100
commit87c9eefb2928252497f6141e847b74ad1158bc61 (patch)
tree0d26b4c48d1c37da86ec6a0ee497977f319ebafa /player
parentc82ffb667077cc9e03f82461e5f753c39d0c633d (diff)
downloadmpv-87c9eefb2928252497f6141e847b74ad1158bc61.tar.bz2
mpv-87c9eefb2928252497f6141e847b74ad1158bc61.tar.xz
console.lua: define remaining emacs keybindings
Diffstat (limited to 'player')
-rw-r--r--player/lua/console.lua36
1 files changed, 33 insertions, 3 deletions
diff --git a/player/lua/console.lua b/player/lua/console.lua
index 2020952840..36c0c95426 100644
--- a/player/lua/console.lua
+++ b/player/lua/console.lua
@@ -260,7 +260,7 @@ function prev_utf8(str, pos)
return pos
end
--- Insert a character at the current cursor position (any_unicode, Shift+Enter)
+-- Insert a character at the current cursor position (any_unicode)
function handle_char_input(c)
if insert_mode then
line = line:sub(1, cursor - 1) .. c .. line:sub(next_utf8(line, cursor))
@@ -313,10 +313,13 @@ function clear()
update()
end
--- Close the REPL if the current line is empty, otherwise do nothing (Ctrl+D)
+-- Close the REPL if the current line is empty, otherwise delete the next
+-- character (Ctrl+D)
function maybe_exit()
if line == '' then
set_active(false)
+ else
+ handle_del()
end
end
@@ -571,7 +574,7 @@ function go_end()
update()
end
--- Delete from the cursor to the end of the word (Ctrl+W)
+-- Delete from the cursor to the beginning of the word (Ctrl+Backspace)
function del_word()
local before_cur = line:sub(1, cursor - 1)
local after_cur = line:sub(cursor)
@@ -582,6 +585,18 @@ function del_word()
update()
end
+-- Delete from the cursor to the end of the word (Ctrl+Del)
+function del_next_word()
+ if cursor > line:len() then return end
+
+ local before_cur = line:sub(1, cursor - 1)
+ local after_cur = line:sub(cursor)
+
+ after_cur = after_cur:gsub('^%s*[^%s]+', '', 1)
+ line = before_cur .. after_cur
+ update()
+end
+
-- Delete from the cursor to the end of the line (Ctrl+K)
function del_to_eol()
line = line:sub(1, cursor - 1)
@@ -675,25 +690,37 @@ function get_bindings()
{ 'enter', handle_enter },
{ 'kp_enter', handle_enter },
{ 'shift+enter', function() handle_char_input('\n') end },
+ { 'ctrl+j', handle_enter },
+ { 'ctrl+m', handle_enter },
{ 'bs', handle_backspace },
{ 'shift+bs', handle_backspace },
+ { 'ctrl+h', handle_backspace },
{ 'del', handle_del },
{ 'shift+del', handle_del },
{ 'ins', handle_ins },
{ 'shift+ins', function() paste(false) end },
{ 'mbtn_mid', function() paste(false) end },
{ 'left', function() prev_char() end },
+ { 'ctrl+b', function() prev_char() end },
{ 'right', function() next_char() end },
+ { 'ctrl+f', function() next_char() end },
{ 'up', function() move_history(-1) end },
+ { 'ctrl+p', function() move_history(-1) end },
{ 'wheel_up', function() move_history(-1) end },
{ 'down', function() move_history(1) end },
+ { 'ctrl+n', function() move_history(1) end },
{ 'wheel_down', function() move_history(1) end },
{ 'wheel_left', function() end },
{ 'wheel_right', function() end },
{ 'ctrl+left', prev_word },
+ { 'alt+b', prev_word },
{ 'ctrl+right', next_word },
+ { 'alt+f', next_word },
{ 'tab', complete },
+ { 'ctrl+i', complete },
+ { 'ctrl+a', go_home },
{ 'home', go_home },
+ { 'ctrl+e', go_end },
{ 'end', go_end },
{ 'pgup', handle_pgup },
{ 'pgdwn', handle_pgdown },
@@ -704,7 +731,10 @@ function get_bindings()
{ 'ctrl+u', del_to_start },
{ 'ctrl+v', function() paste(true) end },
{ 'meta+v', function() paste(true) end },
+ { 'ctrl+bs', del_word },
{ 'ctrl+w', del_word },
+ { 'ctrl+del', del_next_word },
+ { 'alt+d', del_next_word },
{ 'kp_dec', function() handle_char_input('.') end },
}