descriptionPlugin for the Vis editor
ownerrepo.or.cz@soba23.anonaddy.me
last changeSun, 17 Mar 2024 14:38:58 +0000 (17 22:38 +0800)
content tags
add:
README.md

vis-parkour is a structured editing plugin for the vis editor, based on the parkour library.

Configuration

In ~/.config/vis/visrc.lua:

local pk = require'vis-parkour'

-- optional:
pk.auto_square_brackets = true
pk.lispwords.scheme.lambda = 0
pk.repl_fifo = os.getenv('HOME')..'/.repl_fifo'
pk.emacs = false
pk.autoselect = true

auto_square_brackets

Rewrites any delimiter to a square bracket at certain locations.
Has effect only on Scheme; for Clojure and Fennel this behaviour is always on.
Works both when inserting and wrapping.
The locations are not configurable ATM, but are grouped by language in the code - see, for example, the Fennel config.

lispwords.dialect.word

The plugin comes with a set of indentation rules for each supported file type, but they are incomplete and sometimes will be wrong (due to multiple possible dialects under a single file type).
The lispwords table allows customizing those rules by setting the desired number of distinguished arguments a function/macro has. (0 is like defun in Emacs.)
As an example, see the built-in indent numbers for Scheme.

repl_fifo

This option can be set to the path of a named pipe from which a REPL (or anything, really) can read input.
Pressing Enter will send to this pipe either the current paragraph or the visual selection. This works in INSERT mode, too, but only when the cursor is after the last character of a paragraph.
Since REPL commands fit the criteria for paragraph (a top-level S-expression), they get sent as well.

emacs

The plugin comes with two key themes - emacs and vim.
Both are enabled by default (there is no overlap between their key mappings; moreover, the emacs theme consists entirely of INSERT-mode mappings).
Setting this option to false will disable the emacs key theme.

Note: The linked key themes are the only "documentation" on the available keyboard shortcuts ATM.

autoselect ("Kakoune mode")

Setting this option to true will make every motion that has an associated S-expression textobject to automatically select it.
INSERT mode can be directly switched to from VISUAL mode; i will put the cursor before the selection, and a - after it.

Note: the Kakoune reference is mainly wrt the noun-verb order; this is not an attempt to recreate Kakoune's own key mappings. (Adding a new key theme could do that, but only to an extent.)

Usage

  1. Motions and textobjects:
    • a bigword/block is a list
    • a sentence is the current list/string/comment
      Note that sentence motions are exclusive in OPERATOR-PENDING mode.
    • a word is any S-expression - an atom or, if the cursor is on a delimiter, a list/string/comment
      Note that, when the cursor is on a list delimiter, a block textobject will select its parent list.
      This is not compatible with vis/vim, but makes motions and textobjects consistent with each other:
      • using a bigword/block/sentence always leads to depth change
      • using a word never leads to depth change
    • a paragraph is a top-level S-expression
    • word motions skip over comments, unless the cursor is already in a comment
  2. Inner/outer textobjects:
    This only makes a difference for delimited objects - lists, strings, comments.
  3. Objectwise deletion:
    When removing an S-expression that is part of a list, the adjacent whitespace is removed if you use d, and left intact if you use c (or are in INSERT mode).
    This holds true even when using a motion or inner textobject, or when in VISUAL mode.
    Any removed adjacent whitespace will not be copied to the register (but see the next item).
  4. Objectwise pasting:
    If the last y/d/c was used with a textobject, p will paste after the current S-expression, and P - before it.
    An appropiate type of whitespace (space or newline) will be added as well.
    (This generalizes over the idea of linewise pasting)
  5. autosplicing/autowrapping d and y:
    yE/yB wraps the copied half of the list in the same delimiters as the original (including any reader macro prefix).
    dE/dB does so too, and splices the original list.
  6. Pressing v while in VISUAL mode expands the selection by semantic units.

For some of the supported dialects (Guile, Racket, and Fennel, currently), the plugin cooperates with vis-goto-file, and parses include expressions for it.

Bugs

Vis lacks a "file-changed" kind of event, so the plugin cannot detect any changes other than those it caused itself.
This can be a problem if you use custom operators, or rotate visual selections (maybe other things, too).
When a change goes undetected, the internal parse tree grows out of sync with the actual text, word boundaries are no longer where the plugin expects them to be, and various weird and hard-to-reproduce issues may occur.
A work-around is to call undo and redo right after an external change.

Count argument is not implemented yet for operators and textobjects (but works for motions). OTOH, dot-repeating and semantic expansion of the visual selection do work and can often be good enough a substitute.

Dot-repeating a deletion will concatenateallthepieces in the register instead of overwriting the last piece.

shortlog
2024-03-17 Georgi KirilovMerge commit 'f9cb63561b743176ef831298a84c421fdb112f16'master
2024-03-17 Georgi Kirilovadd copyright notice
2024-03-17 Georgi Kirilovadd copyright notice
2024-03-17 Georgi Kirilovlink to fmt configuration as example
2024-03-17 Georgi Kirilovupdate README
2024-03-17 Georgi Kirilovadd backward-kill-sentence and fix the mapping
2023-08-27 Georgi Kirilovsplit the emacs key theme into sections
2023-08-27 Georgi Kirilovadd expand_region for INSERT-mode
2023-08-27 Georgi Kirilovadd more C-x emacs bindings
2023-08-27 Georgi Kirilovreorder key bindings
2023-08-27 Georgi Kirilovnaming consistent with the other functions
2023-08-27 Georgi Kirilovmark_defun from selection (keep the direction too)
2023-08-27 Georgi Kirilovinserting opening delimiter wraps transient selection
2023-08-27 Georgi Kirilovhighlight transient selection like Emacs
2023-08-27 Georgi KirilovMerge commit '3cb19512792726841b1dd5c7e8f6f327d58e268c...
2023-08-27 Georgi Kirilovenable dE to splice-killing when on a closing |#
...
heads
5 weeks ago master
7 months ago wrap
7 months ago fix-paragraph
7 months ago exclusive-paragraph
7 months ago dot-repeat
7 months ago objectwise