diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2702bf0..316187c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,6 +70,13 @@ jobs: exit 1 fi + - name: Verify path-safe module loading + run: | + mkdir -p "/tmp/chopsticks path/modules" + cp .vimrc "/tmp/chopsticks path/.vimrc" + cp modules/*.vim "/tmp/chopsticks path/modules/" + vim -u "/tmp/chopsticks path/.vimrc" -i NONE -es -N -c 'qa!' 2>&1 + - name: Verify minimal profile run: | vim -u NONE -i NONE -es -N \ @@ -78,6 +85,32 @@ jobs: -c 'if has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") || has_key(g:plugs, "vim-lsp-settings") || has_key(g:plugs, "asyncomplete.vim") | cquit | endif' \ -c 'qa!' 2>&1 + - name: Verify local config hook + run: | + mkdir -p /tmp/chopsticks-ci + printf "%s\n" "let g:chopsticks_profile = 'minimal'" > /tmp/chopsticks-ci/local.vim + vim -u NONE -i NONE -es -N \ + -c 'let g:chopsticks_local_config = "/tmp/chopsticks-ci/local.vim"' \ + -c 'source .vimrc' \ + -c 'if g:chopsticks_profile !=# "minimal" || has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") | cquit | endif' \ + -c 'qa!' 2>&1 + + - name: Verify profile-aware cheat sheet + run: | + vim -u NONE -i NONE -es -N \ + -c 'let g:chopsticks_profile = "minimal"' \ + -c 'source .vimrc' \ + -c 'normal ,?' \ + -c 'redir! > /tmp/chopsticks-cheat.txt' \ + -c 'silent %print' \ + -c 'redir END' \ + -c 'qa!' 2>&1 + if grep -Eq 'definition|LspInstallServer|ALE errors|undo tree|markdown preview' /tmp/chopsticks-cheat.txt; then + cat /tmp/chopsticks-cheat.txt + exit 1 + fi + grep -q ',cr run file' /tmp/chopsticks-cheat.txt + - name: Verify Markdown quiet defaults run: | vim -u .vimrc -i NONE -es -N README.md \ diff --git a/.vimrc b/.vimrc index fc64f3b..55b5a62 100644 --- a/.vimrc +++ b/.vimrc @@ -9,7 +9,7 @@ if exists('g:chopsticks_loaded') | finish | endif let g:chopsticks_loaded = 1 function! s:load(mod) abort - execute 'source ' . g:chopsticks_dir . '/modules/' . a:mod . '.vim' + execute 'source ' . fnameescape(g:chopsticks_dir . '/modules/' . a:mod . '.vim') endfunction call s:load('env') diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ed8b5..58fdef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,12 @@ ### Changed +- `,?` cheat sheet is now profile-aware and hides LSP/ALE/preview/UndoTree keys + when those features are disabled +- Module reload/source paths now use `fnameescape()` so installs in paths with + spaces are handled correctly +- CI now verifies path-safe module loading, the local config hook, and + minimal-profile cheat sheet output - Markdown now opens in quiet writing mode by default: no real-time markdownlint, no Marksman LSP, no spell noise, no conceal, no sign column, and no realtime preview - Native `s` is no longer shadowed by EasyMotion; use `,S` for the two-character jump diff --git a/QUICKSTART.md b/QUICKSTART.md index 4f2b0c1..2d52bfa 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -104,4 +104,7 @@ syntax. Enable the heavier Markdown tools only when you want them. :ChopsticksStatus see what's installed and what's missing ``` +The `,?` cheat sheet follows your active profile, so `minimal` users only see +keys for features that are actually loaded. + See [README](README.md) for the full reference. See the [wiki](https://github.com/m1ngsama/chopsticks/wiki) for deep dives. diff --git a/README.md b/README.md index 5cbe958..92f7f4f 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,8 @@ Startify, UndoTree, and browser Markdown preview. `full` keeps those and opts into Markdown lint, format, spell, conceal, Marksman, and LSP virtual text. Project updates leave `~/.config/chopsticks.vim` alone, so put local choices -there instead of editing the managed `.vimrc`. +there instead of editing the managed `.vimrc`. The `,?` cheat sheet follows the +active profile and only shows keys for enabled features. ## Keys diff --git a/modules/tools.vim b/modules/tools.vim index 7867809..5083d83 100644 --- a/modules/tools.vim +++ b/modules/tools.vim @@ -34,7 +34,7 @@ nnoremap W :%s/\s\+$//:let @/='' vnoremap W :s/\s\+$//:let @/=''gv nnoremap ev :edit $MYVIMRC -nnoremap sv :unlet! g:chopsticks_loaded:source $MYVIMRC:echo "vimrc reloaded" +nnoremap sv :unlet! g:chopsticks_loaded:execute 'source ' . fnameescape($MYVIMRC):echo "vimrc reloaded" nnoremap * :%s/\<\>//g vnoremap * :s///g @@ -240,12 +240,13 @@ function! s:CheatSheet() abort execute bufwinnr(l:name) . 'wincmd w | bd' return endif - execute 'vertical botright new ' . l:name - vertical resize 42 - setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile - setlocal nowrap nonumber norelativenumber signcolumn=no - setlocal winfixwidth - call setline(1, [ + + let l:has_lsp = get(g:, 'chopsticks_enable_lsp', 1) + let l:has_lint = get(g:, 'chopsticks_enable_lint', 1) + let l:has_undotree = exists('g:plugs["undotree"]') + let l:has_previm = exists('g:plugs["previm"]') + + let l:lines = [ \ ' chopsticks ,? close', \ ' ─────────────────────────────', \ '', @@ -263,28 +264,50 @@ function! s:CheatSheet() abort \ ' ,fm marks', \ '', \ ' ── code ──────────────────', - \ ' gd definition', - \ ' gy type definition', - \ ' gi implementation', - \ ' gr references', - \ ' K hover docs', - \ ' ,rn rename', - \ ' ,ca code action', - \ ' ,f format', - \ ' ,o outline', - \ ' ,cr run file', - \ ' ,mp markdown preview', - \ ' ,mt table of contents', - \ ' [g ]g LSP diagnostics', - \ ' [e ]e ALE errors', - \ ' ,af format on save', - \ ' :LspInstallServer setup LSP', + \ ] + + if l:has_lsp + call extend(l:lines, [ + \ ' gd definition', + \ ' gy type definition', + \ ' gi implementation', + \ ' gr references', + \ ' K hover docs', + \ ' ,rn rename', + \ ' ,ca code action', + \ ' ,f format', + \ ' ,o outline', + \ ' [g ]g LSP diagnostics', + \ ' :LspInstallServer setup LSP', + \ ]) + endif + + call add(l:lines, ' ,cr run file') + if l:has_previm + call add(l:lines, ' ,mp markdown preview') + endif + call add(l:lines, ' ,mt table of contents') + + if l:has_lint + call extend(l:lines, [ + \ ' [e ]e ALE errors', + \ ' ,af format on save', + \ ]) + endif + + call extend(l:lines, [ \ '', \ ' ── edit ──────────────────', \ ' gc comment', \ ' ,S+2ch easymotion jump', \ ' cs"'' surround', - \ ' ,u undo tree', + \ ]) + + if l:has_undotree + call add(l:lines, ' ,u undo tree') + endif + + call extend(l:lines, [ \ ' ,y ,p clipboard y/p (v)', \ ' Alt+j/k move line (v)', \ ' ,* replace word (v)', @@ -330,6 +353,13 @@ function! s:CheatSheet() abort \ ' ,sv reload vimrc', \ ' :ChopsticksStatus health', \ ]) + + execute 'vertical botright new ' . l:name + vertical resize 42 + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile + setlocal nowrap nonumber norelativenumber signcolumn=no + setlocal winfixwidth + call setline(1, l:lines) setlocal nomodifiable readonly nnoremap q :bd nnoremap ? :bd