add start of zettel.kak
parent
8f94fc2619
commit
05bb93506c
|
@ -0,0 +1,72 @@
|
|||
# lots of this is sourced from Screwtapello's kakoune-ghwiki plugin at
|
||||
# https://gitlab.com/Screwtapello/kakoune-ghwiki/-/blob/master/ghwiki.kak.
|
||||
# (Licensed MIT.) Thanks for having such good comments!
|
||||
declare-option str zettel_all_path zettel-all
|
||||
|
||||
# where are our zettel names stored?
|
||||
declare-option completions zettel_completions
|
||||
|
||||
# Insert our completion option at the front of the list.
|
||||
# Because our completions have non-word characters like spaces and [[]],
|
||||
# our completions need to be higher priority to make them show up reliably.
|
||||
set-option global completers option=zettel_completions %opt{completers}
|
||||
|
||||
define-command zettel-populate-completions %{
|
||||
evaluate-commands %sh{
|
||||
$kak_opt_zettel_all_path | cut -d: -f2 | sed 's/"/""/g' | while read -r link; do
|
||||
printf 'set-option -add window zettel_completions "%s]]||%s]]"\n' "$link" "$link"
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
define-command zettel-select-link-target %{
|
||||
try %{
|
||||
# Do we already have a wiki link completely selected?
|
||||
execute-keys s\A\[\[.*\]\]\z<ret>
|
||||
|
||||
} catch %{
|
||||
# No, but maybe if we select the square brackets around us,
|
||||
# we'll have a complete wiki link?
|
||||
execute-keys <a-a>r
|
||||
execute-keys s\A\[\[.*\]\]\z<ret>
|
||||
|
||||
} catch %{
|
||||
# OK, we've selected text inside one set of square brackets,
|
||||
# and that's not a wiki link,
|
||||
# but maybe the second set of square brackets is around *that*?
|
||||
execute-keys <a-a>r
|
||||
execute-keys s\A\[\[.*\]\]\z<ret>
|
||||
|
||||
} catch %{
|
||||
# Nope, no idea.
|
||||
fail No wiki link found.
|
||||
}
|
||||
|
||||
# We've selected the entire link,
|
||||
# now just select the text inside it.
|
||||
execute-keys <a-i>r <a-i>r
|
||||
}
|
||||
|
||||
define-command \
|
||||
-docstring "Follow the zettel link under the main cursor" \
|
||||
zettel-follow-link \
|
||||
%{
|
||||
# Save the 'a' register so we have a temporary storage space.
|
||||
evaluate-commands -save-regs a %{
|
||||
|
||||
# In a draft context (so we don't mess up the user's selections)
|
||||
evaluate-commands -draft %{
|
||||
# ...select the target page name of the link surrounding each cursor
|
||||
zettel-select-link-target
|
||||
|
||||
# Copy all the page names to a new scratch buffer
|
||||
execute-keys '"ay'
|
||||
}
|
||||
|
||||
# Now all our page names are in register a, so let's open up the
|
||||
# corresponding files!
|
||||
evaluate-commands %sh{
|
||||
printf 'echo "%s"\n' "$kak_main_reg_a"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue