From 8fa79a50297ee5f55e2fadbaeac8bf5a4f42d514 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Thu, 13 Apr 2023 10:17:39 -0400 Subject: [PATCH] dot_profile: added this means we can disable expensive features on weak devices --- src/.config/dot_profile.example | 20 ++++++++ src/.config/nvim/init.vim | 91 ++++++++++++++++++--------------- src/.config/nvim/lua/init.lua | 40 +++++++-------- src/.profile | 7 +++ 4 files changed, 97 insertions(+), 61 deletions(-) create mode 100644 src/.config/dot_profile.example diff --git a/src/.config/dot_profile.example b/src/.config/dot_profile.example new file mode 100644 index 0000000..ca80c9f --- /dev/null +++ b/src/.config/dot_profile.example @@ -0,0 +1,20 @@ +#!/bin/sh +# Profile that enables/disables certain features based on the device +# Everything might need to be restarted for this to take effect. + +## ---------- +## IMPORTANT! +## ---------- +## Copy this to '~/.config/dot_profile'. + +# Profiles +# -------- +# DEFAULT: +# Everything's enabled. Nvim auto-installs plugins on launch. +# SLIM: +# Try to reduce bloat; turn off expensive plugins and eye-candy. +# Run :PlugInstall in Nvim to install plugins. +# MINIMAL: +# Nothing is launched automatically, and no plugins are installed. + +export SYSTEM_PROFILE="DEFAULT" diff --git a/src/.config/nvim/init.vim b/src/.config/nvim/init.vim index f0bb05e..838d6bb 100755 --- a/src/.config/nvim/init.vim +++ b/src/.config/nvim/init.vim @@ -112,54 +112,65 @@ nnoremap W " exit all (akin to ZZ, ZQ) nnoremap ZF :qa +" copy URL under cursor to clipboard bind +:nnoremap uu :let @+ = expand('') + " Plugins " Run PlugInstall if there are missing plugins -" (disabled because it's kind of intense for weak devices) -"autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) - "\| PlugInstall --sync | source $MYVIMRC -"\| endif +if $SYSTEM_PROFILE == "DEFAULT" + autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) + \| PlugInstall --sync | source $MYVIMRC + \| endif +endif +" The rest will not be sourced if the system is on minimal settings. +if $SYSTEM_PROFILE == "MINIMAL" + finish +endif call plug#begin() filetype plugin indent on -Plug 'lervag/vimtex' -let g:vimtex_view_method = 'zathura' -let g:vimtex_compiler_method = 'latexmk' -set conceallevel=0 -let g:tex_conceal='abdmg' -let g:vimtex_view_forward_search_on_start=1 -let g:vimtex_compiler_latexmk = { - \ 'build_dir' : $HOME.'/.cache/latexmk/', - \ 'callback' : 1, - \ 'continuous' : 1, - \ 'executable' : 'latexmk', - \ 'hooks' : [], - \ 'options' : [ - \ '-verbose', - \ '-file-line-error', - \ '-synctex=1', - \ '-interaction=nonstopmode', - \ ], - \} +if $SYSTEM_PROFILE == "DEFAULT" + Plug 'lervag/vimtex' + let g:vimtex_view_method = 'zathura' + let g:vimtex_compiler_method = 'latexmk' + set conceallevel=0 + let g:tex_conceal='abdmg' + let g:vimtex_view_forward_search_on_start=1 + let g:vimtex_compiler_latexmk = { + \ 'build_dir' : $HOME.'/.cache/latexmk/', + \ 'callback' : 1, + \ 'continuous' : 1, + \ 'executable' : 'latexmk', + \ 'hooks' : [], + \ 'options' : [ + \ '-verbose', + \ '-file-line-error', + \ '-synctex=1', + \ '-interaction=nonstopmode', + \ ], + \} -" spellcheck -au BufEnter *.tex set spell spelllang=en_ca + " spellcheck + au BufEnter *.tex set spell spelllang=en_ca -" Autowrite in tex files -" au TextChanged,TextChangedI *.tex silent write + " Autowrite in tex files + " au TextChanged,TextChangedI *.tex silent write +endif -if has('python3') +if has('python3') && ($SYSTEM_PROFILE == "DEFAULT" || $SYSTEM_PROFILE == "SLIM") Plug 'SirVer/ultisnips' let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsJumpBackwardTrigger="" let g:UltiSnipsSnippetDirectories=[$HOME.'/.config/nvim/ultisnips/'] +endif - " my devices without python3 probably don't need these +if $SYSTEM_PROFILE == "DEFAULT" Plug 'neovim/nvim-lspconfig' Plug 'nvim-lua/lsp-status.nvim' @@ -167,9 +178,13 @@ if has('python3') Plug 'hrsh7th/cmp-nvim-lsp' Plug 'stevearc/dressing.nvim' -endif -Plug 'nvim-treesitter/nvim-treesitter' + Plug 'nvim-treesitter/nvim-treesitter' + " Code folding + set foldmethod=expr + set foldexpr=nvim_treesitter#foldexpr() + "autocmd BufEnter * normal zR +endif Plug 'axieax/urlview.nvim' @@ -177,13 +192,7 @@ Plug 'ggandor/leap.nvim' call plug#end() -" copy URL under cursor to clipboard bind -:nnoremap uu :let @+ = expand('') - -" see .config/nvim/lua/init.lua -lua require('init') - -" Code folding -set foldmethod=expr -set foldexpr=nvim_treesitter#foldexpr() -"autocmd BufEnter * normal zR +if $SYSTEM_PROFILE == "DEFAULT" + " see .config/nvim/lua/init.lua + lua require('init') +endif diff --git a/src/.config/nvim/lua/init.lua b/src/.config/nvim/lua/init.lua index 0d9b398..b6a9242 100644 --- a/src/.config/nvim/lua/init.lua +++ b/src/.config/nvim/lua/init.lua @@ -24,28 +24,26 @@ require("urlview").setup({ }, }) -local nvim_lsp = require('lspconfig') - local on_attach = function(client, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- Enable completion triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - local opts = { noremap=true, silent=true } - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'gK', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'gt', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.format()', opts) + local opts = { noremap=true, silent=true } + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'gK', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'gt', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.format()', opts) end -- settings per server (overrides defaults) @@ -68,6 +66,8 @@ local servers = { }, clangd = {} } + +local nvim_lsp = require('lspconfig') for lsp, sv_settings in pairs(servers) do -- defaults settings = { diff --git a/src/.profile b/src/.profile index 3b1e1ed..ca3a31b 100644 --- a/src/.profile +++ b/src/.profile @@ -61,4 +61,11 @@ if [ -r "$XDG_CONFIG_HOME"/identity ]; then source "$XDG_CONFIG_HOME"/identity fi +# Profile to enable/disable features on certain devices +if [ ! -f "$XDG_CONFIG_HOME"/dot_profile ]; then + export SYSTEM_PROFILE="DEFAULT" +else + source "$XDG_CONFIG_HOME"/dot_profile +fi + source .config/bashrc