repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: new function std.prequire

d97451d00a4d754237c71226cb06841fd854a3a6

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

stolen from stevearc's dotfiles.
it is a better version of my previous `std.want` function, which had the same purpose.
thanks to the clever use of a metatable, `prequire` can be used with the same pattern as `require`, even when the modules fails to load.

Changed files (14)

env.nu

Deleted
deleted file mode 100644
1 -# GLOBAL VARIABLES
3 -$env.WIN32 = ( $nu.os-info.name =~ "windows" )
4 -$env.NURC_DIR = ( $nu.config-path | path expand | path dirname )
5 -$env.DOTFILES = ( $env.NURC_DIR | path join ".." | path expand )
6 -$env.WORKSPACE = if $env.WIN32 { "W:/" } else { "~/Workspace" | path expand }
7 -$env.NOTES = if $env.WIN32 { "N:/" } else { "~/Notes" | path expand }
9 -if ($env | get -i TERM_PROGRAM) == WezTerm {
10 - $env.TERM = "wezterm"
11 - if not $env.WIN32 {
12 - $env.TERMCAP = ~./termcap/w/wezterm
13 - }
14 -}
16 -# theme for ls and other programs, that use LS_COLORS
17 -$env.LS_COLORS = (try { vivid generate alabaster_dark | into string } catch {""})
19 -# Specifies how environment variables are:
20 -# - converted from a string to a value on Nushell startup (from_string)
21 -# - converted from a value back to a string when running external commands (to_string)
22 -# Note: The conversions happen *after* config.nu is loaded
23 -$env.ENV_CONVERSIONS = {
24 - "PATH": {
25 - from_string: { |s| $s | split row (char esep) }
26 - to_string: { |v| $v | str join (char esep) }
27 - }
28 - "Path": {
29 - from_string: { |s| $s | split row (char esep) }
30 - to_string: { |v| $v | str join (char esep) }
31 - }
32 -}
34 -# Directories to search for scripts when calling source or use
35 -$env.NU_LIB_DIRS = [
36 - ($nu.config-path | path dirname | path join 'modules'),
37 - ($nu.config-path | path dirname | path join 'completions')
38 -]
40 -if $env.WIN32 {
41 - # TODO: insert scoop cargo path here
42 - # $env.CARGO_HOME = ( '~/.cargo' | path expand )
43 - $env.Path = ( $env.Path | prepend '' )
44 -} else {
45 - $env.CARGO_HOME = ( '~/.cargo' | path expand )
46 - $env.PATH = ( $env.PATH | prepend ( $env.CARGO_HOME | path join 'bin') )
47 - $env.PATH = ( $env.PATH | prepend ( '~/.local/bin'| path expand ) )
48 -}

neovim/README.md

Modified
8 8 init.lua
9 9 : main entry point
10 -\
11 10 lua/std
12 11 : standard lib. can only depend on itself and neovim apis.
13 -\
14 12 lua/bugabinga
15 13 : config modules. in aggregation, defines all of the config. can depend on itself, std and plugins.
16 -\
17 14 lua/bugabinga/plugins
18 15 : third party plugins and their config glue integrating it into the config.
19 -\
20 16 colors/nugu
21 17 : color theme
22 -\
23 18 ftplugin
24 19 : file type specific config

neovim/init.lua

Modified
14 14 vim.cmd.colorscheme 'nugu'
16 +---create special global, that serves as a more graceful alternative to `require`
17 +prequire = require 'std.prequire'
16 19 local ok, loaded
18 21 -- set general neovim editor settings
24 27 -- extends default editorconfig options
25 28 ok, loaded = pcall( require, 'bugabinga.editorconfig' )
26 29 if not ok then
27 - vim.print( 'error while loading editorconfg extensions', loaded )
30 + vim.print( 'error while loading editorconfig extensions', loaded )
30 33 -- install plugin manager and declare plugins to use
48 51 -- visualize marks in signcolumn
49 52 ok, loaded = pcall( require, 'bugabinga.mark' )
50 53 if not ok then
51 - vim.print( 'error while loading mark', loaded )
54 +vim.print( 'error while loading mark', loaded )
54 57 -- setup lsp clients

neovim/justfile

Modified
7 7 # Reproduce some neovim issue
8 8 repro:
9 - nvim -u repro.lua
9 + nvim -u repro.lua
11 11 # update nvim plugins
12 12 update:

neovim/lua/bugabinga/lazy.lua

