-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to #75: (Lua-only atm) Adds ncmode='focus', VimadeFocus comma…
…nds, VimadeMark commands. VimadeFocus is basically limelight with syntax highlighting. Created scope providers for VimadeFocus including treesitter (similar to twilight), blanks (similar to limelight), static (rolling static size), snacks.nvim, mini-indent, hlchunk.nvim. Scope providers can be configured based on filetype and can be used in any combination. Add VimadeMark, which allows you to select an area and prevent it from being faded.
- Loading branch information
Showing
24 changed files
with
2,134 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
local M = {} | ||
|
||
local CORE = require('vimade.focus.core') | ||
|
||
local events = require('vimade.util.events')() | ||
|
||
M.__init = CORE.__init | ||
|
||
M.on = events.on | ||
|
||
M.get = CORE.get | ||
|
||
M.update = CORE.update | ||
|
||
M.cleanup = CORE.cleanup | ||
|
||
M.setup = CORE.setup | ||
|
||
M.global_focus_enabled = function() | ||
return CORE.global_focus_enabled | ||
end | ||
|
||
M.toggle_on = function() | ||
if vim.g.vimade_running == 0 then | ||
return | ||
end | ||
CORE.activate_focus() | ||
events.notify('focus:on') | ||
end | ||
|
||
M.toggle_off = function() | ||
CORE.deactivate_focus() | ||
events.notify('focus:off') | ||
end | ||
|
||
M.toggle = function() | ||
if CORE.global_focus_enabled then | ||
M.toggle_off() | ||
else | ||
M.toggle_on() | ||
end | ||
end | ||
|
||
-- If no range is provided, any marks under the cursor will be removed. | ||
-- If a range is provided, a new mark will be placed. Any marks overlapping the selection will be replaced. | ||
-- config = {@optional range={start, end}} | ||
M.mark_toggle = function(config) | ||
CORE.mark_toggle(config) | ||
events.notify('focus:mark') | ||
end | ||
|
||
-- Places a mark between the range of lines in the window. | ||
-- config = { | ||
-- @optional range={start, end} [default = cursor_location], | ||
-- @optional winid: number [default = vim.api.nvim_get_current_win()] | ||
-- } | ||
M.mark_set = function(config) | ||
CORE.mark_set(config) | ||
events.notify('focus:mark') | ||
end | ||
|
||
-- removes all marks meeting the criteria. If no criteria is included, | ||
-- all marks are removed. | ||
-- config = { | ||
-- @optional range: {start, end} -- NOTE: If range is provided without winid, the current window is assumed. | ||
-- @optional winid: number | ||
-- @optional bufnr: number | ||
-- @optional tabnr: number | ||
-- } | ||
M.mark_remove = function(config) | ||
CORE.mark_remove(config) | ||
events.notify('focus:mark') | ||
end | ||
|
||
M.disable = function() | ||
M.toggle_off() | ||
CORE.cleanup({}) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
local TYPE = require('vimade.util.type') | ||
local API = require('vimade.focus.api') | ||
|
||
local root_options = { | ||
{'VimadeMark', { | ||
{'', function(cmds, arg) API.mark_toggle({range={arg.line1, arg.line2}}) end}, | ||
{'set', function(cmds, arg) API.mark_set({range={arg.line1, arg.line2}}) end}, | ||
{'remove', function(cmds, arg) API.mark_remove({range={arg.line1, arg.line2}}) end}, | ||
{'remove-win', function(cmds, arg) API.mark_remove({winid=vim.api.nvim_get_current_win()}) end}, | ||
{'remove-buf', function(cmds, arg) API.mark_remove({bufnr=vim.api.nvim_get_current_buf()}) end}, | ||
{'remove-tab', function(cmds, arg) API.mark_remove({tabnr=vim.api.nvim_get_current_tabpage()}) end}, | ||
{'remove-all', function(cmds, arg) API.mark_remove({}) end}, | ||
}}, | ||
{'VimadeFocus', { | ||
{'', API.toggle}, | ||
{'toggle', API.toggle}, | ||
{'toggle-on', API.toggle_on}, | ||
{'toggle-off', API.toggle_off}, | ||
}} | ||
} | ||
|
||
local options_of = function(input) | ||
local result = {} | ||
for i, value in ipairs(input) do | ||
if value[1] ~= '' then | ||
table.insert(result, value[1]) | ||
end | ||
end | ||
return result | ||
end | ||
|
||
local process_input = function(input, exact) | ||
local inputs = input:gmatch('([^\\ ]+)') | ||
local options = TYPE.deep_copy(root_options) | ||
local result_options = {} | ||
local remaining = {} | ||
local run = true | ||
local input_size = 0 | ||
local ends_sp = input:sub(-1) == ' ' | ||
local process = {} | ||
for input in inputs do | ||
input = input:lower() | ||
input_size = input_size + 1 | ||
table.insert(process, input) | ||
end | ||
for i, key in ipairs(process) do | ||
local found = false | ||
for _, option in ipairs(options) do | ||
if key == option[1]:lower() then | ||
found = true | ||
if type(option[2]) == 'function' then | ||
table.insert(result_options, option) | ||
elseif i < input_size or ends_sp or exact then | ||
options = option[2] | ||
else | ||
table.insert(remaining, key) | ||
end | ||
break | ||
end | ||
end | ||
if not exact and not found then | ||
table.insert(remaining, key) | ||
end | ||
end | ||
if #remaining > 1 then | ||
return {} | ||
end | ||
if exact and #result_options > 0 then | ||
options = result_options | ||
end | ||
remaining = remaining[1] | ||
local r_ln = remaining and remaining:len() or 0 | ||
local indices = {} | ||
for i, option in ipairs(options) do | ||
indices[option[1]] = i | ||
end | ||
table.sort(options, function(a, b) | ||
local a_is_remaining = a[1]:sub(1, r_ln) == remaining | ||
local b_is_remaining = b[1]:sub(1, r_ln) == remaining | ||
if (a_is_remaining and b_is_remaining) or (not a_is_remaining and not b_is_remaining) then | ||
return indices[a[1]] < indices[b[1]] | ||
elseif a_is_remaining then | ||
return true | ||
elseif b_is_remaining then | ||
return false | ||
end | ||
end) | ||
return options | ||
end | ||
|
||
for _, cmd in ipairs(root_options) do | ||
vim.api.nvim_create_user_command(cmd[1], function(args) | ||
local selection = process_input(args.name .. ' ' .. (args.fargs[1] or ''), true) | ||
local same_level_commands = {} | ||
for _, option in ipairs(selection) do | ||
table.insert(same_level_commands, option[1]) | ||
end | ||
-- only the first is THE selection | ||
if selection[1] and type(selection[1][2]) == 'function' then | ||
selection[1][2](same_level_commands, args) | ||
end | ||
end, { | ||
nargs = '?', | ||
range = true, | ||
complete = function(last_cmd, input) | ||
input = input or '' | ||
input = input:gsub('^\'<,\'>','') | ||
return options_of(process_input(input)) | ||
end | ||
}) | ||
end |
Oops, something went wrong.