From ee1a2f0a746c26e0aea35d40de9ec0335952556f Mon Sep 17 00:00:00 2001 From: James Reed Date: Wed, 6 Nov 2019 11:04:58 -0700 Subject: Add function to check if attached to a buffer --- lua/colorizer.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lua') diff --git a/lua/colorizer.lua b/lua/colorizer.lua index 657afe7..7fdd206 100644 --- a/lua/colorizer.lua +++ b/lua/colorizer.lua @@ -489,6 +489,16 @@ local function new_buffer_options(buf) return FILETYPE_OPTIONS[filetype] or SETUP_SETTINGS.default_options end +--- Check if attached to a buffer. +-- @tparam[opt=0|nil] integer buf A value of 0 implies the current buffer. +-- @return true if attached to the buffer, false otherwise. +local function is_buffer_attached(buf) + if buf == 0 or buf == nil then + buf = nvim_get_current_buf() + end + return BUFFER_OPTIONS[buf] ~= nil +end + --- Attach to a buffer and continuously highlight changes. -- @tparam[opt=0|nil] integer buf A value of 0 implies the current buffer. -- @param[opt] options Configuration options as described in `setup` @@ -627,6 +637,7 @@ end return { DEFAULT_NAMESPACE = DEFAULT_NAMESPACE; setup = setup; + is_buffer_attached = is_buffer_attached; attach_to_buffer = attach_to_buffer; detach_from_buffer = detach_from_buffer; highlight_buffer = highlight_buffer; -- cgit v1.2.3-70-g09d2