Is it possible to work with a str-list
option like a stack or array?
Is this option type effectively just a string that you can concat to with set -add
?
If I add several string values that each may contain spaces to a str-list
, then is it possible to retrieve, say, the first item?
This post seems like a good reference for implementing pushing/popping to a str-list, but also seems to confirm my suspicion that you’d have to manually manage the format of each item added to the list.
One feature from Vim that I was missing in Kakoune is the tag stack. Here is a very basic implementation:
declare-option str-list tagstack ""
declare-option str tagstack_cmd "ctags-search"
define-command -override -params 1 tagstack-push %{
set-option global tagstack "%val{buffile}" "%val{cursor_line}" \
"%val{cursor_column}" "%arg{1}" %opt{tagstack}
try %{
%opt{tagstack_cmd} "%arg{1}"
} catch %{
tagstack-pop
fail "tag not found %arg{1}"
}
}
define-command -override ta…
Based on the previously referenced example, this is a minimal demonstration for working with with str-list
options via shell expansion:
define-command example_str_list_consumer %{
declare-option str-list mystrlst
set-option global mystrlst
set-option -add global mystrlst "list item 1"
set-option -add global mystrlst "list item 2"
evaluate-commands %sh{
eval "set -- $kak_quoted_opt_mystrlst"
printf "echo -debug ''\n"
printf "echo -debug 'arg count: %s'\n" "$#"
printf "echo -debug 'all args: %s'\n" "$*"
printf "echo -debug 'arg 1: %s'\n" "$1"
printf "echo -debug 'arg 2: %s'\n" "$2"
printf "buffer *debug*\n"
}
}
This will open the debug buffer with the following entries:
arg count: 2
all args: list item 1 list item 2
arg 1: list item 1
arg 2: list item 2
When referenced in this way, each item in the str-list option is preserved, spaces and all!