Skip to content

Commit

Permalink
+ registers! + fix macros +started on better vim's delete-as-cut
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenpt committed Aug 2, 2021
1 parent adc6ac6 commit e0c67e6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 23 deletions.
37 changes: 37 additions & 0 deletions com.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local style = require "core.style"
local translate = require "core.doc.translate"

local misc = require "plugins.lite-xl-vibe.misc"

Expand Down Expand Up @@ -75,16 +76,52 @@ command.add(nil, {
["vibe:open-scratch-buffer"] = function()
core.root_view:open_doc(core.open_doc(misc.scratch_filepath()))
end,
["vibe:paste"] = function()
core.log('vibe:paste')
local text
if core.vibe.target_register
and core.vibe.registers[core.vibe.target_register] then
system.set_clipboard(core.vibe.registers[core.vibe.target_register], true)
-- aand zero it back for further actions
core.vibe.target_register = nil
end
if doc():has_selection() then
text = doc():get_text(doc():get_selection())
end
command.perform("doc:paste")
if text then
system.set_clipboard(text)
end
end,
["vibe:delete-symbol-under-cursor"] = function()
local doc = core.active_view.doc
local line,col,line2,col2 = doc:get_selection()
doc:set_selection(line,col)
doc:delete_to(translate.next_char)
doc:set_selection(line,col,line2,col2)
end,
})


command.add(has_selection, {
["vibe:copy"] = function()
core.log('vibe:copy')
command.perform("doc:copy")
if core.vibe.target_register then
core.vibe.registers[core.vibe.target_register] = system.get_clipboard()
-- aand zero it back for further actions
core.vibe.target_register = nil
end
end,
["vibe:delete"] = function()
core.log('vibe:delete')
local text = doc():get_text(doc():get_selection())
if core.vibe.target_register then
core.vibe.registers[core.vibe.target_register] = text
-- aand zero it back for further actions
core.vibe.target_register = nil
end
system.set_clipboard(text)
command.perform("doc:delete")
end,
})
Expand Down
10 changes: 7 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vibe.flags = {}
vibe.flags['run_stroke_seq'] = false
vibe.flags['recording_macro'] = false

vibe.target_register = nil
vibe.target_register = nil
vibe.registers = require("plugins.lite-xl-vibe.registers")

Expand Down Expand Up @@ -50,6 +51,7 @@ end

function vibe.run_stroke_seq(seq)
vibe.last_executed_seq = seq
local previous_run_stroke_seq = vibe.flags['run_stroke_seq']
vibe.flags['run_stroke_seq'] = true
if type(seq) ~= 'table' then
seq = vibe.kb.split_stroke_seq(seq)
Expand All @@ -67,7 +69,7 @@ function vibe.run_stroke_seq(seq)
end
end
end
vibe.flags['run_stroke_seq'] = false
vibe.flags['run_stroke_seq'] = previous_run_stroke_seq
end

command.add_hook("vibe:switch-to-insert-mode", function()
Expand All @@ -78,6 +80,7 @@ end)

vibe.on_key_pressed__orig = keymap.on_key_pressed
function keymap.on_key_pressed(k)
core.log_quiet('key pressed : %s', k)
if dv():is(CommandView) then
-- only original lite-xl mode in CommandViews
-- .. for now at least
Expand Down Expand Up @@ -107,8 +110,9 @@ function vibe.process_stroke(stroke)
if vibe.flags['run_stroke_seq'] == false then
vibe.last_executed_seq = vibe.last_executed_seq .. stroke
if vibe.flags['recording_macro'] then
vibe.registers[vibe.target_register] =
vibe.registers[vibe.target_register]..stroke
vibe.registers[vibe.recording_register] =
vibe.registers[vibe.recording_register]..stroke
core.log_quiet('added,now reg = |%s|', vibe.registers[vibe.recording_register])
end
end

