...
 
Commits (2)
  • Tim Allen's avatar
    Address shellcheck warnings. · bc60560d
    Tim Allen authored
    bc60560d
  • Tim Allen's avatar
    Remove state-save-reg-sync. · ab7c0c76
    Tim Allen authored
    Certain Kakoune registers (the ones that represent prompt history,
    like the command prompt or the pipe prompt) append new items rather than
    replacing the whole list. When I originally created kakoune-state-save,
    I depended on that behaviour to automatically merge history
    from different Kakoune sessions: when a Kakoune session ended,
    it would merge in history saved by other sessions before writing out its own
    history.
    
    Unfortunately, Kakoune limits the number of history items to 100,
    which means that if you have 100 items on disk, state-save-reg-load will
    clobber the history of your current session with that of the previous session,
    so no new history items will ever be written out ever again.
    
    Since loading a register immediately before saving it out breaks things,
    and that's exactly what state-save-reg-sync did,
    there's no point in having it around.
    
    I've filed a Kakoune issue about making register-value merging smarter
    (https://github.com/mawww/kakoune/issues/3354), if it gets fixed then I'll
    add state-save-reg-sync back.
    ab7c0c76
......@@ -131,7 +131,9 @@ For most registers, the new values entirely replace the old values.
For history-like registers
(such as `colon`, the command-history register,
and `slash`, the search-history register)
the new values are appended, and then duplicates are removed.
each new item is appended,
any older duplicates are removed,
and the list is trimmed to 100 total items.
**WARNING:** Properly loading register contents
requires using Kakoune's `evaluate-commands` feature,
......@@ -139,26 +141,6 @@ which means anyone who can write to files in `%opt{state_save_path}`
can make your Kakoune _**execute arbitrary code**_
when you invoke `state-save-reg-load`.
`state-save-reg-sync <regname>`
-------------------------------
**regname:** One of the alphabetic register names
from Kakoune's `:doc registers` documentation.
Invoking `state-save-reg-sync whatever` is exactly the same as:
state-save-reg-load whatever
state-save-reg-save whatever
For history-like registers
(see the note under `state-save-reg-load` above),
this incorporates any items from other Kakoune sessions
into this Kakoune session,
and makes this sessions' items available
to other sessions.
**WARNING:** See the warning under `state-save-reg-load` above.
Usage
=====
......@@ -169,22 +151,21 @@ To save and restore command-history, search history, and pipe-command history,
add a snippet like this to your `kakrc` file:
hook global KakBegin .* %{
state-save-reg-sync colon
state-save-reg-sync pipe
state-save-reg-sync slash
state-save-reg-load colon
state-save-reg-load pipe
state-save-reg-load slash
}
hook global KakEnd .* %{
state-save-reg-sync colon
state-save-reg-sync pipe
state-save-reg-sync slash
state-save-reg-save colon
state-save-reg-save pipe
state-save-reg-save slash
}
You can save and restore other registers too,
see `:doc registers` to learn more.
**WARNING:** `state-save-reg-load` (and therefore `state-save-reg-sync`)
has security implications;
**WARNING:** `state-save-reg-load` has security implications;
see the warning in the `state-save-reg-load` section above.
Alternatively,
......
......@@ -62,21 +62,6 @@ define-command \
"%%reg{%arg{1}}"
}
define-command \
-params 1 \
-docstring "
state-save-reg-sync <regname>
Load register state from disk, then immediately save it back out.
This is only useful for registers that merge new items on load,
like the colon, slash, and pipe registers.
" \
state-save-reg-sync \
%{
state-save-reg-load %arg{1}
state-save-reg-save %arg{1}
}
# When a window is created for a buffer...
hook global WinCreate .* %{
# ...set the initial history ID for that buffer.
......@@ -87,7 +72,7 @@ hook global WinCreate .* %{
# window-related hook not executed in a draft context)...
hook -once window WinDisplay .* %{ evaluate-commands %sh{
# Do we care about the state of this file?
eval set -- $kak_opt_state_save_exclude_globs
eval set -- "$kak_opt_state_save_exclude_globs"
while [ $# -gt 0 ]; do
# If our buffer name matches one of the exclude globs, exit.
case "$kak_buffile" in ($1) exit ;; esac
......@@ -117,7 +102,7 @@ hook global WinCreate .* %{
#echo "echo -debug last saved history id: $kak_opt_last_state_save_history_id"
# ...if the buffer has not been modified since it was last saved...
if [ $kak_history_id = $kak_opt_last_state_save_history_id ]; then
if [ "$kak_history_id" = "$kak_opt_last_state_save_history_id" ]; then
# ...remember the current selection state of the buffer.
printf "%s\n" "set-option buffer last_state_save_selection '$kak_selections_desc'"
fi
......@@ -137,7 +122,7 @@ hook global WinCreate .* %{
# Whenever the buffer is closed...
hook window WinClose .* %{ evaluate-commands %sh{
# Do we care about the state of this file?
eval set -- $kak_opt_state_save_exclude_globs
eval set -- "$kak_opt_state_save_exclude_globs"
while [ $# -gt 0 ]; do
# If our buffer name matches one of the exclude globs, exit.
case "$kak_buffile" in ($1) exit ;; esac
......