From bc33c5a25e8fa17a8a24d8dfe4bcb08451cbaa5f Mon Sep 17 00:00:00 2001 From: Iron-E Date: Sun, 9 Apr 2023 17:23:39 -0400 Subject: [PATCH] =?UTF-8?q?style:=20`render`=20=E2=86=92=20`Render`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All the modules in the `ui` module use capital letters for their names. In a followup PR I can normalize the naming convention of: * POD → snake_case * Data + behavior → CamelCase --- lua/barbar.lua | 6 ++--- lua/barbar/api.lua | 44 +++++++++++++++++----------------- lua/barbar/events.lua | 26 ++++++++++---------- lua/barbar/ui/render.lua | 50 +++++++++++++++++++-------------------- lua/bufferline/render.lua | 6 ++--- 5 files changed, 66 insertions(+), 66 deletions(-) diff --git a/lua/barbar.lua b/lua/barbar.lua index ec02e263..422188fc 100644 --- a/lua/barbar.lua +++ b/lua/barbar.lua @@ -10,7 +10,7 @@ local api = require'barbar.api' local bbye = require'barbar.bbye' local events = require'barbar.events' local notify = require'barbar.utils'.notify -local render = require'barbar.ui.render' +local Render = require'barbar.ui.render' local state = require'barbar.state' local utils = require'barbar.utils' @@ -188,13 +188,13 @@ function barbar.setup(options) create_user_command( 'BufferScrollLeft', - function(tbl) render.scroll(-max(1, tbl.count)) end, + function(tbl) Render.scroll(-max(1, tbl.count)) end, {count = true, desc = 'Scroll the bufferline left'} ) create_user_command( 'BufferScrollRight', - function(tbl) render.scroll(max(1, tbl.count)) end, + function(tbl) Render.scroll(max(1, tbl.count)) end, {count = true, desc = 'Scroll the bufferline right'} ) diff --git a/lua/barbar/api.lua b/lua/barbar/api.lua index baf6d046..a21bd4dc 100644 --- a/lua/barbar/api.lua +++ b/lua/barbar/api.lua @@ -22,7 +22,7 @@ local Buffer = require'barbar.buffer' local config = require'barbar.config' local JumpMode = require'barbar.jump_mode' local Layout = require'barbar.ui.layout' -local render = require'barbar.ui.render' +local Render = require'barbar.ui.render' local state = require'barbar.state' local utils = require'barbar.utils' @@ -37,12 +37,12 @@ local function pick_buffer_wrap(fn) end state.is_picking_buffer = true - render.update() + Render.update() fn() state.is_picking_buffer = false - render.update() + Render.update() end --- Shows an error that `bufnr` was not among the `state.buffers` @@ -87,7 +87,7 @@ function api.close_all_but_current() end end - render.update() + Render.update() end --- Close all open buffers, except those in visible windows. @@ -100,7 +100,7 @@ function api.close_all_but_visible() end end - render.update() + Render.update() end --- Close all open buffers, except pinned ones. @@ -112,7 +112,7 @@ function api.close_all_but_pinned() end end - render.update() + Render.update() end --- Close all open buffers, except pinned ones or the current one. @@ -126,7 +126,7 @@ function api.close_all_but_current_or_pinned() end end - render.update() + Render.update() end --- Close all buffers which are visually left of the current buffer. @@ -141,7 +141,7 @@ function api.close_buffers_left() bbye.bdelete(false, state.buffers[i]) end - render.update() + Render.update() end --- Close all buffers which are visually right of the current buffer. @@ -156,7 +156,7 @@ function api.close_buffers_right() bbye.bdelete(false, state.buffers[i]) end - render.update() + Render.update() end -- Restore last recently closed buffer @@ -192,13 +192,13 @@ end --- @param steps integer --- @return nil function api.goto_buffer_relative(steps) - render.get_updated_buffers() + Render.get_updated_buffers() if #state.buffers < 1 then return utils.notify('E85: There is no listed buffer', vim.log.levels.ERROR) end - local current_bufnr = render.set_current_win_listed_buffer() + local current_bufnr = Render.set_current_win_listed_buffer() local idx = utils.index_of(state.buffers, current_bufnr) if not idx then -- fall back to: 1. the alternate buffer, 2. the first buffer @@ -237,7 +237,7 @@ local function move_buffer_animated_tick(ratio, current_animation) end end - render.update() + Render.update() if current_animation.running == false then move_animation = nil @@ -305,14 +305,14 @@ local function move_buffer(from_idx, to_idx) function(ratio, current_animation) move_buffer_animated_tick(ratio, current_animation) end) end - render.update() + Render.update() end --- Move the current buffer to the index specified. --- @param idx integer --- @return nil function api.move_current_buffer_to(idx) - render.update() + Render.update() if idx == -1 then idx = #state.buffers @@ -332,7 +332,7 @@ end --- @param steps integer --- @return nil function api.move_current_buffer(steps) - render.update() + Render.update() local current_bufnr = get_current_buf() local idx = utils.index_of(state.buffers, current_bufnr) @@ -348,7 +348,7 @@ end --- @return nil function api.order_by_buffer_number() table_sort(state.buffers, function(a, b) return a < b end) - render.update() + Render.update() end --- Order the buffers by their parent directory. @@ -379,7 +379,7 @@ function api.order_by_directory() return a_less_than_b end)) - render.update() + Render.update() end --- Order the buffers by filetype. @@ -389,7 +389,7 @@ function api.order_by_language() return buf_get_option(a, 'filetype') < buf_get_option(b, 'filetype') end)) - render.update() + Render.update() end --- Order the buffers by their respective window number. @@ -399,7 +399,7 @@ function api.order_by_window_number() return bufwinnr(buf_get_name(a)) < bufwinnr(buf_get_name(b)) end)) - render.update() + Render.update() end --- Activate the buffer pick mode. @@ -437,7 +437,7 @@ function api.pick_buffer_delete() utils.notify('Invalid input', vim.log.levels.WARN) end - render.update() + Render.update() end end) end @@ -465,7 +465,7 @@ function api.set_offset(width, text, hl, side) { hl = hl, text = text, width = width } or { hl = nil, text = '', width = 0 } - render.update() + Render.update() end --- Toggle the `bufnr`'s "pin" state, visually. @@ -473,7 +473,7 @@ end --- @return nil function api.toggle_pin(buffer_number) state.toggle_pin(buffer_number or 0) - render.update() + Render.update() end return api diff --git a/lua/barbar/events.lua b/lua/barbar/events.lua index 2dd0147c..06545d47 100644 --- a/lua/barbar/events.lua +++ b/lua/barbar/events.lua @@ -26,7 +26,7 @@ local bbye = require'barbar.bbye' local config = require'barbar.config' local highlight = require'barbar.highlight' local JumpMode = require'barbar.jump_mode' -local render = require'barbar.ui.render' +local Render = require'barbar.ui.render' local state = require'barbar.state' local utils = require'barbar.utils' @@ -65,7 +65,7 @@ end --- @return nil events.disable = schedule_wrap(function() events.augroups() -- clear the autocommands - render.set_tabline(nil) -- clear the tabline + Render.set_tabline(nil) -- clear the tabline enabled = false -- mark as disabled end) @@ -86,7 +86,7 @@ function events.enable() callback = vim.schedule_wrap(function(tbl) JumpMode.unassign_letter_for(tbl.buf) state.push_recently_closed(tbl.file) - render.update() + Render.update() end), group = augroup_render, }) @@ -104,14 +104,14 @@ function events.enable() local is_modified = buf_get_option(tbl.buf, 'modified') if is_modified ~= vim.b[tbl.buf].checked then buf_set_var(tbl.buf, 'checked', is_modified) - render.update() + Render.update() end end, group = augroup_render, }) create_autocmd({'BufEnter', 'BufNew'}, { - callback = function() render.update(true) end, + callback = function() Render.update(true) end, group = augroup_render, }) @@ -124,7 +124,7 @@ function events.enable() 'WinEnter', 'WinLeave', }, { - callback = function() render.update() end, + callback = function() Render.update() end, group = augroup_render, } ) @@ -208,7 +208,7 @@ function events.enable() end create_autocmd('OptionSet', { - callback = function() render.update() end, + callback = function() Render.update() end, group = augroup_render, pattern = 'buflisted', }) @@ -225,13 +225,13 @@ function events.enable() if restore_cmd then command(restore_cmd) end vim.defer_fn(function() state.loading_session = false end, 100) - schedule(function() render.update(true) end) + schedule(function() Render.update(true) end) end, group = augroup_render, }) create_autocmd('TermOpen', { - callback = function() defer_fn(function() render.update(true) end, 500) end, + callback = function() defer_fn(function() Render.update(true) end, 500) end, group = augroup_render, }) @@ -277,7 +277,7 @@ function events.enable() }) create_autocmd('WinClosed', { - callback = schedule_wrap(render.update), + callback = schedule_wrap(Render.update), group = augroup_render, }) @@ -299,7 +299,7 @@ function events.enable() ]] end) - render.update() + Render.update() enabled = true end @@ -317,7 +317,7 @@ function events.main_click_handler(bufnr, _, btn, _) if btn == 'm' then bbye.bdelete(false, bufnr) else - render.set_current_win_listed_buffer() + Render.set_current_win_listed_buffer() set_current_buf(bufnr) end end @@ -333,7 +333,7 @@ function events.on_option_changed(user_config) -- Don't jump-start barbar if it is disabled if enabled then - render.update() + Render.update() end end diff --git a/lua/barbar/ui/render.lua b/lua/barbar/ui/render.lua index 189fac4e..994894f7 100644 --- a/lua/barbar/ui/render.lua +++ b/lua/barbar/ui/render.lua @@ -64,8 +64,8 @@ local ANIMATION = { --- @field target integer the place where the bufferline is scrolled/wants to scroll to. local scroll = { current = 0, target = 0 } ---- @class barbar.ui.render -local render = {} +--- @class barbar.ui.Render +local Render = {} --- An incremental animation for `close_buffer_animated`. --- @param bufnr integer @@ -75,10 +75,10 @@ local function close_buffer_animated_tick(bufnr, new_width, animation) if new_width > 0 and state.data_by_bufnr[bufnr] ~= nil then local buffer_data = state.get_buffer_data(bufnr) buffer_data.width = new_width - return render.update() + return Render.update() end animate.stop(animation) - render.close_buffer(bufnr, true) + Render.close_buffer(bufnr, true) end --- Stop tracking the `bufnr` with barbar, and update the bufferline. @@ -86,17 +86,17 @@ end --- @param bufnr integer --- @param do_name_update? boolean refreshes all buffer names iff `true` --- @return nil -function render.close_buffer(bufnr, do_name_update) +function Render.close_buffer(bufnr, do_name_update) state.close_buffer(bufnr, do_name_update) - render.update() + Render.update() end --- Same as `close_buffer`, but animated. --- @param bufnr integer --- @return nil -function render.close_buffer_animated(bufnr) +function Render.close_buffer_animated(bufnr) if config.options.animation == false then - return render.close_buffer(bufnr) + return Render.close_buffer(bufnr) end local buffer_data = state.get_buffer_data(bufnr) @@ -121,7 +121,7 @@ local function open_buffer_animated_tick(bufnr, new_width, animation) local buffer_data = state.get_buffer_data(bufnr) buffer_data.width = animation.running and new_width or nil - render.update() + Render.update() end --- Opens a buffer with animation. @@ -216,7 +216,7 @@ end --- Refresh the buffer list. --- @return integer[] state.buffers -function render.get_updated_buffers(update_names) +function Render.get_updated_buffers(update_names) local current_buffers = state.get_buffer_list() local new_buffers = tbl_filter(function(b) return not tbl_contains(state.buffers, b) end, current_buffers) @@ -234,9 +234,9 @@ function render.get_updated_buffers(update_names) did_change = true if buffer_data.computed_width == nil then - render.close_buffer(buffer_number) + Render.close_buffer(buffer_number) else - render.close_buffer_animated(buffer_number) + Render.close_buffer_animated(buffer_number) end end end @@ -260,7 +260,7 @@ end --- Open the window which contained the buffer which was clicked on. --- @return integer current_bufnr -function render.set_current_win_listed_buffer() +function Render.set_current_win_listed_buffer() local current = get_current_buf() local is_listed = buf_get_option(current, 'buflisted') @@ -289,8 +289,8 @@ end --- Scroll the bufferline relative to its current position. --- @param n integer the amount to scroll by. Use negative numbers to scroll left, and positive to scroll right. --- @return nil -function render.scroll(n) - render.set_scroll(max(0, scroll.target + n)) +function Render.scroll(n) + Render.set_scroll(max(0, scroll.target + n)) end local scroll_animation = nil @@ -302,18 +302,18 @@ local function set_scroll_tick(new_scroll, animation) if animation.running == false then scroll_animation = nil end - render.update(nil, false) + Render.update(nil, false) end --- Scrolls the bufferline to the `target`. --- @param target integer where to scroll to --- @return nil -function render.set_scroll(target) +function Render.set_scroll(target) scroll.target = target if not config.options.animation then scroll.current = target - return render.update(nil, false) + return Render.update(nil, false) end if scroll_animation ~= nil then @@ -328,7 +328,7 @@ end --- Sets and redraws `'tabline'` if `s` does not match the cached value. --- @param s? string --- @return nil -function render.set_tabline(s) +function Render.set_tabline(s) s = s or '' if last_tabline ~= s then last_tabline = s @@ -379,9 +379,9 @@ local function get_bufferline_containers(layout, bufnrs, refocus) local end_ = accumulated_unpinned_width + container_width if scroll.target > start then - render.set_scroll(start) + Render.set_scroll(start) elseif scroll.target + layout.buffers.unpinned_allocated_width < end_ then - render.set_scroll(scroll.target + (end_ - (scroll.target + layout.buffers.unpinned_allocated_width))) + Render.set_scroll(scroll.target + (end_ - (scroll.target + layout.buffers.unpinned_allocated_width))) end end @@ -683,12 +683,12 @@ end --- @param refocus? boolean if `true`, the bufferline will be refocused on the current buffer (default: `true`) --- @param update_names? boolean whether to refresh the names of the buffers (default: `false`) --- @return nil -function render.update(update_names, refocus) +function Render.update(update_names, refocus) if vim.g.SessionLoad then return end - local buffers = Buffer.hide(render.get_updated_buffers(update_names)) + local buffers = Buffer.hide(Render.get_updated_buffers(update_names)) -- Auto hide/show if applicable if config.options.auto_hide then @@ -716,7 +716,7 @@ function render.update(update_names, refocus) -- Render the tabline local ok, result = xpcall( - function() render.set_tabline(generate_tabline(buffers, refocus)) end, + function() Render.set_tabline(generate_tabline(buffers, refocus)) end, debug.traceback ) @@ -731,4 +731,4 @@ function render.update(update_names, refocus) end end -return render +return Render diff --git a/lua/bufferline/render.lua b/lua/bufferline/render.lua index dcdb3a69..bb09c6a8 100644 --- a/lua/bufferline/render.lua +++ b/lua/bufferline/render.lua @@ -1,6 +1,6 @@ -local render = require('barbar.ui.render') +local Render = require('barbar.ui.render') --- @deprecated use `state.restore_buffers` instead -render.restore_buffers = require('barbar.state').restore_buffers +Render.restore_buffers = require('barbar.state').restore_buffers -return render +return Render