Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14 make buffer mappings configurable #15

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions lua/yode-nvim/changeSyncing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ local onSeditorBufferLines = function(_, bufId, _, firstline, lastline, newLastl
local seditorWindow = seditors.selectors.getSeditorById(bufId)
local operationType = h.getOperationOfBufLinesEvent(firstline, lastline, linedata)
local lineData = seditorWindow.indentCount
and h.map(
R.concat(h.createWhiteSpace(seditorWindow.indentCount)),
linedata
)
and h.map(R.concat(h.createWhiteSpace(seditorWindow.indentCount)), linedata)
or linedata

log.debug(bufId, operationType, {
Expand Down Expand Up @@ -278,11 +275,8 @@ local onFileBufferLines = function(_, bufId, tick, firstline, lastline, newLastl
local linedata = vim.api.nvim_buf_get_lines(bufId, firstline, newLastline, true)
local lineLength = lastline - firstline
local dataLength = #linedata
local operationType, editLineCount = h.getOperationOfBufLinesEvent(
firstline,
lastline,
linedata
)
local operationType, editLineCount =
h.getOperationOfBufLinesEvent(firstline, lastline, linedata)
log.debug(
bufId,
'lines:',
Expand Down
12 changes: 2 additions & 10 deletions lua/yode-nvim/createSeditor.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local h = require('yode-nvim.helper')
local logging = require('yode-nvim.logging')
local handlers = require('yode-nvim.handlers')
local storeBundle = require('yode-nvim.redux.index')
local seditors = storeBundle.seditors
local R = require('yode-nvim.deps.lamda.dist.lamda')
Expand Down Expand Up @@ -46,16 +47,7 @@ local createSeditor = function(opts)
local name = getFileBufferName(fileBufferId, seditorBufferId)
vim.api.nvim_buf_call(seditorBufferId, function()
vim.cmd('file ' .. name)
vim.cmd([[
nmap <buffer> <leader>bll :YodeGoToAlternateBuffer<cr>
imap <buffer> <leader>bll <esc>:YodeGoToAlternateBuffer<cr>
nmap <buffer> <leader>blt :YodeGoToAlternateBuffer t<cr>
imap <buffer> <leader>blt <esc>:YodeGoToAlternateBuffer t<cr>
nmap <buffer> <leader>blz :YodeGoToAlternateBuffer z<cr>
imap <buffer> <leader>blz <esc>:YodeGoToAlternateBuffer z<cr>
nmap <buffer> <leader>blb :YodeGoToAlternateBuffer b<cr>
imap <buffer> <leader>blb <esc>:YodeGoToAlternateBuffer b<cr>
]])
handlers.fns.onSeditorBufCal()
end)
return seditorBufferId
end
Expand Down
14 changes: 14 additions & 0 deletions lua/yode-nvim/defaultConfig.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
local M = {
log = {},
handlers = {
onSeditorBufCal = function()
vim.cmd([[
nmap <buffer> <leader>bll :YodeGoToAlternateBuffer<cr>
imap <buffer> <leader>bll <esc>:YodeGoToAlternateBuffer<cr>
nmap <buffer> <leader>blt :YodeGoToAlternateBuffer t<cr>
imap <buffer> <leader>blt <esc>:YodeGoToAlternateBuffer t<cr>
nmap <buffer> <leader>blz :YodeGoToAlternateBuffer z<cr>
imap <buffer> <leader>blz <esc>:YodeGoToAlternateBuffer z<cr>
nmap <buffer> <leader>blb :YodeGoToAlternateBuffer b<cr>
imap <buffer> <leader>blb <esc>:YodeGoToAlternateBuffer b<cr>
]])
end,
},
}

M.log.level = 'warn'
Expand Down
33 changes: 11 additions & 22 deletions lua/yode-nvim/diffLib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ M.findConnectedBlocks = function(diffData)
local lineGroups = h.map(function(group)
local findHappyStart = function(tokens)
local dropTokensBeforeCount = R.max(1, tokens[1].index - CONNECTED_TOKEN_BORDER)
local tokensBeforeProbablyMiddleInLine = R.pipe(
R.drop(dropTokensBeforeCount - 1),
withoutInTokens
)(diffData.diffTokens)
local tokensBeforeProbablyMiddleInLine =
R.pipe(R.drop(dropTokensBeforeCount - 1), withoutInTokens)(diffData.diffTokens)
local tokenTillStartOfLine = R.pipe(
R.take(dropTokensBeforeCount - 1),
withoutInTokens,
Expand All @@ -144,27 +142,21 @@ M.findConnectedBlocks = function(diffData)
end)
)(diffData.diffTokens)
local validDiffTokens = R.concat(tokenTillStartOfLine, tokensBeforeProbablyMiddleInLine)
local diffTokens = R.takeWhile(
R.complement(R.propEq('index', tokens[1].index)),
validDiffTokens
)
local diffTokens =
R.takeWhile(R.complement(R.propEq('index', tokens[1].index)), validDiffTokens)
local diffLines = R.pipe(
R.take(R.min(START_END_COMPARE_COUNT, #tokens + CONNECTED_TOKEN_BORDER)),
M.joinTokenText,
R.split('\n')
)(validDiffTokens)
local lineCount = R.length(diffLines)
local baseText =
R.pipe(
M.joinTokenText,
R.split('\n'),
R.take(lineCount),
R.join('\n')
)(diffData.newTokens)
local startMatches = h.map(function(counter)
local diffLinesMatch = R.pipe(R.drop(counter), R.take(lineCount - counter))(
diffLines
R.pipe(M.joinTokenText, R.split('\n'), R.take(lineCount), R.join('\n'))(
diffData.newTokens
)
local startMatches = h.map(function(counter)
local diffLinesMatch =
R.pipe(R.drop(counter), R.take(lineCount - counter))(diffLines)
local text = R.join('\n', diffLinesMatch)
local distance = getEditDistance(baseText, text)

Expand Down Expand Up @@ -230,11 +222,8 @@ M.findConnectedBlocks = function(diffData)
end),
R.join('')
)
local additionalTokensTrimmed = h.over(
h.lensIndex(1),
h.over(h.lensProp('token'), trimToken),
additionalTokens
)
local additionalTokensTrimmed =
h.over(h.lensIndex(1), h.over(h.lensProp('token'), trimToken), additionalTokens)
local grouWithHappyStart = R.concat(additionalTokensTrimmed, tokens)

return startLine, grouWithHappyStart
Expand Down
12 changes: 12 additions & 0 deletions lua/yode-nvim/handlers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local R = require('yode-nvim.deps.lamda.dist.lamda')
local logging = require('yode-nvim.logging')
local M = { fns = {} }

M.setup = function(handlers)
local log = logging.create('handlers')
log.debug('args', handlers)
M.fns = R.pick({ 'onSeditorBufCal' }, handlers)
log.debug('computed', M.fns)
end

return M
4 changes: 3 additions & 1 deletion lua/yode-nvim/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
local mapWithObjectKey = function(fn, data)
return R.reduce(function(acc, key)
return R.assoc(key, fn(data[key], key, data), acc)
end, {}, R.keys(data))
end, {}, M.keysSorted(data))
end

M.mapWithIndex = R.curry2(function(fn, data)
Expand All @@ -29,6 +29,8 @@ M.mapWithIndex = R.curry2(function(fn, data)
return mapWithObjectKey(fn, data)
end)

M.keysSorted = R.pipe(R.keys, R.sort(R.lt))

M.maxPositiveNumber = math.pow(2, 1024)
--M.maxNegative = M.maxPositiveNumber * -1

Expand Down
60 changes: 27 additions & 33 deletions lua/yode-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local defaultConfig = require('yode-nvim.defaultConfig')
local logging = require('yode-nvim.logging')
local handlers = require('yode-nvim.handlers')
local R = require('yode-nvim.deps.lamda.dist.lamda')
local storeBundle = require('yode-nvim.redux.index')
local store = storeBundle.store
Expand All @@ -17,8 +18,17 @@ local M = {
local lastTabId = 1

M.setup = function(options)
if not R.isEmpty(M.config) then
local log = logging.create('setup')
log.debug('already configured', M.config)
return
end

M.config = vim.tbl_deep_extend('force', defaultConfig, options or {})
logging.setup(M.config.log)
handlers.setup(M.config.handlers)
local log = logging.create('setup')
log.debug('configured with options', options, 'to', M.config)
end

M.yodeNvim = function()
Expand All @@ -27,7 +37,7 @@ M.yodeNvim = function()
--testSetup.setup2()
--testSetup.setup3()

vim.cmd('YodeBufferDelete')
--vim.cmd('YodeBufferDelete')
--vim.cmd('tabnew')
--vim.cmd('normal G')
--vim.cmd('normal gg10j16dd')
Expand Down Expand Up @@ -117,10 +127,8 @@ M.cloneCurrentIntoFloat = function()
local bufId = vim.fn.bufnr('%')
local winId = vim.fn.win_getid()

local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ bufId = bufId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { bufId = bufId })
if floatWin then
log.warn('buffer is already visible as floating window!')
return
Expand All @@ -144,10 +152,8 @@ M.bufferDelete = function()
local log = logging.create('bufferDelete')
local winId = vim.fn.win_getid()
local bufId = vim.fn.bufnr('%')
local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ winId = winId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { winId = winId })

if floatWin then
log.debug('deleting floating window', bufId, winId)
Expand Down Expand Up @@ -216,10 +222,8 @@ end
M.onBufWinEnter = function()
local log = logging.create('onBufWinEnter')
local winId = vim.fn.win_getid()
local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ winId = winId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { winId = winId })
if floatWin == nil then
return
end
Expand Down Expand Up @@ -262,10 +266,8 @@ end

M.layoutShiftWinDown = function()
local winId = vim.fn.win_getid()
local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ winId = winId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { winId = winId })
if floatWin == nil then
vim.cmd('wincmd r')
return
Expand All @@ -279,10 +281,8 @@ end

M.layoutShiftWinUp = function()
local winId = vim.fn.win_getid()
local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ winId = winId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { winId = winId })
if floatWin == nil then
vim.cmd('wincmd R')
return
Expand All @@ -296,10 +296,8 @@ end

M.layoutShiftWinBottom = function()
local winId = vim.fn.win_getid()
local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ winId = winId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { winId = winId })
if floatWin == nil then
vim.cmd('wincmd J')
return
Expand All @@ -313,10 +311,8 @@ end

M.layoutShiftWinTop = function()
local winId = vim.fn.win_getid()
local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ winId = winId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { winId = winId })
if floatWin == nil then
vim.cmd('wincmd K')
return
Expand Down Expand Up @@ -356,10 +352,8 @@ M.floatToMainWindow = function()
return
end

local floatWin = layout.selectors.getWindowBySomeId(
vim.api.nvim_get_current_tabpage(),
{ bufId = bufId }
)
local floatWin =
layout.selectors.getWindowBySomeId(vim.api.nvim_get_current_tabpage(), { bufId = bufId })
if not floatWin then
log.debug('buffer is not floating, nothing to do')
return
Expand Down
6 changes: 2 additions & 4 deletions lua/yode-nvim/redux/index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ local wrapWithDispatch = h.map(function(action)
end
end)

M.store = createStore(
reducers,
applyMiddleware(stateLogger, layoutStateToNeovim, generalStateToNeovim)
)
M.store =
createStore(reducers, applyMiddleware(stateLogger, layoutStateToNeovim, generalStateToNeovim))
M.seditors = {
actions = wrapWithDispatch(seditorsReducer.actions),
selectors = globalizeSelectors(STATE_PATH_SEDITORS, seditorsReducer.selectors),
Expand Down
12 changes: 4 additions & 8 deletions lua/yode-nvim/redux/seditorsReducer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ local INIT_SEDITOR = 'INIT_SEDITOR'
M.actions.initSeditor = R.pipe(R.pick({ 'seditorBufferId', 'data' }), R.assoc('type', INIT_SEDITOR))

local CHANGE_START_LINE = 'CHANGE_START_LINE'
M.actions.changeStartLine = R.pipe(
R.pick({ 'seditorBufferId', 'amount' }),
R.assoc('type', CHANGE_START_LINE)
)
M.actions.changeStartLine =
R.pipe(R.pick({ 'seditorBufferId', 'amount' }), R.assoc('type', CHANGE_START_LINE))

local CHANGE_DATA = 'CHANGE_DATA'
M.actions.changeData = R.pipe(R.pick({ 'seditorBufferId', 'data' }), R.assoc('type', CHANGE_DATA))
Expand All @@ -32,10 +30,8 @@ M.actions.softlyKillSeditor = R.pipe(
)

M.actionNames.RESURRECT_SEDITOR = 'RESURRECT_SEDITOR'
M.actions.resurrectSeditor = R.pipe(
R.pick({ 'seditorBufferId' }),
R.assoc('type', M.actionNames.RESURRECT_SEDITOR)
)
M.actions.resurrectSeditor =
R.pipe(R.pick({ 'seditorBufferId' }), R.assoc('type', M.actionNames.RESURRECT_SEDITOR))

M.selectors.getSeditorById = function(id, state)
return R.prop(id, state)
Expand Down
6 changes: 2 additions & 4 deletions lua/yode-nvim/seditor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ M.checkLineDataIndentCount = function(sed, lineData)
data = { indentCount = indentCount },
})
local currentLines = vim.api.nvim_buf_get_lines(sed.seditorBufferId, 0, -1, true)
local changedLines = h.map(
R.concat(h.createWhiteSpace(sed.indentCount - indentCount)),
currentLines
)
local changedLines =
h.map(R.concat(h.createWhiteSpace(sed.indentCount - indentCount)), currentLines)

vim.schedule(function()
vim.api.nvim_buf_set_lines(sed.seditorBufferId, 0, -1, true, changedLines)
Expand Down
Loading