# Warn when saving some but not all buffers

**URL:** <https://discuss.kakoune.com/t/warn-when-saving-some-but-not-all-buffers/1572>\
**Category:** Recipes & Guides\
**Created:** [February 8, 2021, 3:05pm UTC](https://discuss.kakoune.com/t/warn-when-saving-some-but-not-all-buffers/1572 "2021-02-08T15:05:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xfoo](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/x/cdc98d/32.png) [@xfoo](https://discuss.kakoune.com/u/xfoo)\
**Post date:** [February 8, 2021, 3:05pm UTC](https://discuss.kakoune.com/t/warn-when-saving-some-but-not-all-buffers/1572/1 "2021-02-08T15:05:27Z")

</div>

This prevents me from forgetting to save files:

```auto
declare-option str-list buffers_modified_false
declare-option str-list buffers_modified_true

hook -group kakrc global BufWritePost .* %{
    set-option global buffers_modified_false
    set-option global buffers_modified_true
    eval -buffer * %{
        set-option -add global "buffers_modified_%val{modified}" %val{bufname}
    }
    try %{
        evaluate-commands -draft %{
            buffer-next %opt{buffers_modified_true} # buffer-next fails if given any arguments, i.e. if buffers_modified_true is nonempty
        }
        echo
    } catch %{
        echo -markup "{Information}WARNING: unsaved buffers: %opt{buffers_modified_true}"
    }
}

```

Every time I save a file, this hook makes a list of saved buffers and a list of unsaved buffers. If there are any unsaved buffers, it prints a warning.

To check whether a list is empty, I pass it as the argument list to `buffer-next` which requires 0 arguments to not fail.