Modified
29 29 defaults = {
30 30 lazy = true,
31 31 -- version = '*',
32 + -- useful to globally disable plugins
33 + -- cond = function ( plugin_spec )
34 + -- return plugin_spec.name:find 'oil'
35 + -- end,
33 37 install = {
34 38 missing = true,

neovim/lua/bugabinga/lsp/clients/lua.lua

Modified
11 11 Lua = {
12 12 addonManager = { enable = false, },
13 13 completion = { callSnippet = 'Replace', },
14 - diagnostics = { globals = { 'vim', }, workspaceRate = 50, },
14 + diagnostics = { globals = { 'vim', 'prequire', }, workspaceRate = 50, },
15 15 hint = { enable = true, setType = true, },
16 16 telemetry = { enable = false, },
17 17 window = { progressBar = true, statusBar = true, },

neovim/lua/bugabinga/options/ui.lua

Modified
8 8 pattern = '*',
9 9 command = function () vim.highlight.on_yank() end,
12 11 auto 'disable_columns_in_special_buffers' {
13 12 description = 'Hide columns in buffers, that do not show source code.',
14 13 events = { 'FileType', },
24 23 -- show trailing whitespace
25 24 vim.opt.list = true
26 25 vim.opt.listchars = {
27 - -- space = icon.space,
28 - -- eol = icon.eol,
26 + space = icon.space,
27 + eol = icon.eol,
29 28 tab = icon.tab .. icon.middle_ellipsis,
30 29 trail = icon.trail,
31 30 extends = icon.extends,
33 32 nbsp = icon.nbsp,
36 --- force english messages
35 +-- force English messages
37 36 vim.cmd [[ language mes en_US.utf8 ]]
39 38 -- do not spam the cmdline with every little input
43 42 -- virtually break lines on border
45 --- always display tme signcolumn to avoid jitter
44 +-- always display the signcolumn to avoid jitter
46 45 vim.opt.signcolumn = 'yes:1'
48 47 -- what is a ruler? me?
77 76 -- truncate messages at end
78 77 vim.opt.shortmess:append 't'
80 --- show cmd window to prevent jitter ui
79 +-- show cmd window to prevent jitter UI
81 80 vim.opt.cmdheight = 1
83 --- do not conceal special characters by default. filestypes can enable this on demand.
82 +-- do not conceal special characters by default. ftplugin can enable this on demand.
84 83 vim.opt.conceallevel = 0
86 85 -- I do not care for folding
104 103 -- hide the mode indicator in status
105 104 vim.opt.showmode = false
107 --- always show tabs, to avoid jitter ui
106 +-- always show tabs, to avoid jitter UI
108 107 vim.opt.showtabline = 2
110 109 local is_tty = os.getenv 'XDG_SESSION_TYPE' == 'tty' and os.getenv 'SSH_TTY' == ''
122 121 vim.opt.smoothscroll = true
124 123 -- cursor
125 --- vim.opt.guicursor = 'n-v-c-sm:block-Cursor,i-ci-ve:ver25-blinkon250,r-cr:hor20,o:hor50'
124 +vim.opt.guicursor = 'n-v-c-sm:block-Cursor,i-ci-ve:ver25-blinkon250,r-cr:hor20,o:hor50'
127 126 -- font
128 127 vim.opt.guifont = 'Cousine,Symbols Nerd Font Mono:#e-subpixelantialias:#h-full'

neovim/lua/bugabinga/plugins/format.lua

Modified
25 25 opts = {
26 26 formatters_by_ft = {
27 27 -- https://github.com/razziel89/mdslw/issues/14
28 - -- markdown = { 'mdslw', },
28 + markdown = { 'mdslw', },
29 29 -- lua = { "stylua" },
30 30 toml = { 'taplo', },
31 31 sh = { 'shfmt', },
40 40 formatters = {
41 41 mdslw = {
42 42 -- remove `:` from the default set of end markers
43 - prepend_args = { '--end-markers', '?!.', },
43 + -- prepend_args = { '--end-markers', '?!.', },
46 46 log_level = debug.get() and vim.log.levels.TRACE or vim.log.levels.INFO,

neovim/lua/bugabinga/plugins/sessions.lua

Modified
11 11 -- Only load the session if nvim was started with no args
12 12 if vim.fn.argc( -1 ) == 0 then
13 13 -- Save these to a different directory, so our manual sessions don't get polluted
14 - require 'resession'.load( vim.fn.getcwd(), { dir = 'autosession', silence_errors = true, } )
14 + prequire 'resession'.load( vim.fn.getcwd(), { dir = 'autosession', silence_errors = true, } )
16 16 end,
19 19 events = 'VimLeavePre',
20 20 description = 'Automatically save sessions for the CWD (tab)',
21 - command = function () require 'resession'.save_tab( vim.fn.getcwd(), { dir = 'autosession', notify = false, } ) end,
21 + command = function () prequire 'resession'.save_tab( vim.fn.getcwd(), { dir = 'autosession', notify = false, } ) end,
24 24 events = 'VimLeavePre',
25 25 description = 'Automatically save last session (all tabs)',
26 - command = function () require 'resession'.save( LAST_SESSION ) end,
26 + command = function () prequire 'resession'.save( LAST_SESSION ) end,
31 31 description = 'Restore last session',
32 32 category = 'history',
33 33 keys = '<leader>sl',
34 - command = function () require 'resession'.load( LAST_SESSION ) end,
34 + command = function () prequire 'resession'.load( LAST_SESSION ) end,
37 37 map.normal {
38 38 description = 'Restore a session',
39 39 category = 'history',
40 40 keys = '<leader>sL',
41 - command = function () require 'resession'.load() end,
41 + command = function () prequire 'resession'.load() end,
44 44 map.normal {
45 45 description = 'Delete session',
46 46 category = 'history',
47 47 keys = '<leader>sd',
48 - command = function () require 'resession'.delete() end,
48 + command = function () prequire 'resession'.delete() end,
51 51 map.normal {
52 52 description = 'Save session (tab)',
53 53 category = 'history',
54 54 keys = '<leader>ss',
55 - command = function () require 'resession'.save_tab() end,
55 + command = function () prequire 'resession'.save_tab() end,
58 58 map.normal {
59 59 description = 'Save session (all tabs)',
60 60 category = 'history',
61 61 keys = '<leader>sS',
62 - command = function () require 'resession'.save() end,
62 + command = function () prequire 'resession'.save() end,
65 65 return {

neovim/lua/bugabinga/ui.lua

Modified
1 -local NuiPopup = require 'nui.popup'
2 -local NuiText = require 'nui.text'
3 -local NuiLine = require 'nui.line'
1 +local NuiPopup = prequire 'nui.popup'
2 +local NuiText = prequire 'nui.text'
3 +local NuiLine = prequire 'nui.line'
5 5 local get_nui_popup = function ()
6 6 local popup = NuiPopup {

neovim/lua/std/prequire.lua

Added
new file mode 100644
1 +---Require one or more modules gracefully.
2 +---Calls `require` in protected mode.
3 +---@example
4 +--- local want = require 'std.want'
5 +--- want 'foo'.setup {}
6 +--- want('foo', 'bar', function(foo, bar)
7 +--- foo.setup{arg = bar}
8 +--- end)
9 +---@see pcall
10 +---@param ... 1 or more module names. The last argument may optionally be a function, consuming all modules
11 +---previously given.
12 +---@return any The first module, when loaded successfully. Otherwise a proxy object, that does nothing when called or
13 +---indexed into. This prevents nil dereferencing errors when using the pattern `require('std.prequire')('this mod does
14 +---not exist').setup()`.
15 +return function(...)
16 + local args = { ... }
17 + local mods = {}
18 + local first_mod
19 + for _, arg in ipairs(args) do
20 + if type(arg) == "function" then
21 + arg(unpack(mods))
22 + break
23 + end
24 + local ok, mod = pcall(require, arg)
25 + if ok then
26 + if not first_mod then
27 + first_mod = mod
28 + end
29 + table.insert(mods, mod)
30 + else
31 + vim.notify_once(string.format("Missing module: %s", arg), vim.log.levels.WARN)
32 + -- Return a proxy item that returns itself, so we can do things like
33 + -- grace("module").setup()
34 + local proxy = {}
35 + setmetatable(proxy, {
36 + __call = function()
37 + return proxy
38 + end,
39 + __index = function()
40 + return proxy
41 + end,
42 + })
43 + return proxy
44 + end
45 + end
46 + return first_mod
47 +end

neovim/neovim.yml

Modified
25 25 any: true
26 26 bit:
27 27 any: true
28 + prequire:
29 + args:
30 + - type: string
31 + - type: function

neovim/spell/nerd.utf-8.add

Modified
34 34 signcolumn
35 35 togglers
36 36 ripgrep
37 +prequire
38 +pcall
39 +args
40 +ipairs
41 +setmetatable
42 +colorscheme
43 +cmdline
44 +treesitter
45 +cmd
46 +popups
47 +neovide
48 +wezterm
49 +fullscreen
50 +checkhealth
51 +pls

neovim/spell/nerd.utf-8.add.spl

Modified

Previous version contains binary or non-UTF-8 data.

Current version contains binary or non-UTF-8 data.