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

Migrate commands definition inside setup() #83

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ library to do custom highlighting themselves.
},
-- all the sub-options of filetypes apply to buftypes
buftypes = {},
-- disable built-in commands with `false`
default_commands = true,
}
```

Expand Down
32 changes: 32 additions & 0 deletions lua/colorizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ local SETUP_SETTINGS = {
exclusions = { buf = {}, file = {} },
all = { file = false, buf = false },
default_options = USER_DEFAULT_OPTIONS,
default_commands = true,
}

--- Make new buffer Configuration
Expand Down Expand Up @@ -438,6 +439,32 @@ function colorizer.attach_to_buffer(buf, options, typ)
BUFFER_LOCAL[buf].__augroup_id = au_group_id
end

function define_commands()
local command = vim.api.nvim_create_user_command

command("ColorizerAttachToBuffer", function()
require("colorizer").attach_to_buffer(0)
end, {})

-- Stop highlighting the current buffer (detach).
command("ColorizerDetachFromBuffer", function()
require("colorizer").detach_from_buffer(0)
end, {})

command("ColorizerReloadAllBuffers", function()
require("colorizer").reload_all_buffers()
end, {})

command("ColorizerToggle", function()
local c = require "colorizer"
if c.is_buffer_attached(0) then
c.detach_from_buffer(0)
else
c.attach_to_buffer(0)
end
end, {})
end

---Easy to use function if you want the full setup without fine grained control.
--Setup an autocmd which enables colorizing for the filetypes and options specified.
--
Expand All @@ -454,6 +481,7 @@ end
-- user_default_options,
-- -- all the sub-options of filetypes apply to buftypes
-- buftypes = {},
-- default_commands = true,
-- }
--</pre>
--For all user_default_options, see |user_default_options|
Expand All @@ -469,6 +497,10 @@ function colorizer.setup(config)

local conf = vim.deepcopy(config) or {}

if conf.default_commands ~= false then
define_commands()
end

-- if nothing given the enable for all filetypes
local filetypes = conf.filetypes or conf[1] or { "*" }
local user_default_options = conf.user_default_options or conf[2] or {}
Expand Down
29 changes: 0 additions & 29 deletions plugin/colorizer.lua

This file was deleted.