(redir to vim-dev)
On Fr, 10 Okt 2014, William Gardner wrote:
> I've got a plugin that registers an autocmd on TextChanged and uses the '[
> and '] marks to act on the modified lines (trim trailing whitespace). There's
> a weird edge case that happens if you open a file and immediately save it.
> The save triggers TextChanged, and '[,'] defaults to 1,$. Here's a simple
> repro using a recently-built vim at 7.4.473:
>
> $ cat > foo
> foo
> bar
> baz
> ^D
> $ vim -N -u NONE foo
> :autocmd TextChanged * echomsg(line("'[") . "," . line("']"))
> :w
>
> And notice that "1,3" is printed in the status line.
>
> I can understand why '[,'] defaults to 1,$, but why does save trigger
> TextChanged?
Looks like on saving, the b:changedtick variable is incremented but the
last_changedtick variable is not, which triggers the autocommand.
This patch fixes it:
diff --git a/src/fileio.c b/src/fileio.c
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4877,6 +4877,11 @@ restore_backup:
)
{
unchanged(buf, TRUE);
+#ifdef FEAT_AUTOCMD
+ /* buf->b_changedtick is incremented in unchanged() */
+ if (last_changedtick + 1 == buf->b_changedtick)
+ last_changedtick = buf->b_changedtick;
+#endif
u_unchanged(buf);
u_update_save_nr(buf);
}
Best,
Christian
--
Wer selbst keine Handlungskompetenzen hat, kann nicht
wissen, wie man diese am besten vermittelt bekommt.
-- Nils Krüger
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.