Looks like you can do it after an undo-redo (provided of course that
there is at least one undoable change). changenr() will then return the
number of the change which has just been redone, and that is what you
call the "state" in the above example.
":undo" can accept an integer argument, which is an undo number. Vim
treats it internally as a count even though it isn't a "number of times
to repeat the same action". Similarly, ":wincmd w" accepts a "count"
which is not a number of repeats but a window number.
From what I see with ":cs find s NEEDARG" in the Vim source, NEEDARG
seems to be for non-numeric arguments, such as filenames, "xterm" or
"mswin" in the ":behave" command, ex-commands after ":silent" ":browse"
":botright", etc.
Best regards,
Tony.
--
Schlattwhapper, n.:
The window shade that allows itself to be pulled down,
hesitates for a second, then snaps up in your face.
-- Rich Hall, "Sniglets"