Files
nuwiki/ftdetect/nuwiki.vim
gffranco 09b9bd98a3
CI / cargo fmt --check (push) Successful in 35s
CI / cargo clippy (push) Successful in 1m12s
CI / cargo test (push) Successful in 1m26s
fix(ftplugin): load on .wiki buffers without manual filetype override
Three reasons the plugin wasn't activating on `nvim --clean -u init.lua
foo.wiki`:

1. **File-name mismatch.** Vim's filetype-plugin runtime looks for
   `ftplugin/<filetype>.vim` matching the *filetype name*. Our
   filetype is `vimwiki` (per `ftdetect`) but the file was named
   `ftplugin/nuwiki.vim` — so `:runtime! ftplugin/vimwiki.vim` from
   the built-in FileType autocmd never found it, and none of the
   `:Vimwiki*` / `:Nuwiki*` commands got defined. Same wart on the
   syntax side. Renamed:
   - `ftplugin/nuwiki.vim`  → `ftplugin/vimwiki.vim`
   - `syntax/nuwiki.vim`    → `syntax/vimwiki.vim`

2. **`setfiletype` deferred to Neovim's bundled rule.** Neovim ships
   a default `*.wiki → mediawiki` rule via `vim.filetype.add`, and
   `:setfiletype vimwiki` is a no-op once a filetype has been set.
   - `ftdetect/nuwiki.vim` now uses `set filetype=vimwiki` (force).
   - `lua/nuwiki/init.lua`'s `setup()` also calls
     `vim.filetype.add({ extension = { wiki = 'vimwiki', ... } })`
     so the modern table-based detection picks us before the
     bundled rule fires. Honours `config.options.file_extension`
     so a user with a custom extension gets covered automatically.

3. **`foldmethod`/`foldexpr` are window-local options.**
   `ftplugin.lua` was setting them with `nvim_set_option_value({ buf
   = bufnr })`, which threw `'buf' cannot be passed for window-local
   option 'foldmethod'` and aborted the rest of the per-buffer
   attach. Switched to `vim.opt_local.*` (window-aware), applied on
   the current window when the ftplugin fires, and re-applied via a
   `BufWinEnter` autocmd so `:split` / `:vsplit` keep the fold mode.

Verified end-to-end with:

  nvim --clean -u init.lua sample.wiki
  → filetype = vimwiki
  → :VimwikiTOC, :NuwikiIndex, … all defined
  → foldmethod = expr, foldexpr = v:lua.vim.lsp.foldexpr()
  → ftdetect, plugin, ftplugin, syntax all in :scriptnames

Total 377 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 22:16:57 +00:00

13 lines
624 B
VimL

" ftdetect/nuwiki.vim — associate *.wiki files with the `vimwiki` filetype.
"
" Users who configure a custom `file_extension` in setup() should add their
" own `:autocmd BufRead,BufNewFile *.myext setfiletype vimwiki` mapping;
" we hardcode `.wiki` since ftdetect runs before any user setup() call.
"
" Use `set filetype=…` (not `setfiletype`) so we override Neovim's bundled
" `*.wiki → mediawiki` rule. Users who actually want MediaWiki on .wiki
" can override this with their own autocmd at a later runtimepath entry,
" or with `vim.filetype.add` in Neovim.
autocmd! BufRead,BufNewFile *.wiki set filetype=vimwiki