Skip to content

Commit

Permalink
Use 'vim.tbl_contains'.
Browse files Browse the repository at this point in the history
  • Loading branch information
declancm committed Jul 13, 2022
1 parent fa92205 commit 7594df8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lua/cinnamon/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local motions = require('cinnamon.motions')

fn.check_command_errors = function(command)
-- If no search pattern, return an error if using a repeat search command.
if utils.contains(motions.search_repeat, command) then
if vim.tbl_contains(motions.search_repeat, command) then
local pattern = vim.fn.getreg('/')
if pattern == '' then
utils.error_msg('The search pattern is empty')
Expand All @@ -19,7 +19,7 @@ fn.check_command_errors = function(command)
end

-- If no word under cursor, return an error if using a word-near-cursor search command.
if utils.contains(motions.search_cursor, command) then
if vim.tbl_contains(motions.search_cursor, command) then
-- Check if string is empty or only whitespace.
if vim.fn.getline('.'):match('^%s*$') then
utils.error_msg('No string under cursor', 'E348')
Expand All @@ -28,7 +28,7 @@ fn.check_command_errors = function(command)
end

-- If no word under cursor, return an error if using a goto declaration command.
if utils.contains(motions.goto_declaration, command) then
if vim.tbl_contains(motions.goto_declaration, command) then
-- Check if string is empty or only whitespace.
if vim.fn.getline('.'):match('^%s*$') then
utils.error_msg('No identifier under cursor', 'E349')
Expand Down
4 changes: 2 additions & 2 deletions lua/cinnamon/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ M.scroll = function(command, scroll_win, use_count, delay_length, deprecated_arg
end

-- Execute command if only moving one line/char.
if utils.contains(motions.no_scroll, command) and vim.v.count1 == 1 then
if vim.tbl_contains(motions.no_scroll, command) and vim.v.count1 == 1 then
vim.cmd('norm! ' .. command)
return
end

-- Check if command is a mouse wheel scroll.
local scroll_wheel = false
if utils.contains(motions.scroll_wheel, command) then
if vim.tbl_contains(motions.scroll_wheel, command) then
scroll_wheel = true
end

Expand Down
9 changes: 0 additions & 9 deletions lua/cinnamon/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ utils.create_keymap = function(mode, lhs, rhs)
end
end

utils.contains = function(table, target)
for _, item in pairs(table) do
if item == target then
return true
end
end
return false
end

utils.merge = function(t1, t2)
for k, v in pairs(t2) do
if (type(v) == 'table') and (type(t1[k] or false) == 'table') then
Expand Down

0 comments on commit 7594df8

Please sign in to comment.