Skip to content

About

Native Neovim plugin for StrictDoc (.sdoc): syntax, indent, folding, navigation, wrap mappings

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

strictdoc.nvim

Native Neovim support for StrictDoc .sdoc files: syntax, indent, folding, node motions, wrap mappings, an outline and tag jumps. Pure Lua plus one Vimscript syntax file. No dependencies, no setup(), no Treesitter.

The syntax follows StrictDoc's textX grammar (strictdoc/backend/sdoc/grammar/), and the tests run on real .sdoc files from the StrictDoc repo.

Install

With the built-in vim.pack (Neovim 0.12+), in your init.lua:

vim.pack.add({ 'https://github.com/awschult002/strictdoc.nvim' })

Or by hand as a native package (any name works in place of plugins):

git clone https://github.com/awschult002/strictdoc.nvim \
  ~/.local/share/nvim/site/pack/plugins/start/strictdoc.nvim
nvim -c 'helptags ALL' -c q

Features

  • Filetype: *.sdoc is detected as sdoc.
  • Syntax (modeled on the bundled toml.vim): [DOCUMENT], [GRAMMAR], [DOCUMENT_FROM_FILE], [SECTION]/[/SECTION], [[NODE]]/[[/NODE]] composite nodes, [REQUIREMENT], [TEXT] and custom nodes, legacy [FREETEXT]/[/FREETEXT], KEY: fields, >>>/<<< text blocks, RELATIONS (- TYPE: Parent, VALUE:), booleans, [LINK: …] and [ANCHOR: …]. Groups link to standard ones (Title, Statement, PreProc, Identifier, String, …) so any colorscheme works.
  • Indent: files stay flat, the way StrictDoc requires: =/gg=G puts every marker and field in column 0 and keeps the grammar's two-space lists (RELATIONS, OPTIONS, VIEWS, [GRAMMAR]). Text between >>> and <<< is never reindented, so gg=G is safe on a whole file.
  • Blank lines: StrictDoc needs exactly one empty line before every node marker ([TEXT], [REQUIREMENT], [[SECTION]], [[/SECTION]], [DOCUMENT_FROM_FILE], …; none or two is a syntax error). =, gq and :StrictdocFormat insert or squeeze them, outside >>>/<<< blocks. (indentexpr can't add lines, so = is a buffer-local operator that fixes blank lines, then runs the builtin =.)
  • Virtual indent: nesting is shown with inline virtual text, one shiftwidth per open [SECTION]/[[NODE]]. The buffer text is never changed, so what you save is what StrictDoc parses.
  • Folding: foldexpr folds every node; sections nest their children.
  • Motions: ]]/[[ jump between nodes (counts, visual and operator-pending work); an/in select a node, at/it a >>>/<<< block.
  • Wrap: visual gr, gt, gs wrap the selection in a requirement, a text node or a section, always written flat.
  • Outline: :StrictdocOutline toggles a tree of sections and nodes (titles and UIDs) on the right. <CR> jumps, zc/zo fold, q closes. It refreshes when you write the file.
  • Tags: Ctrl-] on a UID, [LINK: X] or VALUE: X jumps to the node or anchor, also across the project's other .sdoc files. :tag Section title jumps to a section by title.

StrictDoc 0.30 rejects leading whitespace before markers and fields. Files indented by older versions of this plugin are fixed with gg=G.

Mappings

Buffer-local, in sdoc buffers only.

Keys Mode <Plug> Action
]] / [[ n x o (strictdoc-next-node) / (strictdoc-prev-node) next / previous node
an / in x o (strictdoc-node-outer) / (strictdoc-node-inner) around / inside node
at / it x o (strictdoc-block-outer) / (strictdoc-block-inner) around / inside >>> block
gr x (strictdoc-wrap-requirement) [REQUIREMENT] + STATEMENT: >>> … <<<
gt x (strictdoc-wrap-text) [TEXT] + STATEMENT: >>> … <<<
gs x (strictdoc-wrap-section) [SECTION] + TITLE: (cursor there) … [/SECTION]
= / == n x / n (strictdoc-format) / (strictdoc-format-line) indent + one blank line before each node marker
n (strictdoc-outline) toggle the outline

In sdoc buffers these shadow the visual-mode gs (sleep), the visual gra LSP code action, and the Treesitter an/in selections (no sdoc parser exists). Nowhere else.

Options

Option Default Effect
vim.g.strictdoc_virtual_indent on 0: no virtual indent (plain flat view)
shiftwidth (buffer) 2 width of one virtual indent level
vim.g.strictdoc_no_mappings unset 1: skip the default keys; <Plug> maps stay
vim.g.strictdoc_composite_sections 1 0: gs emits legacy [SECTION] / [/SECTION] (rejected by StrictDoc ≥ 0.30)
:StrictdocOutline toggle the outline; in it <CR> jumps, zc/zo fold, q closes
vim.g.strictdoc_format_on_save off 1: :StrictdocFormat the buffer before each write
:StrictdocFormat fix indent and blank lines (range, default whole file); also gq, and = unless strictdoc_no_mappings
vim.g.strictdoc_makeprg strictdoc export --formats=html of the cwd project makeprg for :compiler strictdoc. :make checks the grammar and the RST in every >>> block, and :copen lists errors at the .sdoc file and line. Run Neovim from the project root. Use strictdoc format %:S for a fast grammar-only check
vim.g.strictdoc_rst_syntax on 0: no RST highlighting inside >>> blocks
tagfunc set Ctrl-]/:tag on UIDs, links, anchors, section titles
foldmethod=expr, foldlevel 99 every node folds; zM closes all

Set the vim.g variables before the first .sdoc file opens. The ftplugin sets expandtab, shiftwidth=2, softtabstop=2, foldmethod=expr and foldlevel=99; override them in ~/.config/nvim/after/ftplugin/sdoc.lua:

vim.bo.shiftwidth = 4   -- virtual indent of 4 per level
vim.wo.foldlevel = 0    -- open files folded

Example config

vim.pack.add({ 'https://github.com/awschult002/strictdoc.nvim' })

vim.g.strictdoc_no_mappings = 1        -- pick your own keys

vim.api.nvim_create_autocmd('FileType', {
  pattern = 'sdoc',
  callback = function()
    local map = function(m, l, r) vim.keymap.set(m, l, r, { buffer = true }) end
    map({ 'n', 'x', 'o' }, ']]', '<Plug>(strictdoc-next-node)')
    map({ 'n', 'x', 'o' }, '[[', '<Plug>(strictdoc-prev-node)')
    map('x', '<leader>r', '<Plug>(strictdoc-wrap-requirement)')
    map('x', '<leader>t', '<Plug>(strictdoc-wrap-text)')
    map('x', '<leader>s', '<Plug>(strictdoc-wrap-section)')
    map('n', '<leader>o', '<Plug>(strictdoc-outline)')
  end,
})

See :help strictdoc for details.

Tests

make test

Runs nvim --headless -u NONE on tests/run.lua with the plugin installed as a pack/*/start package, then installs it with vim.pack.add(). CI runs the same on Neovim stable.

About

Native Neovim plugin for StrictDoc (.sdoc): syntax, indent, folding, navigation, wrap mappings

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages