From e0624ab63d5504dc42fbaed9f48158b86295d21f Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 19 Jan 2023 18:33:43 +0100 Subject: vim: format config with stylua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .vim/.editorconfig | 11 ++++ .vim/.stylua.toml | 6 +++ .vim/after/ftplugin/dirbuf.lua | 1 + .vim/lua/internal/lsp_symbols.lua | 36 +++++++++++++ .vim/lua/internal/notify.lua | 105 ++++++++++++++++++++++++++++++++++++++ .vim/snippets/sh.lua | 39 ++++++++++++++ .vim/snippets/text.lua | 26 ++++++++++ 7 files changed, 224 insertions(+) create mode 100644 .vim/.editorconfig create mode 100644 .vim/.stylua.toml create mode 100644 .vim/after/ftplugin/dirbuf.lua create mode 100644 .vim/lua/internal/lsp_symbols.lua create mode 100644 .vim/lua/internal/notify.lua create mode 100644 .vim/snippets/sh.lua create mode 100644 .vim/snippets/text.lua (limited to '.vim') diff --git a/.vim/.editorconfig b/.vim/.editorconfig new file mode 100644 index 0000000..c0b69e9 --- /dev/null +++ b/.vim/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +tab_width = 8 +end_of_line = lf +insert_final_newline = true + +[*.lua] +max_line_length = 100 diff --git a/.vim/.stylua.toml b/.vim/.stylua.toml new file mode 100644 index 0000000..616d360 --- /dev/null +++ b/.vim/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 100 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +#call_parentheses = "Always" diff --git a/.vim/after/ftplugin/dirbuf.lua b/.vim/after/ftplugin/dirbuf.lua new file mode 100644 index 0000000..109e3a4 --- /dev/null +++ b/.vim/after/ftplugin/dirbuf.lua @@ -0,0 +1 @@ +vim.opt_local.list = false diff --git a/.vim/lua/internal/lsp_symbols.lua b/.vim/lua/internal/lsp_symbols.lua new file mode 100644 index 0000000..ce8b1a7 --- /dev/null +++ b/.vim/lua/internal/lsp_symbols.lua @@ -0,0 +1,36 @@ +return { + -- 󰆼 󱆃 + Array = '󰨾 ', + Boolean = '󰦍 ', + Class = '󰙀 ', + Color = '󰉦 ', + Constant = ' ', + Constructor = '󱇿 ', + Enum = ' ', + EnumMember = ' ', + Event = '󱐋 ', + -- Field = '󰽜 ', + Field = '󰆈 ', + File = '󰈔 ', + Folder = '󰝰 ', + Function = ' ', + Interface = '󱦜 ', + Key = '󰌋 ', + Keyword = '󰓽 ', + Method = '󰒓 ', + Module = '󰏖 ', + Namespace = '󰆧 ', + Null = '󰎣 ', + Object = '󰘦 ', + Operator = '󱓉 ', + Property = '󰐱 ', + Package = '󰏗 ', + Reference = '󰌹 ', + Snippet = '󰯁 ', + Struct = '󰙅 ', + Text = '󰉿 ', + TypeParameter = '󰌨 ', + Unit = '󰠱 ', + Value = '󰎠 ', + Variable = '󱄑 ', +} diff --git a/.vim/lua/internal/notify.lua b/.vim/lua/internal/notify.lua new file mode 100644 index 0000000..5445f4f --- /dev/null +++ b/.vim/lua/internal/notify.lua @@ -0,0 +1,105 @@ +-- notifications cache +_G.statusline_notifications = {} +_G.statusline_notifications_archive = {} + +-- out vim.notify implementation +local notify = function(m, l, o) + local lvl_string = l + local hi = nil + if l and type(l) == 'number' then + if l == vim.log.levels.TRACE then + hi = 'deEmph' + elseif l == vim.log.levels.DEBUG then + hi = 'DiagnosticHint' + elseif l == vim.log.levels.INFO then + hi = 'DiagnosticInfo' + elseif l == vim.log.levels.WARN then + hi = 'DiagnosticWarn' + elseif l == vim.log.levels.ERROR then + hi = 'DiagnosticError' + end + -- get level string + lvl_string = vim.lsp.log_levels[l] + end + local display = m + if lvl_string then + display = lvl_string .. ' ' .. display + end + table.insert(_G.statusline_notifications, { + message = m, + level = l, + options = o, + lvl_string = lvl_string, + hi = hi, + display = display, + }) + + if _G.statusline_enable_notifysend then + local args = {} + if lvl_string then + if lvl_string == 'ERROR' then + table.insert(args, '--category=error') + end + if lvl_string == 'WARN' then + table.insert(args, '--category=warning') + end + end + table.insert(args, 'nvim') + table.insert(args, display) + require('internal.job').jobstart({ command = 'notify-send', args = args }) + end +end + +-- overwrite vim.notify +vim.notify = function(m, l, o) + if vim.in_fast_event() then + vim.schedule(function() + notify(m, l, o) + end) + else + return notify(m, l, o) + end +end + +vim.keymap.set('n', 'n', function() + local pickers = require('telescope.pickers') + local finders = require('telescope.finders') + local conf = require('telescope.config').values + local actions = require('telescope.actions') + -- local action_state = require('telescope.actions.state') + -- local previewers = require('telescope.previewers') + + local opts = {} + pickers + .new(opts, { + prompt_title = 'Notifications', + finder = finders.new_dynamic({ + fn = function() + return _G.statusline_notifications_archive + end, + entry_maker = function(n) + return { + value = n, + display = n.display, + ordinal = n.message, + } + end, + }), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr, _) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + -- noop + -- local sel = action_state.get_selected_entry() + -- vim.notify(sel.value.message, sel.value.level, sel.value.options) + end) + return true + end, + -- previewer = previewers.new_buffer_previewer { + -- define_preview = function(self, entry) + -- vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, {entry.value.display}) + -- end, + -- }, + }) + :find() +end, { desc = 'notifications' }) diff --git a/.vim/snippets/sh.lua b/.vim/snippets/sh.lua new file mode 100644 index 0000000..e8ba23b --- /dev/null +++ b/.vim/snippets/sh.lua @@ -0,0 +1,39 @@ +---@diagnostic disable: undefined-global +return { + s( + { trig = 'getopts', desc = 'getopts skeleton' }, + fmt( + [=[ + while getopts h{} opt; do + case ${{opt}} in + h | ?) + printf "usage: %s [-h]\n" "$(basename "$0")" + printf "\n" + exit 2 + ;; + esac + done + shift $((OPTIND - 1)) + ]=], + { i(1) } + ) + ), + + s( + { trig = 'usage' }, + fmt( + [=[ + usage() {{ + printf "usage: %s{}" "$(basename "$0")\n" + printf "\n" + {} + printf "\n" + }} + ]=], + { + i(1, ' []'), + i(2, 'printf " -{}\n"'), + } + ) + ), +} diff --git a/.vim/snippets/text.lua b/.vim/snippets/text.lua new file mode 100644 index 0000000..9fca88f --- /dev/null +++ b/.vim/snippets/text.lua @@ -0,0 +1,26 @@ +---@diagnostic disable: undefined-global +return { + s('test', t('test inserted')), + -- licenses (full-text) + s( + { trig = 'license-mit', name = 'MIT license' }, + file_contents(vim.fn.stdpath('config') .. '/snippets/.licenses/mit', { + year = f(function() + return os.date('%Y') + end, {}), + copyright = sn(1, user_email), + }) + ), + s( + { trig = 'license-gpl-3.0', name = 'GPL-3.0 license' }, + file_contents(vim.fn.stdpath('config') .. '/snippets/.licenses/gpl-3.0', {}) + ), + s( + { trig = 'license-agpl-3.0', name = 'AGPL-3.0 license' }, + file_contents(vim.fn.stdpath('config') .. '/snippets/.licenses/agpl-3.0', {}) + ), + s( + { trig = 'license-cc0-1.0', name = 'CC-Zero-1.0 license' }, + file_contents(vim.fn.stdpath('config') .. '/snippets/.licenses/cc0-1.0', {}) + ), +} -- cgit 1.4.1