the undo serial number of current buffer?

2 views
Skip to first unread message

StarWing

unread,
Jul 15, 2009, 6:33:08 AM7/15/09
to vim_dev
OKay, changenr() is more or less enough. but in doc, it says "After
undo it is one less than the number of the undone change."

so, how can I get the exactly serial number of current buffer? the one
I can use in undo command. (changenr() can't use in undo command, exec
changenr()."u" is not always current status of buffer).

Ben Fritz

unread,
Jul 16, 2009, 10:31:33 PM7/16/09
to vim_dev
What do you mean changenr() can't be used in the undo command? It says
right in the help that it can be! What exactly are you trying to do,
and what do you get instead? What is the "serial number of current
buffer"? Are you looking for :help changetick instead?

You give an example trying to do :exec changenr()."u" Don't you
want :exec "undo ".changenr()? It doesn't look like :undo takes a
count...it takes an argument.

StarWing

unread,
Jul 17, 2009, 3:40:06 AM7/17/09
to vim_dev
Thank you for attention my problem!!! :-)

first, my purpose is confirm the state of buffer. that's see, when I
press 'u<C-R>', '<C-R>u>', 'ifoobaru', 'g+g-', etc. we can know the
state of buffer is not change. so I can't use b:changetick...

then, the doc of changenr() said, when you do a undo, changenr() just
return the state number you are undo FORM substract 1, e.g. you are in
state 5, you press u and return to state 2, but changenr() doesn't
return 2, it returns 5-1 = 4! you can do a expriement:

1. input "ione<ESC>". (changenr() 1, state 1)
2. input "i too<ESC>". (changenr() 2, state 2)
3. input "u". (changenr() 1, state 1)
4. input "i two<esc>". (changenr() 3, state 3)
5. input "u" (changenr() 2, but state is 1)

so, I can't use changenr() for this purpose :-(

at last, in ex_cmds.h, undo item is just:

EX(CMD_undo, "undo", ex_undo,
RANGE|NOTADR|COUNT|ZEROR|TRLBAR|CMDWIN),

it can accept a count and even a range, but not NEEDARG. so maybe we
should update the doc undo.txt...

Tony Mechelynck

unread,
Jul 17, 2009, 4:23:13 AM7/17/09
to vim...@googlegroups.com


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"

StarWing

unread,
Jul 17, 2009, 5:31:01 AM7/17/09
to vim_dev


On 7月17日, 下午4时23分, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:
Thank you. undo-redo is just a way to provide that, though one state
can't reach...and it may be slow.

it caused in undo.c u_undoredo() function, 1300lines. can any one fix
it?
Reply all
Reply to author
Forward
0 new messages