Expand Down
21 changes: 17 additions & 4 deletions keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ keymap.add_nmap {
["u"] = "doc:undo",
["C-r"] = "doc:redo",
["/"] = "find-replace:find",
[":s"] = "find-replace:replace",
["n"] = "find-replace:repeat-find",
["N"] = "find-replace:previous-find",
["dd"] = "doc:delete-lines",
Expand All @@ -124,21 +125,21 @@ keymap.add_nmap {
["y"] = "vibe:copy",
["d"] = "vibe:delete",

["x"] = "vibe:delete-symbol-under-cursor",
-- actions through sequences, huh? I do like that.
["x"] = "i<delete><ESC>", -- needs to be changed.. (deletes selection)
["o"] = "$i<CR>",
["O"] = "0i<CR><ESC>ki<tab>",
["a"] = "li",
["A"] = "$i",
["C"] = "iS-<end><delete>", -- huh. playing out the `usual` mappings
["D"] = "C<ESC>",
["C"] = "Di",
["D"] = "v$d",

["v$"] = "iS-<end><ESC>",
["y$"] = "v$C-c<ESC>",
["Y"] = "y$",
["C"] = "iS-<end><delete>",
["yy"] = "0iS-<down><ESC>y<up>",
["p"] = "doc:paste",
["p"] = "vibe:paste",

["<delete>"] = "doc:delete",

Expand Down Expand Up @@ -170,6 +171,7 @@ keymap.add_nmap {
[":wC-m"] = "doc:save",
[":w<space>"] = "doc:save-as",
[":l"] = "core:open-log",
[":s"] = "find-replace:replace",
-- may be ok?
[":s<CR>"] = "doc:save",
[":s<space>"] = "doc:save-as",
Expand Down Expand Up @@ -208,6 +210,7 @@ end
-- project-search --
-------------------------------------------------------------------------------
keymap.add_nmap({
["r"] = "project-search:refresh",
["<f5>"] = "project-search:refresh",
["C-/"] = "project-search:find",
["k"] = "project-search:select-previous",
Expand Down Expand Up @@ -235,6 +238,7 @@ keymap.add_nmap({
-------------------------------------------------------------------------------
keymap.add_nmap({
["<f5>"] = "vibe:marks:list:refresh",
["r"] = "vibe:marks:list:refresh",
["C-/"] = "vibe:marks:list:find",
["k"] = "vibe:marks:list:select-previous",
["j"] = "vibe:marks:list:select-next",
Expand Down Expand Up @@ -360,6 +364,15 @@ for obj_name,obj_lets in pairs(object_letters) do
end
end

-------------------------------------------------------------------------------
-- registers

for _,symbol in ipairs(kb.all_typed_symbols) do
keymap.add_nmap({
['"'..kb.escape_stroke(symbol)] = "vibe:target-register-"..symbol,
})
end

-------------------------------------------------------------------------------
-- macroses

Expand Down
33 changes: 20 additions & 13 deletions misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ end
-------------------------------------------------------------------------------
-- vim-like save to clipboard of all deleted text --
-------------------------------------------------------------------------------

local on_text_change__orig = Doc.on_text_change
function Doc:on_text_change(type)
on_text_change__orig(self,type)

if type == "remove" then
system.set_clipboard(self.undo_stack[self.undo_stack.idx-1][3])
end
end
-- allright, it does work but damn it's useless when I use x
-- maybe I should accumulate characters from xs into one ring item? hmm..
-- for now moved all that to vibe:delete

-- local on_text_change__orig = Doc.on_text_change
-- function Doc:on_text_change(type)
-- on_text_change__orig(self,type)
-- if type == "remove" then
-- system.set_clipboard(self.undo_stack[self.undo_stack.idx-1][3])
-- end
-- end

-------------------------------------------------------------------------------
-- clipboard ring --
Expand All @@ -56,10 +58,15 @@ core.vibe.clipboard_ring = {}
core.vibe.clipboard_ring_ix = 0
misc.system__set_clipboard = system.set_clipboard
misc.system__set_clipboard_ix = 0
function system.set_clipboard(s)
core.vibe.clipboard_ring[#core.vibe.clipboard_ring + 1] = s
core.vibe.clipboard_ring_ix = #core.vibe.clipboard_ring
core.vibe.clipboard_ring[#core.vibe.clipboard_ring - config.vibe.clipboard_ring_max] = nil
function system.set_clipboard(s, skip_ring)
if skip_ring then
-- pass

else
core.vibe.clipboard_ring[#core.vibe.clipboard_ring + 1] = s
core.vibe.clipboard_ring_ix = #core.vibe.clipboard_ring
core.vibe.clipboard_ring[#core.vibe.clipboard_ring - config.vibe.clipboard_ring_max] = nil
end
misc.system__set_clipboard(s)
end

Expand Down
13 changes: 10 additions & 3 deletions registers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ local registers = {}

local function start_recording_macro(symbol)
registers[symbol] = ''
core.vibe.target_register = symbol
core.vibe.recording_register = symbol
core.vibe.flags['recording_macro'] = true
end

local function stop_recording_macro(symbol)
core.vibe.target_register = nil
core.vibe.recording_register = nil
core.vibe.flags['recording_macro'] = false
end

for _,symbol in ipairs(kb.all_typed_symbols) do

command.add(nil, {
["vibe:target-register-"..symbol] = function()
core.log("vibe:target-register-"..symbol)
core.vibe.target_register = symbol
end,
})

command.add(function() return not core.vibe.flags['recording_macro'] end,{
["vibe:macro:start-recording-"..symbol] = function()
start_recording_macro(symbol)
Expand All @@ -46,7 +53,7 @@ end

command.add(function() return core.vibe.flags['recording_macro'] end,{
["vibe:macro:stop-recording"] = function()
core.vibe.target_register = nil
core.vibe.recording_register = nil
core.vibe.flags['recording_macro'] = false
end,
})
Expand Down

0 comments on commit e0c67e6

Please sign in to comment.