From aaa3b3236e23b1934c56d7a0cab29054bebdb7c9 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 21 Jul 2024 21:47:24 +0200 Subject: [PATCH] nvim: use consistent style for lua files --- config/nvim/lua/fschauen/autocmd.lua | 12 +- config/nvim/lua/fschauen/diagnostic.lua | 8 +- .../nvim/lua/fschauen/plugins/colorizer.lua | 8 +- .../nvim/lua/fschauen/plugins/colorscheme.lua | 4 +- .../nvim/lua/fschauen/plugins/completion.lua | 31 ++-- config/nvim/lua/fschauen/plugins/dial.lua | 8 +- .../nvim/lua/fschauen/plugins/formatter.lua | 12 +- .../nvim/lua/fschauen/plugins/headlines.lua | 8 +- config/nvim/lua/fschauen/plugins/lsp.lua | 9 +- config/nvim/lua/fschauen/plugins/lualine.lua | 151 +++++++++--------- .../lua/fschauen/plugins/markdown-preview.lua | 4 +- .../nvim/lua/fschauen/plugins/nvim-lint.lua | 4 +- .../nvim/lua/fschauen/plugins/nvim-notify.lua | 4 +- .../nvim/lua/fschauen/plugins/openbrowser.lua | 4 +- .../plugins/telescope-file-browser.lua | 10 +- .../nvim/lua/fschauen/plugins/telescope.lua | 12 +- .../nvim/lua/fschauen/plugins/text-case.lua | 10 +- config/nvim/lua/fschauen/util/init.lua | 4 +- config/nvim/lua/fschauen/util/lua.lua | 8 +- config/nvim/lua/fschauen/util/options.lua | 4 +- config/nvim/lua/fschauen/window.lua | 56 ++----- config/nvim/stylua.toml | 5 +- 22 files changed, 156 insertions(+), 220 deletions(-) diff --git a/config/nvim/lua/fschauen/autocmd.lua b/config/nvim/lua/fschauen/autocmd.lua index 621521d..4626991 100644 --- a/config/nvim/lua/fschauen/autocmd.lua +++ b/config/nvim/lua/fschauen/autocmd.lua @@ -7,27 +7,21 @@ M.setup = function() desc = "Briefly highlight yanked text.", group = group, pattern = "*", - callback = function(_) - vim.highlight.on_yank() - end, + callback = function(_) vim.highlight.on_yank() end, }) vim.api.nvim_create_autocmd("InsertEnter", { desc = "Hide cursor line when entering insert mode.", group = group, pattern = "*", - callback = function(_) - vim.opt.cursorlineopt = "number" - end, + callback = function(_) vim.opt.cursorlineopt = "number" end, }) vim.api.nvim_create_autocmd("InsertLeave", { desc = "Show cursor line when leaving insert mode.", group = group, pattern = "*", - callback = function(_) - vim.opt.cursorlineopt = "both" - end, + callback = function(_) vim.opt.cursorlineopt = "both" end, }) end diff --git a/config/nvim/lua/fschauen/diagnostic.lua b/config/nvim/lua/fschauen/diagnostic.lua index 9f60acf..8314a55 100644 --- a/config/nvim/lua/fschauen/diagnostic.lua +++ b/config/nvim/lua/fschauen/diagnostic.lua @@ -37,9 +37,7 @@ end ---Show diagnostics in a floating window. ---@param opts table|nil: options passed along to `vim.diagnostic.open_float`. -M.open_float = function(opts) - vim.diagnostic.open_float(opts) -end +M.open_float = function(opts) vim.diagnostic.open_float(opts) end ---Toggle diagnostics in the given buffer. ---@param bufnr integer|nil: Buffer number (0 for current buffer, nil for all buffers. @@ -54,9 +52,7 @@ end ---Hide currently displayed diagnostics. ---@param bufnr integer|nil: Buffer number (0 for current buffer, nil for all buffers. -M.hide = function(bufnr) - vim.diagnostic.hide(nil, bufnr or 0) -end +M.hide = function(bufnr) vim.diagnostic.hide(nil, bufnr or 0) end M.select_virtual_text_severity = function() vim.ui.select( diff --git a/config/nvim/lua/fschauen/plugins/colorizer.lua b/config/nvim/lua/fschauen/plugins/colorizer.lua index 928b327..65c8e31 100644 --- a/config/nvim/lua/fschauen/plugins/colorizer.lua +++ b/config/nvim/lua/fschauen/plugins/colorizer.lua @@ -1,9 +1,7 @@ return { "norcalli/nvim-colorizer.lua", - cond = function(_) - return vim.o.termguicolors - end, + cond = function(_) return vim.o.termguicolors end, event = { "BufNewFile", "BufReadPost" }, @@ -12,7 +10,5 @@ return { mode = "foreground", }, - config = function(_, opts) - require("colorizer").setup(nil, opts) - end, + config = function(_, opts) require("colorizer").setup(nil, opts) end, } diff --git a/config/nvim/lua/fschauen/plugins/colorscheme.lua b/config/nvim/lua/fschauen/plugins/colorscheme.lua index 66a04f2..baccee1 100644 --- a/config/nvim/lua/fschauen/plugins/colorscheme.lua +++ b/config/nvim/lua/fschauen/plugins/colorscheme.lua @@ -39,9 +39,7 @@ return { opts = { style = "night", dim_inactive = true, - on_colors = function(colors) - colors.bg_highlight = "#1d212f" - end, + on_colors = function(colors) colors.bg_highlight = "#1d212f" end, }, }, } diff --git a/config/nvim/lua/fschauen/plugins/completion.lua b/config/nvim/lua/fschauen/plugins/completion.lua index 056dc03..845320e 100644 --- a/config/nvim/lua/fschauen/plugins/completion.lua +++ b/config/nvim/lua/fschauen/plugins/completion.lua @@ -1,8 +1,6 @@ local make_keymap = function(cmp) local if_visible = function(yes, no) - no = no or function(fallback) - fallback() - end + no = no or function(fallback) fallback() end return function(fallback) if cmp.visible() then yes(fallback) @@ -12,19 +10,19 @@ local make_keymap = function(cmp) end end + local m = cmp.mapping local select = { behavior = cmp.SelectBehavior.Select } - local next_or_complete = if_visible(cmp.mapping.select_next_item(select), cmp.mapping.complete()) - local prev_or_complete = if_visible(cmp.mapping.select_prev_item(select), cmp.mapping.complete()) - local next = if_visible(cmp.mapping.select_next_item(select)) - local prev = if_visible(cmp.mapping.select_prev_item(select)) + local next_or_complete = if_visible(m.select_next_item(select), m.complete()) + local prev_or_complete = if_visible(m.select_prev_item(select), m.complete()) + local next = if_visible(m.select_next_item(select)) + local prev = if_visible(m.select_prev_item(select)) - local abort = if_visible(cmp.mapping.abort()) - local confirm = if_visible(cmp.mapping.confirm { select = true }) - local confirm_or_complete = - if_visible(cmp.mapping.confirm { select = true }, cmp.mapping.complete()) + local abort = if_visible(m.abort()) + local confirm = if_visible(m.confirm { select = true }) + local confirm_or_complete = if_visible(m.confirm { select = true }, m.complete()) - local scroll_docs_down = cmp.mapping.scroll_docs(3) - local scroll_docs_up = cmp.mapping.scroll_docs(-3) + local scroll_docs_down = m.scroll_docs(3) + local scroll_docs_up = m.scroll_docs(-3) -- Mappings that should work in both command line and Insert mode. return { @@ -76,13 +74,12 @@ return { enabled = function() local ctx = require("cmp.config.context") - return not ctx.in_treesitter_capture("comment") and not ctx.in_syntax_group("Comment") + return not ctx.in_treesitter_capture("comment") + and not ctx.in_syntax_group("Comment") end, snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, + expand = function(args) require("luasnip").lsp_expand(args.body) end, }, formatting = { diff --git a/config/nvim/lua/fschauen/plugins/dial.lua b/config/nvim/lua/fschauen/plugins/dial.lua index e23b279..807929a 100644 --- a/config/nvim/lua/fschauen/plugins/dial.lua +++ b/config/nvim/lua/fschauen/plugins/dial.lua @@ -4,9 +4,7 @@ ---@return function local dial_cmd = function(cmd, suffix) suffix = suffix or "" - return function() - return require("dial.map")[cmd]() .. suffix - end + return function() return require("dial.map")[cmd]() .. suffix end end ---Make a new augend that cycles over the given elements. @@ -30,9 +28,7 @@ local weekdays = { "Sunday", } -local weekdays_short = vim.tbl_map(function(s) - return s:sub(1, 3) -end, weekdays) +local weekdays_short = vim.tbl_map(function(s) return s:sub(1, 3) end, weekdays) local ui = require("fschauen.util.icons").ui local inc, dec = ui.Increment, ui.Decrement diff --git a/config/nvim/lua/fschauen/plugins/formatter.lua b/config/nvim/lua/fschauen/plugins/formatter.lua index 8de783e..122e2b5 100644 --- a/config/nvim/lua/fschauen/plugins/formatter.lua +++ b/config/nvim/lua/fschauen/plugins/formatter.lua @@ -22,17 +22,17 @@ local shfmt = function() end local toggle_format_on_write = (function() - local augroup_id = nil + local augroup = nil return function() - if augroup_id then - vim.api.nvim_del_augroup_by_id(augroup_id) - augroup_id = nil + if augroup then + vim.api.nvim_del_augroup_by_id(augroup) + augroup = nil vim.notify("Format on write DISABLED", vim.log.levels.WARN) else - augroup_id = vim.api.nvim_create_augroup("fschauen.format_on_write", { clear = true }) + augroup = vim.api.nvim_create_augroup("fschauen.format_on_write", { clear = true }) vim.api.nvim_create_autocmd("BufWritePost", { desc = "Format files on write.", - group = augroup_id, + group = augroup, pattern = "*", command = ":FormatWrite", }) diff --git a/config/nvim/lua/fschauen/plugins/headlines.lua b/config/nvim/lua/fschauen/plugins/headlines.lua index 642f713..5466320 100644 --- a/config/nvim/lua/fschauen/plugins/headlines.lua +++ b/config/nvim/lua/fschauen/plugins/headlines.lua @@ -18,7 +18,13 @@ return { require("headlines").setup { markdown = { - headline_highlights = { "Headline1", "Headline2", "Headline3", "Headline4", "Headline5" }, + headline_highlights = { + "Headline1", + "Headline2", + "Headline3", + "Headline4", + "Headline5", + }, bullets = "", dash_string = "", fat_headlines = false, diff --git a/config/nvim/lua/fschauen/plugins/lsp.lua b/config/nvim/lua/fschauen/plugins/lsp.lua index 7928ee5..3a4f9aa 100644 --- a/config/nvim/lua/fschauen/plugins/lsp.lua +++ b/config/nvim/lua/fschauen/plugins/lsp.lua @@ -12,7 +12,10 @@ end local lsp_handlers = function() return { ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, border), - ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, border), + ["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, + border + ), } end @@ -85,9 +88,7 @@ local server_opts = setmetatable({ }, { -- The default is a just a passthrough of the options. __index = function() - return function(opts) - return opts - end + return function(opts) return opts end end, }) diff --git a/config/nvim/lua/fschauen/plugins/lualine.lua b/config/nvim/lua/fschauen/plugins/lualine.lua index 9bbaaeb..0bc92be 100644 --- a/config/nvim/lua/fschauen/plugins/lualine.lua +++ b/config/nvim/lua/fschauen/plugins/lualine.lua @@ -1,33 +1,36 @@ -local M = { 'nvim-lualine/lualine.nvim' } +local M = { "nvim-lualine/lualine.nvim" } -local icons = require('fschauen.util.icons') +local icons = require("fschauen.util.icons") local ui = icons.ui -local orange = '#d65d0e' -local bright = '#ffffff' -- alternative: '#f9f5d7' +local orange = "#d65d0e" +local bright = "#ffffff" -- alternative: '#f9f5d7' -M.dependencies = 'nvim-tree/nvim-web-devicons' +M.dependencies = "nvim-tree/nvim-web-devicons" -M.config = function(--[[plugin]]_, --[[opts]]_) - local window = require 'fschauen.window' +M.config = function() + local window = require("fschauen.window") local filename = (function() - local C = require('lualine.component'):extend() + local C = require("lualine.component"):extend() function C:init(options) C.super.init(self, options) local color = options.color or {} - local modified = { gui = 'italic' } + local modified = { gui = "italic" } - self.custom_highlights = { -- [is_focused, modified] + self.custom_highlights = { -- [is_focused, modified] [true] = { - [true] = self:create_hl(vim.tbl_extend('force', color, modified), 'focus_modified'), - [false] = self:create_hl(color, 'focus'), + [true] = self:create_hl( + vim.tbl_extend("force", color, modified), + "focus_modified" + ), + [false] = self:create_hl(color, "focus"), }, [false] = { - [true] = self:create_hl(modified, 'nofocus_modified'), - [false] = self:create_hl({}, 'nofocus'), + [true] = self:create_hl(modified, "nofocus_modified"), + [false] = self:create_hl({}, "nofocus"), }, } end @@ -35,14 +38,14 @@ M.config = function(--[[plugin]]_, --[[opts]]_) function C:update_status(is_focused) self.options.color_highlight = self.custom_highlights[is_focused][vim.bo.modified] - local path = vim.fn.expand('%:~:.') + local path = vim.fn.expand("%:~:.") if window.is_wide() then return path elseif window.is_medium() then - return vim.fn.pathshorten(path) -- only first letter of directories + return vim.fn.pathshorten(path) -- only first letter of directories else - return vim.fn.fnamemodify(path, ':t') -- only tail + return vim.fn.fnamemodify(path, ":t") -- only tail end end @@ -50,68 +53,69 @@ M.config = function(--[[plugin]]_, --[[opts]]_) end)() local mode = (function() - local C = require('lualine.component'):extend() + local C = require("lualine.component"):extend() C.map = { - ['n'] = icons.modes.Normal, -- 'Normal ', -- Normal - ['no'] = icons.modes.OperatorPending, -- 'O-Pend ', -- Operator-pending - ['ni'] = icons.modes.NormalI, -- 'Normal ', -- Normal via i_CTRL-O - ['v'] = icons.modes.Visual, -- 'Visual ', -- Visual by character - [''] = icons.modes.VisualBlock, -- 'V-Block', -- Visual blockwise - ['s'] = icons.modes.Select, -- 'Select ', -- Select by character - [''] = icons.modes.SelectBlock, -- 'S-Block', -- Select blockwise - ['i'] = icons.modes.Insert, -- 'Insert ', -- Insert - ['r'] = icons.modes.Replace, -- 'Replace', -- Replace - ['rv'] = icons.modes.VirtualReplace, -- 'V-Repl ', -- Virtual Replace - ['c'] = icons.modes.Command, -- 'Command', -- Command-line - ['cv'] = icons.modes.Ex, -- ' Ex ', -- Ex mode - ['rm'] = icons.modes.modeore, -- ' modeore ', -- -- modeORE -- - ['r?'] = icons.modes.Cofirm, -- 'Confirm', -- :confirm - ['!'] = icons.modes.Shell, -- ' Shell ', -- External command executing - ['t'] = icons.modes.Term, -- ' Term ', -- Terminal + ["n"] = icons.modes.Normal, -- 'Normal ', -- Normal + ["no"] = icons.modes.OperatorPending, -- 'O-Pend ', -- Operator-pending + ["ni"] = icons.modes.NormalI, -- 'Normal ', -- Normal via i_CTRL-O + ["v"] = icons.modes.Visual, -- 'Visual ', -- Visual by character + [""] = icons.modes.VisualBlock, -- 'V-Block', -- Visual blockwise + ["s"] = icons.modes.Select, -- 'Select ', -- Select by character + [""] = icons.modes.SelectBlock, -- 'S-Block', -- Select blockwise + ["i"] = icons.modes.Insert, -- 'Insert ', -- Insert + ["r"] = icons.modes.Replace, -- 'Replace', -- Replace + ["rv"] = icons.modes.VirtualReplace, -- 'V-Repl ', -- Virtual Replace + ["c"] = icons.modes.Command, -- 'Command', -- Command-line + ["cv"] = icons.modes.Ex, -- ' Ex ', -- Ex mode + ["rm"] = icons.modes.modeore, -- ' modeore ', -- -- modeORE -- + ["r?"] = icons.modes.Cofirm, -- 'Confirm', -- :confirm + ["!"] = icons.modes.Shell, -- ' Shell ', -- External command executing + ["t"] = icons.modes.Term, -- ' Term ', -- Terminal } function C:update_status(is_focused) - if not is_focused then return ' ' .. ui.Sleep end + if not is_focused then return " " .. ui.Sleep end local code = vim.api.nvim_get_mode().mode:lower() local symbol = C.map[code:sub(1, 2)] or C.map[code:sub(1, 1)] or code - return ' ' .. symbol .. ' ' + return " " .. symbol .. " " end return C end)() local searchcount = (function() - local C = require('lualine.component'):extend() + local C = require("lualine.component"):extend() function C:init(options) C.super.init(self, options) - self.options = vim.tbl_extend('keep', self.options or {}, { + self.options = vim.tbl_extend("keep", self.options or {}, { maxcount = 999, timeout = 250, }) end function C:update_status() - if vim.v.hlsearch == 0 then return '' end + if vim.v.hlsearch == 0 then return "" end local count = vim.fn.searchcount { maxcount = self.options.maxcount, - timeout = self.options.timeout + timeout = self.options.timeout, } - if next(count) == nil then return '' end + if next(count) == nil then return "" end - local denominator = count.total > count.maxcount and '' or string.format('%d', count.total) - return string.format(ui.Search .. '%d/%s', count.current, denominator) + local denominator = count.total > count.maxcount and "" + or string.format("%d", count.total) + return string.format(ui.Search .. "%d/%s", count.current, denominator) end return C end)() local colored_if_focused = function(component) - if type(component) == 'string' then - local C = require('lualine.components.' .. component):extend() + if type(component) == "string" then + local C = require("lualine.components." .. component):extend() function C:update_status(is_focused) self.options.colored = is_focused @@ -119,9 +123,8 @@ M.config = function(--[[plugin]]_, --[[opts]]_) end return C - - elseif type(component) == 'function' then - local C = require('lualine.component'):extend() + elseif type(component) == "function" then + local C = require("lualine.component"):extend() function C:init(options) C.super.init(self, options) @@ -140,35 +143,33 @@ M.config = function(--[[plugin]]_, --[[opts]]_) local trailing_whitespace = { colored_if_focused(function() local trailing = [[\s\+$]] - local lineno = vim.fn.search(trailing, 'nwc') - if lineno == 0 then return '' end + local lineno = vim.fn.search(trailing, "nwc") + if lineno == 0 then return "" end local result = ui.Attention .. lineno local total = vim.fn.searchcount({ pattern = trailing }).total - if total > 1 then result = result .. string.format(' (%d total)', total) end + if total > 1 then result = result .. string.format(" (%d total)", total) end return result end), color = { bg = orange }, - cond = function() - return vim.bo.filetype ~= 'help' - end, + cond = function() return vim.bo.filetype ~= "help" end, } local paste = { - colored_if_focused(function(has_focus) return has_focus and ui.Paste or ' ' end), + colored_if_focused(function(has_focus) return has_focus and ui.Paste or " " end), color = { bg = orange, }, - cond = function() return vim.o.paste end + cond = function() return vim.o.paste end, } local status = { colored_if_focused(function(_) - local status = '' + local status = "" if vim.bo.modified then status = status .. ui.Modified end if vim.bo.readonly or not vim.bo.modifiable then status = status .. ui.ReadOnly end return status @@ -181,51 +182,51 @@ M.config = function(--[[plugin]]_, --[[opts]]_) local sections = { lualine_a = { paste, - mode + mode, }, lualine_b = { - { 'branch', icon = icons.git.Branch, cond = window.is_medium }, + { "branch", icon = icons.git.Branch, cond = window.is_medium }, }, lualine_c = { filename, status, }, lualine_x = { - colored_if_focused('diagnostics'), + colored_if_focused("diagnostics"), searchcount, - { colored_if_focused('filetype'), cond = window.is_medium }, + { colored_if_focused("filetype"), cond = window.is_medium }, }, lualine_y = { - { 'fileformat', cond = window.is_medium }, - 'progress', + { "fileformat", cond = window.is_medium }, + "progress", }, lualine_z = { - 'location', + "location", trailing_whitespace, }, } - require('lualine').setup { + require("lualine").setup { options = { icons_enabled = true, component_separators = { - left = '', - right = '' + left = "", + right = "", }, section_separators = { - left = '', - right = '' + left = "", + right = "", }, }, sections = sections, inactive_sections = sections, extensions = { - 'fugitive', - 'quickfix', - 'nvim-tree', - 'lazy', - 'man', - 'trouble', + "fugitive", + "quickfix", + "nvim-tree", + "lazy", + "man", + "trouble", }, } end diff --git a/config/nvim/lua/fschauen/plugins/markdown-preview.lua b/config/nvim/lua/fschauen/plugins/markdown-preview.lua index ff4a96a..1b043f7 100644 --- a/config/nvim/lua/fschauen/plugins/markdown-preview.lua +++ b/config/nvim/lua/fschauen/plugins/markdown-preview.lua @@ -1,9 +1,7 @@ return { "iamcco/markdown-preview.nvim", - build = function() - vim.fn["mkdp#util#install"]() - end, + build = function() vim.fn["mkdp#util#install"]() end, cmd = { "MarkdownPreview", diff --git a/config/nvim/lua/fschauen/plugins/nvim-lint.lua b/config/nvim/lua/fschauen/plugins/nvim-lint.lua index a14409c..2b06859 100644 --- a/config/nvim/lua/fschauen/plugins/nvim-lint.lua +++ b/config/nvim/lua/fschauen/plugins/nvim-lint.lua @@ -6,9 +6,7 @@ return { keys = { { "L", - function() - require("lint").try_lint() - end, + function() require("lint").try_lint() end, desc = icon .. " [L]int file", }, }, diff --git a/config/nvim/lua/fschauen/plugins/nvim-notify.lua b/config/nvim/lua/fschauen/plugins/nvim-notify.lua index e7065cd..3a44228 100644 --- a/config/nvim/lua/fschauen/plugins/nvim-notify.lua +++ b/config/nvim/lua/fschauen/plugins/nvim-notify.lua @@ -15,9 +15,7 @@ local telescope_notifications = function() telescope.load_extension("notify").notify(theme) end -local dismiss_notifications = function() - require("notify").dismiss() -end +local dismiss_notifications = function() require("notify").dismiss() end return { "rcarriga/nvim-notify", diff --git a/config/nvim/lua/fschauen/plugins/openbrowser.lua b/config/nvim/lua/fschauen/plugins/openbrowser.lua index 396b9f2..573fcf8 100644 --- a/config/nvim/lua/fschauen/plugins/openbrowser.lua +++ b/config/nvim/lua/fschauen/plugins/openbrowser.lua @@ -18,7 +18,5 @@ return { }, }, - init = function() - vim.g.openbrowser_default_search = "duckduckgo" - end, + init = function() vim.g.openbrowser_default_search = "duckduckgo" end, } diff --git a/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua b/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua index dbd612c..9bbfdf4 100644 --- a/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua +++ b/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua @@ -7,10 +7,12 @@ return { dependencies = "nvim-telescope/telescope.nvim", keys = { - { lhs("B"), "Telescope file_browser theme=ivy", desc = desc("file [B]rowser") }, + { + lhs("B"), + "Telescope file_browser theme=ivy", + desc = desc("file [B]rowser"), + }, }, - config = function() - require("telescope").load_extension("file_browser") - end, + config = function() require("telescope").load_extension("file_browser") end, } diff --git a/config/nvim/lua/fschauen/plugins/telescope.lua b/config/nvim/lua/fschauen/plugins/telescope.lua index 72d9289..260a8a4 100644 --- a/config/nvim/lua/fschauen/plugins/telescope.lua +++ b/config/nvim/lua/fschauen/plugins/telescope.lua @@ -1,14 +1,10 @@ local ui = require("fschauen.util.icons").ui ---Create the left hand side for a Telescope keymap. -local lhs = function(keys) - return "f" .. keys -end +local lhs = function(keys) return "f" .. keys end ---Create the description for a Telescope keymap. -local desc = function(text) - return ui.Telescope .. " Telescope " .. text -end +local desc = function(text) return ui.Telescope .. " Telescope " .. text end local builtin_picker = function(name, opts) return function(title) @@ -43,9 +39,7 @@ local pickers = setmetatable({ }, { -- Fall back to telescope's built-in pickers if a custom one is not defined -- above, but make sure to keep the title we defined. - __index = function(_, key) - return builtin_picker(key) - end, + __index = function(_, key) return builtin_picker(key) end, }) return { diff --git a/config/nvim/lua/fschauen/plugins/text-case.lua b/config/nvim/lua/fschauen/plugins/text-case.lua index 4ebb23e..c5bab21 100644 --- a/config/nvim/lua/fschauen/plugins/text-case.lua +++ b/config/nvim/lua/fschauen/plugins/text-case.lua @@ -1,9 +1,7 @@ local icon = require("fschauen.util.icons").ui.Text -local description = icon .." [c]hange text [c]ase" +local description = icon .. " [c]hange text [c]ase" -local theme = function() - return require("telescope.themes").get_cursor() -end +local theme = function() return require("telescope.themes").get_cursor() end return { "johmsalas/text-case.nvim", @@ -20,9 +18,7 @@ return { keys = { { "cc", - function() - require("telescope").extensions.textcase.normal_mode(theme()) - end, + function() require("telescope").extensions.textcase.normal_mode(theme()) end, mode = "n", desc = description, }, diff --git a/config/nvim/lua/fschauen/util/init.lua b/config/nvim/lua/fschauen/util/init.lua index 3112900..87f339d 100644 --- a/config/nvim/lua/fschauen/util/init.lua +++ b/config/nvim/lua/fschauen/util/init.lua @@ -22,9 +22,7 @@ end ---Get selected text. ---@return string: selected text, or word under cursor if not in visual mode. M.get_selected_text = function() - if vim.fn.mode() ~= "v" then - return vim.fn.expand("") - end + if vim.fn.mode() ~= "v" then return vim.fn.expand("") end return M.preserve_register("v", function() vim.cmd([[noautocmd sil norm "vy]]) diff --git a/config/nvim/lua/fschauen/util/lua.lua b/config/nvim/lua/fschauen/util/lua.lua index d191cc7..1d6971a 100644 --- a/config/nvim/lua/fschauen/util/lua.lua +++ b/config/nvim/lua/fschauen/util/lua.lua @@ -12,9 +12,7 @@ local find_module_sources = function(modname) for _, directory in ipairs(vim.opt.runtimepath:get()) do for _, candidate in ipairs(candidates) do local path = directory .. "/" .. candidate - if exists(path) then - table.insert(results, path) - end + if exists(path) then table.insert(results, path) end end end return results @@ -51,9 +49,7 @@ M.go_to_module = function(modname) vim.cmd.edit(sources[1]) else vim.ui.select(sources, { prompt = "Which one?" }, function(choice) - if choice then - vim.cmd.edit(choice) - end + if choice then vim.cmd.edit(choice) end end) end end diff --git a/config/nvim/lua/fschauen/util/options.lua b/config/nvim/lua/fschauen/util/options.lua index 41aca05..8382005 100644 --- a/config/nvim/lua/fschauen/util/options.lua +++ b/config/nvim/lua/fschauen/util/options.lua @@ -27,8 +27,8 @@ end M.set_gitcommit_buffer_options = function() vim.bo.textwidth = 72 - vim.opt.formatoptions:append('t') -- wrap text on 'textwidth' - vim.opt.spell = true -- turn on spell checking + vim.opt.formatoptions:append("t") -- wrap text on 'textwidth' + vim.opt.spell = true -- turn on spell checking end return M diff --git a/config/nvim/lua/fschauen/window.lua b/config/nvim/lua/fschauen/window.lua index d6dfd4c..e78fa67 100644 --- a/config/nvim/lua/fschauen/window.lua +++ b/config/nvim/lua/fschauen/window.lua @@ -3,16 +3,12 @@ local M = {} ---Determine whether the window is wide. ---@param win_nr integer|nil: window number or window-ID, 0 for current window. ---@return boolean -M.is_wide = function(win_nr) - return vim.fn.winwidth(win_nr or 0) > 80 -end +M.is_wide = function(win_nr) return vim.fn.winwidth(win_nr or 0) > 80 end ---Determine whether the window is medium. ---@param win_nr integer|nil: window number or window-ID, 0 for current window. ---@return boolean -M.is_medium = function(win_nr) - return vim.fn.winwidth(win_nr or 0) > 50 -end +M.is_medium = function(win_nr) return vim.fn.winwidth(win_nr or 0) > 50 end ---Whether the current window is the last in a given direction. ---@param direction string: one of 'h', 'j', 'k', or 'l' @@ -22,9 +18,7 @@ local is_last = function(direction) local next = vim.api.nvim_get_current_win() local is_last = current == next - if not is_last then - vim.cmd("wincmd p") - end + if not is_last then vim.cmd("wincmd p") end return is_last end @@ -33,17 +27,13 @@ end ---@param dir string: one of 'h', 'j', 'k', or 'l' ---@param size integer: how much to resize local resize = function(dir, size) - if dir ~= "h" and dir ~= "j" and dir ~= "k" and dir ~= "l" then - return - end + if dir ~= "h" and dir ~= "j" and dir ~= "k" and dir ~= "l" then return end size = math.abs(size) local is_height = dir == "j" or dir == "k" local is_positive = dir == "j" or dir == "l" - if is_last(is_height and "j" or "l") then - is_positive = not is_positive - end + if is_last(is_height and "j" or "l") then is_positive = not is_positive end local delta = string.format("%s%d", is_positive and "+" or "-", size) local prefix = is_height and "" or "vertical " @@ -53,63 +43,45 @@ end ---Resize current window upwards. ---@param size integer: how much to resize M.resize_up = function(size) - return function() - resize("k", size) - end + return function() resize("k", size) end end ---Resize current window downwards. ---@param size integer: how much to resize M.resize_down = function(size) - return function() - resize("j", size) - end + return function() resize("j", size) end end ---Resize current window leftwards. ---@param size integer: how much to resize M.resize_left = function(size) - return function() - resize("h", size) - end + return function() resize("h", size) end end ---Resize current window rightwards. ---@param size integer: how much to resize M.resize_right = function(size) - return function() - resize("l", size) - end + return function() resize("l", size) end end ---Toggle quickfix (or location) list. ---@param qf string: 'c' for quickfix, 'l' for location list local toggle_list = function(qf) local l = qf == "l" and 1 or 0 - local is_qf = function(win) - return win.quickfix == 1 and win.loclist == l - end + local is_qf = function(win) return win.quickfix == 1 and win.loclist == l end local is_open = not vim.tbl_isempty(vim.tbl_filter(is_qf, vim.fn.getwininfo())) if is_open then vim.cmd(qf .. "close") else - local ok = pcall(function(c) - vim.cmd(c) - end, qf .. "open") - if not ok and qf == "l" then - vim.notify("No location list", vim.log.levels.WARN) - end + local ok = pcall(function(c) vim.cmd(c) end, qf .. "open") + if not ok and qf == "l" then vim.notify("No location list", vim.log.levels.WARN) end end end ---Toggle quickfix list. -M.toggle_quickfix = function() - toggle_list("c") -end +M.toggle_quickfix = function() toggle_list("c") end ---Toggle location list. -M.toggle_loclist = function() - toggle_list("l") -end +M.toggle_loclist = function() toggle_list("l") end return M diff --git a/config/nvim/stylua.toml b/config/nvim/stylua.toml index 02cb825..529fbb3 100644 --- a/config/nvim/stylua.toml +++ b/config/nvim/stylua.toml @@ -1,6 +1,7 @@ -column_width = 100 +column_width = 90 +line_endings = "Unix" indent_type = "Spaces" indent_width = 2 quote_style = "AutoPreferDouble" call_parentheses = "NoSingleTable" -collapse_simple_statement = "Never" +collapse_simple_statement = "Always"