From 2dc8a5a61cd1e8aa52147f22f2691f258474d094 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Sat, 14 Oct 2023 19:49:26 +1100 Subject: [PATCH] Consistently tab-indent Vimscript --- .editorconfig | 6 + .../autoload/crystalline/theme/gruvbox8.vim | 114 ++++---- config/vim/init.vim | 36 +-- config/vim/lsp.vim | 246 +++++++++--------- config/vim/plugins.vim | 22 +- vimrc | 16 +- 6 files changed, 223 insertions(+), 217 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6453fa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = tab diff --git a/config/vim/autoload/crystalline/theme/gruvbox8.vim b/config/vim/autoload/crystalline/theme/gruvbox8.vim index ea78a90..624e772 100644 --- a/config/vim/autoload/crystalline/theme/gruvbox8.vim +++ b/config/vim/autoload/crystalline/theme/gruvbox8.vim @@ -1,87 +1,87 @@ vim9script const dark = { - bg0: ['#282828', 235], - bg1: ['#3c3836', 237], - bg2: ['#504945', 239], - bg4: ['#7c6f64', 243], + bg0: ['#282828', 235], + bg1: ['#3c3836', 237], + bg2: ['#504945', 239], + bg4: ['#7c6f64', 243], - fg1: ['#ebdbb2', 187], - fg4: ['#a89984', 137], + fg1: ['#ebdbb2', 187], + fg4: ['#a89984', 137], - green: ['#98971a', 100], - yellow: ['#d79921', 172], - blue: ['#458588', 66], - aqua: ['#689d6a', 71], - orange: ['#d65d0e', 166], - red: ['#fb4934', 203], + green: ['#98971a', 100], + yellow: ['#d79921', 172], + blue: ['#458588', 66], + aqua: ['#689d6a', 71], + orange: ['#d65d0e', 166], + red: ['#fb4934', 203], } const light = { - bg0: ['#fbf1c7', 230], - bg1: ['#ebdbb2', 187], - bg2: ['#d5c4a1', 187], - bg4: ['#a89984', 137], + bg0: ['#fbf1c7', 230], + bg1: ['#ebdbb2', 187], + bg2: ['#d5c4a1', 187], + bg4: ['#a89984', 137], - fg1: ['#3c3836', 237], - fg4: ['#7c6f64', 243], + fg1: ['#3c3836', 237], + fg4: ['#7c6f64', 243], - green: ['#98971a', 100], - yellow: ['#d79921', 172], - blue: ['#458588', 66], - aqua: ['#689d6a', 71], - orange: ['#d65d0e', 166], - red: ['#9d0006', 124], + green: ['#98971a', 100], + yellow: ['#d79921', 172], + blue: ['#458588', 66], + aqua: ['#689d6a', 71], + orange: ['#d65d0e', 166], + red: ['#9d0006', 124], } def ToCrystalline(fg: list, bg: list): list - return [ - [fg[1], bg[1]], - [fg[0], bg[0]], - '' - ] + return [ + [fg[1], bg[1]], + [fg[0], bg[0]], + '' + ] enddef def MakeTheme(c: dict>): dict> - var theme = { - A: ToCrystalline(c.bg0, c.bg4), - B: ToCrystalline(c.fg4, c.bg2), - Fill: ToCrystalline(c.fg4, c.bg1), + var theme = { + A: ToCrystalline(c.bg0, c.bg4), + B: ToCrystalline(c.fg4, c.bg2), + Fill: ToCrystalline(c.fg4, c.bg1), - InactiveA: ToCrystalline(c.bg4, c.bg1), - InactiveB: ToCrystalline(c.bg4, c.bg1), - InactiveFill: ToCrystalline(c.bg4, c.bg1), + InactiveA: ToCrystalline(c.bg4, c.bg1), + InactiveB: ToCrystalline(c.bg4, c.bg1), + InactiveFill: ToCrystalline(c.bg4, c.bg1), - InsertModeA: ToCrystalline(c.bg0, c.blue), - InsertModeFill: ToCrystalline(c.fg4, c.bg2), + InsertModeA: ToCrystalline(c.bg0, c.blue), + InsertModeFill: ToCrystalline(c.fg4, c.bg2), - VisualModeA: ToCrystalline(c.bg0, c.orange), - ReplaceModeA: ToCrystalline(c.bg0, c.aqua), - ReplaceModeFill: ToCrystalline(c.fg4, c.bg2), - TerminalModeA: ToCrystalline(c.bg0, c.green), + VisualModeA: ToCrystalline(c.bg0, c.orange), + ReplaceModeA: ToCrystalline(c.bg0, c.aqua), + ReplaceModeFill: ToCrystalline(c.fg4, c.bg2), + TerminalModeA: ToCrystalline(c.bg0, c.green), - Modified: ToCrystalline(c.red, c.bg1), - InsertModeModified: ToCrystalline(c.red, c.bg2), + Modified: ToCrystalline(c.red, c.bg1), + InsertModeModified: ToCrystalline(c.red, c.bg2), - TabSel: ToCrystalline(c.bg0, c.fg4), - ModifiedSel: ToCrystalline(c.bg1, c.fg4), - } + TabSel: ToCrystalline(c.bg0, c.fg4), + ModifiedSel: ToCrystalline(c.bg1, c.fg4), + } - theme->extend({ - Tab: theme.Fill, - NormalModeModified: theme.Modified, - CommandModeModified: theme.Modified, - VisualModeModified: theme.Modified, - ReplaceModeModified: theme.InsertModeModified, - }) + theme->extend({ + Tab: theme.Fill, + NormalModeModified: theme.Modified, + CommandModeModified: theme.Modified, + VisualModeModified: theme.Modified, + ReplaceModeModified: theme.InsertModeModified, + }) - return theme + return theme enddef export def GetThemeColours(): dict> - return &background ==# 'dark' ? dark : light + return &background ==# 'dark' ? dark : light enddef export def SetTheme(): void - GetThemeColours()->MakeTheme()->g:crystalline#GenerateTheme() + GetThemeColours()->MakeTheme()->g:crystalline#GenerateTheme() enddef diff --git a/config/vim/init.vim b/config/vim/init.vim index b7f3fc9..efd874e 100644 --- a/config/vim/init.vim +++ b/config/vim/init.vim @@ -9,21 +9,21 @@ enddef # These are really clever - minpac will actually be loaded on the fly only # when you need to update or clean your packages, rather than all the time. command! PackUpdate source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#update() -command! PackClean source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#clean() +command! PackClean source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#clean() command! PackStatus source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#status() # If the pack directory doesn't exist, we haven't installed any packages yet, # so let's call PackUpdate. if !isdirectory($XDG_CACHE_HOME .. '/vim/pack') - PackUpdate + PackUpdate endif if has('gui_running') || has('termguicolors') - if $COLORTERM == 'truecolor' - &t_8f = "\[38:2:%lu:%lu:%lum" - &t_8b = "\[48:2:%lu:%lu:%lum" - endif - set termguicolors + if $COLORTERM == 'truecolor' + &t_8f = "\[38:2:%lu:%lu:%lum" + &t_8b = "\[48:2:%lu:%lu:%lum" + endif + set termguicolors endif set background=dark @@ -39,7 +39,7 @@ nnoremap :Files packadd! editorconfig if exists('+belloff') - set belloff+=ctrlg + set belloff+=ctrlg endif set completeopt+=menuone @@ -49,30 +49,30 @@ set modelines=5 set showcmd set wildmode=longest,full if has('patch-8.2.4325') - set wildoptions+=pum + set wildoptions+=pum endif set tabstop=2 shiftwidth=2 if exists('+breakindent') - set breakindent breakindentopt=sbr + set breakindent breakindentopt=sbr endif if exists('+relativenumber') - set relativenumber + set relativenumber else - set number + set number endif for dir_name in ['backup', 'swap', 'undo'] - EnsureDir($XDG_STATE_HOME .. '/vim/' .. dir_name) + EnsureDir($XDG_STATE_HOME .. '/vim/' .. dir_name) endfor set backupdir=.,$XDG_STATE_HOME/vim/backup set directory=.,$XDG_STATE_HOME/vim/swap if exists('+undofile') - set undofile - set undodir=$XDG_STATE_HOME/vim/undo + set undofile + set undodir=$XDG_STATE_HOME/vim/undo endif g:csv_no_conceal = 1 @@ -87,9 +87,9 @@ nmap (ale_previous_wrap) nmap (ale_next_wrap) g:mucomplete#can_complete = { - default: { - omni: (t) => strlen(&l:omnifunc) > 0 && t =~# '\m\k\%(\k\|\.\)$' - } + default: { + omni: (t) => strlen(&l:omnifunc) > 0 && t =~# '\m\k\%(\k\|\.\)$' + } } import "./statusline.vim" diff --git a/config/vim/lsp.vim b/config/vim/lsp.vim index 644379f..fe37cb2 100644 --- a/config/vim/lsp.vim +++ b/config/vim/lsp.vim @@ -1,161 +1,161 @@ vim9script const lspServers = [ - { - name: 'dockerfile-langserver', - filetype: 'dockerfile', - path: expand('~/.local/bin/docker-langserver'), - args: ['--stdio'], - install: 'npm install -g dockerfile-language-server-nodejs', - }, + { + name: 'dockerfile-langserver', + filetype: 'dockerfile', + path: expand('~/.local/bin/docker-langserver'), + args: ['--stdio'], + install: 'npm install -g dockerfile-language-server-nodejs', + }, - { - name: 'lua-language-server', - filetype: 'lua', - path: '/usr/local/bin/lua-language-server', - args: [], - install: 'brew install lua-language-server', - }, + { + name: 'lua-language-server', + filetype: 'lua', + path: '/usr/local/bin/lua-language-server', + args: [], + install: 'brew install lua-language-server', + }, - { - name: 'taplo', - filetype: 'toml', - path: '/usr/local/bin/taplo', - args: ['lsp', 'stdio'], - install: 'brew install taplo', - }, + { + name: 'taplo', + filetype: 'toml', + path: '/usr/local/bin/taplo', + args: ['lsp', 'stdio'], + install: 'brew install taplo', + }, - { - name: 'tilt-lsp', - filetype: 'bzl', - path: '/usr/local/bin/tilt', - args: ['lsp', 'start'], - install: 'brew install tilt', - }, + { + name: 'tilt-lsp', + filetype: 'bzl', + path: '/usr/local/bin/tilt', + args: ['lsp', 'start'], + install: 'brew install tilt', + }, - { - name: 'typescript-language-server', - filetype: ['javascript', 'typescript'], - path: '/usr/local/bin/typescript-language-server', - args: ['--stdio'], - install: 'brew install typescript-language-server', - }, + { + name: 'typescript-language-server', + filetype: ['javascript', 'typescript'], + path: '/usr/local/bin/typescript-language-server', + args: ['--stdio'], + install: 'brew install typescript-language-server', + }, - { - name: 'phpactor', - filetype: 'php', - path: expand('~/bin/phpactor'), - args: ['language-server'], - initializationOptions: { - 'language_server_configuration.auto_config': false, - }, - install: 'curl -Lo phpactor https://github.com/phpactor/phpactor/releases/latest/download/phpactor.phar && chmod u+x phpactor && mv phpactor ~/bin', - }, + { + name: 'phpactor', + filetype: 'php', + path: expand('~/bin/phpactor'), + args: ['language-server'], + initializationOptions: { + 'language_server_configuration.auto_config': false, + }, + install: 'curl -Lo phpactor https://github.com/phpactor/phpactor/releases/latest/download/phpactor.phar && chmod u+x phpactor && mv phpactor ~/bin', + }, - { - name: 'pylsp', - filetype: 'python', - path: '/usr/local/bin/pylsp', - args: [], - install: 'brew install python-lsp-server', - }, + { + name: 'pylsp', + filetype: 'python', + path: '/usr/local/bin/pylsp', + args: [], + install: 'brew install python-lsp-server', + }, - { - name: 'solargraph', - filetype: 'ruby', - path: '/usr/local/bin/solargraph', - args: ['stdio'], - install: 'brew install solargraph', - }, + { + name: 'solargraph', + filetype: 'ruby', + path: '/usr/local/bin/solargraph', + args: ['stdio'], + install: 'brew install solargraph', + }, - { - name: 'vim-language-server', - filetype: 'vim', - path: expand('~/.local/bin/vim-language-server'), - args: ['--stdio'], - install: 'npm install -g vim-language-server', - }, + { + name: 'vim-language-server', + filetype: 'vim', + path: expand('~/.local/bin/vim-language-server'), + args: ['--stdio'], + install: 'npm install -g vim-language-server', + }, - { - name: 'vscode-json-language-server', - filetype: ['json', 'jsonc'], - path: expand('~/.local/bin/vscode-json-language-server'), - args: ['--stdio'], - workspaceConfig: {json: { - format: {enable: true}, + { + name: 'vscode-json-language-server', + filetype: ['json', 'jsonc'], + path: expand('~/.local/bin/vscode-json-language-server'), + args: ['--stdio'], + workspaceConfig: {json: { + format: {enable: true}, validate: {enable: true}, - schemas: g:SchemaStore#Schemata(), - }}, - install: 'npm install -g vscode-langservers-extracted', - }, + schemas: g:SchemaStore#Schemata(), + }}, + install: 'npm install -g vscode-langservers-extracted', + }, - { - name: 'yaml-language-server', - filetype: 'yaml', - path: expand('~/.local/bin/yaml-language-server'), - args: ['--stdio'], - workspaceConfig: {yaml: { - format: {enable: true, singleQuote: true}, - schemaStore: {enable: true, url: 'https://www.schemastore.org/api/json/catalog.json'}, - }}, - install: 'npm install -g yaml-language-server', - }, + { + name: 'yaml-language-server', + filetype: 'yaml', + path: expand('~/.local/bin/yaml-language-server'), + args: ['--stdio'], + workspaceConfig: {yaml: { + format: {enable: true, singleQuote: true}, + schemaStore: {enable: true, url: 'https://www.schemastore.org/api/json/catalog.json'}, + }}, + install: 'npm install -g yaml-language-server', + }, ] const lspOptions = { - aleSupport: true, - ignoreMissingServer: true, + aleSupport: true, + ignoreMissingServer: true, } command! -nargs=0 -bar LspInstall Install() def InstalledServers(): list> - return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 1) + return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 1) enddef def MissingServers(): list> - return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 0) + return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 0) enddef export def LazyConfigure(): void - autocmd VimEnter * ++once Configure() + autocmd VimEnter * ++once Configure() enddef export def Configure(): void - final installedServers = InstalledServers() - if len(lspServers) != len(installedServers) - echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.' - endif - g:LspAddServer(installedServers) - g:LspOptionsSet(lspOptions) + final installedServers = InstalledServers() + if len(lspServers) != len(installedServers) + echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.' + endif + g:LspAddServer(installedServers) + g:LspOptionsSet(lspOptions) enddef export def Install(): void - const missingServers = MissingServers() - if empty(missingServers) - echo $"All {len(lspServers)} configured language servers are already installed." - return - endif + const missingServers = MissingServers() + if empty(missingServers) + echo $"All {len(lspServers)} configured language servers are already installed." + return + endif - # The installScript runs every missing server's install command, regardless - # of whether any fail in the process. The script's exit status is the number - # of failed installations. - const installScript = "failed=0\n" .. missingServers->copy() - ->map((_, server): string => $"\{ {server.install}; \} || failed=$((failed + 1))") - ->join("\n") .. "\nexit $failed\n" + # The installScript runs every missing server's install command, regardless + # of whether any fail in the process. The script's exit status is the number + # of failed installations. + const installScript = "failed=0\n" .. missingServers->copy() + ->map((_, server): string => $"\{ {server.install}; \} || failed=$((failed + 1))") + ->join("\n") .. "\nexit $failed\n" - const term = term_start('sh', {exit_cb: (job: job, status: number): void => { - # If any installations failed, keep the terminal window open so we can - # troubleshoot. If they all worked fine, close the terminal and reload the - # LSP configuration. - if status == 0 - execute 'bdelete' job->ch_getbufnr('out') - Configure() - endif - }}) + const term = term_start('sh', {exit_cb: (job: job, status: number): void => { + # If any installations failed, keep the terminal window open so we can + # troubleshoot. If they all worked fine, close the terminal and reload the + # LSP configuration. + if status == 0 + execute 'bdelete' job->ch_getbufnr('out') + Configure() + endif + }}) - # We prefer term_sendkeys() over sh -c because that will display each - # command in the terminal as it's being executed, making it easier to - # understand exactly what the install script is doing. - term->term_sendkeys(installScript) + # We prefer term_sendkeys() over sh -c because that will display each + # command in the terminal as it's being executed, making it easier to + # understand exactly what the install script is doing. + term->term_sendkeys(installScript) enddef diff --git a/config/vim/plugins.vim b/config/vim/plugins.vim index 0704d27..ad5c349 100644 --- a/config/vim/plugins.vim +++ b/config/vim/plugins.vim @@ -1,11 +1,11 @@ vim9script silent! packadd minpac if !exists('g:loaded_minpac') - silent !git clone https://github.com/k-takata/minpac.git $XDG_CACHE_HOME/vim/pack/minpac/opt/minpac - augroup minpac { - autocmd! - autocmd VimEnter * call minpac#update() - } + silent !git clone https://github.com/k-takata/minpac.git $XDG_CACHE_HOME/vim/pack/minpac/opt/minpac + augroup minpac { + autocmd! + autocmd VimEnter * call minpac#update() + } endif packadd minpac @@ -17,7 +17,7 @@ minpac#add('prabirshrestha/async.vim') minpac#add('lifepillar/vim-gruvbox8') if !isdirectory($VIMRUNTIME .. '/pack/dist/opt/editorconfig') - minpac#add('editorconfig/editorconfig-vim') + minpac#add('editorconfig/editorconfig-vim') endif minpac#add('direnv/direnv.vim') @@ -74,7 +74,7 @@ minpac#add('fpob/nette.vim') minpac#add('leafOfTree/vim-svelte-plugin') if executable('task') - minpac#add('farseer90718/vim-taskwarrior') + minpac#add('farseer90718/vim-taskwarrior') endif minpac#add('pedrohdz/vim-yaml-folds') @@ -83,8 +83,8 @@ minpac#add('alx741/yesod.vim') minpac#add('pbrisbin/vim-syntax-shakespeare') if has('macunix') - minpac#add('rizzatti/dash.vim') - # We rename this plugin to make sure it loads AFTER vim-polyglot, - # since it won't work properly if it's loaded first. - minpac#add('itspriddle/vim-marked', {name: 'zzvim-marked'}) + minpac#add('rizzatti/dash.vim') + # We rename this plugin to make sure it loads AFTER vim-polyglot, + # since it won't work properly if it's loaded first. + minpac#add('itspriddle/vim-marked', {name: 'zzvim-marked'}) endif diff --git a/vimrc b/vimrc index 7b937a4..80297bc 100644 --- a/vimrc +++ b/vimrc @@ -1,20 +1,20 @@ vim9script const xdg = { - XDG_CONFIG_HOME: '~/.config', - XDG_CACHE_HOME: '~/.cache', - XDG_DATA_HOME: '~/.local/share', - XDG_STATE_HOME: '~/.local/state', + XDG_CONFIG_HOME: '~/.config', + XDG_CACHE_HOME: '~/.cache', + XDG_DATA_HOME: '~/.local/share', + XDG_STATE_HOME: '~/.local/state', } for [key, default] in items(xdg) - if !has_key(environ(), key) - setenv(key, expand(default)) - endif + if !has_key(environ(), key) + setenv(key, expand(default)) + endif endfor set runtimepath=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_CONFIG_HOME/vim/after,$XDG_CACHE_HOME/vim/after set viminfo+=n$XDG_STATE_HOME/vim/viminfo if exists('+packpath') - set packpath^=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim + set packpath^=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim endif g:netrw_home = $XDG_CACHE_HOME .. '/vim/netrw'