Permalink
Browse files

Included patch for persistent undo. Lots of changes and added test.

--HG--
branch : vim73
  • Loading branch information...
1 parent 5489f92 commit def17d9dffd41da749ff28408a76b21512c28924 @brammool brammool committed May 23, 2010
View
@@ -805,6 +805,7 @@ Note: these are typed literally, they are not special keys!
*filename-modifiers*
*:_%:* *::8* *::p* *::.* *::~* *::h* *::t* *::r* *::e* *::s* *::gs*
+ *%:8* *%:p* *%:.* *%:~* *%:h* *%:t* *%:r* *%:e* *%:s* *%:gs*
The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>",
"<afile>" or "<abuf>". They are also used with the |fnamemodify()| function.
These are not available when Vim has been compiled without the |+modify_fname|
View
@@ -6053,6 +6053,7 @@ os2 OS/2 version of Vim.
osfiletype Compiled with support for osfiletypes |+osfiletype|
path_extra Compiled with up/downwards search in 'path' and 'tags'
perl Compiled with Perl interface.
+persistent_undo Compiled with support for persistent undo history.
postscript Compiled with PostScript file printing.
printer Compiled with |:hardcopy| support.
profile Compiled with |:profile| support.
View
@@ -7220,6 +7220,33 @@ A jump table for the options with a short description can be found at |Q_op|.
global
Alias for 'term', see above.
+ *'undodir'* *'udir'*
+'undodir' 'udir' string (default ".")
+ global
+ {not in Vi}
+ {only when compiled with the +persistent_undo feature}
+ List of directory names for undo files, separated with commas.
+ See |'backupdir'| for the format. Specifically, "." means using the
+ directory of the file.
+ When writing: The first directory that exists is used. "." always
+ works, no directories after "." will be used for writing.
+ When reading all entries are tried to find an undo file. The first
+ undo file that exists is used. When it cannot be read an error is
+ given, no further entry is used.
+ See |undo-persistence|.
+
+ *'undofile'* *'udf'*
+'undofile' 'udf' boolean (default off)
+ local to buffer
+ {not in Vi}
+ {only when compiled with the +persistent_undo feature}
+ When on, Vim automatically saves undo history to an undo file when
+ writing a buffer to a file, and restores undo history from the same
+ file on buffer read.
+ The name of the undo file is specified by 'undodir'.
+ See |undo-persistence|.
+ WARNING: this is a very new feature. Use at your own risc!
+
*'undolevels'* *'ul'*
'undolevels' 'ul' number (default 100, 1000 for Unix, VMS,
Win32 and OS/2)
View
@@ -10,6 +10,16 @@ $VIM starting.txt /*$VIM*
$VIM-use version5.txt /*$VIM-use*
$VIMRUNTIME starting.txt /*$VIMRUNTIME*
% motion.txt /*%*
+%:. cmdline.txt /*%:.*
+%:8 cmdline.txt /*%:8*
+%:e cmdline.txt /*%:e*
+%:gs cmdline.txt /*%:gs*
+%:h cmdline.txt /*%:h*
+%:p cmdline.txt /*%:p*
+%:r cmdline.txt /*%:r*
+%:s cmdline.txt /*%:s*
+%:t cmdline.txt /*%:t*
+%:~ cmdline.txt /*%:~*
& change.txt /*&*
' motion.txt /*'*
'' motion.txt /*''*
@@ -1005,7 +1015,11 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME*
'tw' options.txt /*'tw'*
'tx' options.txt /*'tx'*
'uc' options.txt /*'uc'*
+'udf' options.txt /*'udf'*
+'udir' options.txt /*'udir'*
'ul' options.txt /*'ul'*
+'undodir' options.txt /*'undodir'*
+'undofile' options.txt /*'undofile'*
'undolevels' options.txt /*'undolevels'*
'updatecount' options.txt /*'updatecount'*
'updatetime' options.txt /*'updatetime'*
@@ -1163,6 +1177,7 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME*
+path_extra various.txt /*+path_extra*
+perl various.txt /*+perl*
+perl/dyn various.txt /*+perl\/dyn*
++persistent_undo various.txt /*+persistent_undo*
+postscript various.txt /*+postscript*
+printer various.txt /*+printer*
+profile various.txt /*+profile*
@@ -2582,6 +2597,7 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME*
:rubydo if_ruby.txt /*:rubydo*
:rubyf if_ruby.txt /*:rubyf*
:rubyfile if_ruby.txt /*:rubyfile*
+:rundo undo.txt /*:rundo*
:runtime repeat.txt /*:runtime*
:rv starting.txt /*:rv*
:rviminfo starting.txt /*:rviminfo*
@@ -2964,6 +2980,7 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME*
:write_f editing.txt /*:write_f*
:ws workshop.txt /*:ws*
:wsverb workshop.txt /*:wsverb*
+:wundo undo.txt /*:wundo*
:wv starting.txt /*:wv*
:wviminfo starting.txt /*:wviminfo*
:x editing.txt /*:x*
@@ -6913,6 +6930,7 @@ perl-overview if_perl.txt /*perl-overview*
perl-patterns pattern.txt /*perl-patterns*
perl-using if_perl.txt /*perl-using*
perl.vim syntax.txt /*perl.vim*
+persistent-undo undo.txt /*persistent-undo*
pexpr-option print.txt /*pexpr-option*
pfn-option print.txt /*pfn-option*
pheader-option print.txt /*pheader-option*
@@ -7835,6 +7853,7 @@ undo undo.txt /*undo*
undo-blocks undo.txt /*undo-blocks*
undo-branches undo.txt /*undo-branches*
undo-commands undo.txt /*undo-commands*
+undo-persistence undo.txt /*undo-persistence*
undo-redo undo.txt /*undo-redo*
undo-remarks undo.txt /*undo-remarks*
undo-tree undo.txt /*undo-tree*
View
@@ -30,6 +30,9 @@ be worked on, but only if you sponsor Vim development. See |sponsor|.
*known-bugs*
-------------------- Known bugs and current work -----------------------
+When Vim crashes it may run out of stack while executing autocommands. Patch
+to not run autocommands when leaving Vim? (James Vega, 2010 May 23)
+
Cursor positioning wrong with 0x200e character. (John Becket, 2010 May 6)
E315 when trying to change a file in FileChangedRO autocommand event.
@@ -1082,6 +1085,18 @@ restored. (Luc St-Louis)
Vim 7.3:
Patches to include:
+8 Persistent undo bugs / fixes:
+ - Add tests. Also with different 'enc'
+ - Add undofile(name): get undo file name for buffer "name".
+- Extend test62 for gettabvar() and settabvar(). (Yegappan Lakshmanan, 2010
+ May 23)
+- Also crypt the undo file.
+- Also crypt the swap file, each block separately. Change mf_write() and
+ mf_read(). How to get b_p_key to these functions?
+- Do profiling on sha256 code to find obvious bottlenecks.
+- Do profiling on crypt code to find obvious bottlenecks.
+- Use off_t instead of long for bytes in a buffer. (James Vega, 2010 May 22,
+ update next day)
- Include conceal patch?
http://vince.negri.googlepages.com/
http://vim.wikia.com/wiki/Patch_to_conceal_parts_of_lines
@@ -1150,42 +1165,17 @@ Needs some work:
Needs some more testing.
Update 2010 Apr 20, patch by Andy Kittner, May 16
- Easier/standard way to disable default plugins.
-8 Persistent undo: store undo in a file. Patch by Jordan Lewis, 2009 Feb
- 20. Repost 2009 Nov 16.
- Get tar file from: http://repo.or.cz/w/vim_extended.git/tree/feat/persistent-undo
- -> disable by default and add remark that it's new and may fail.
- Testing remarks by Christian Brabandt, 2010 May 1:
- - doesn't work well with symlinks (Jordan will look into it)
- - old undo files tend to pile up
- - :rundo should output a message (Jordan will fix this)
- Bugs / fixes:
- - Undo file should be stored with the original file by default, the undo
- directory doesn't handle remote files or directory renames.
- Use same mechanism as for swap files? But only with one file name.
- - Read coladd depending on FEAT_VIRTUALEDIT, should always read/write it
- - invoke u_wundo() inside buf_write()
- - invoke u_rundo() inside readfile()
- - Document that ":wundo" and ":rundo" should only be used in autocommands.
- - unserialize_pos() does not need a return value
- - function comments go before the function, not inside
- - u_get_undofile() changes its argument ffname
- - make magic four bytes.
- - errors need numbers "E000:"
- - also put 'enc' in undo file.
- - don't use timestamp, "touch file" or dir copy may change it and undo
- still works.
- Older ideas:
- - Use timestamps, so that a version a certain time ago can be found and
- info before some time/date can be flushed. 'undopersist' gives maximum
- time to keep undo: "3h", "1d", "2w", "1y", etc. For the file use dot
- and extension: ".filename.un~" (like swapfile but "un~" instead of
- "swp").
- ":{range}source": source the lines from the current file.
You can already yank lines and use :@" to execute them.
Most of do_source() would not be used, need a new function.
It's easy when not doing breakpoints or profiling.
+Probably not now:
+- Use timestamps for undo, so that a version a certain time ago can be found
+ and info before some time/date can be flushed. 'undopersist' gives maximum
+ time to keep undo: "3h", "1d", "2w", "1y", etc.
Before (beta) release:
- Add fixes for 7.2 to version7.txt
+- Rename vim73 branch to default (hints: Xavier de Gaye, 2010 May 23)
More patches:
@@ -1292,7 +1282,6 @@ Awaiting updated patches:
to left as well? See patch of Dec 26. (Nadim Shaikli)
8 Option to lock all used memory so that it doesn't get swapped to disk
(uncrypted). Patch by Jason Holt, 2003 May 23. Uses mlock.
-7 Support a stronger encryption. Jason Holt implemented AES (May 6 2003).
7 Add ! register, for shell commands. (patch from Grenie)
8 In the gzip plugin, also recognize *.gz.orig, *.gz.bak, etc. Like it's
done for filetype detection. Patch from Walter Briscoe, 2003 Jul 1.
@@ -4320,11 +4309,6 @@ Mouse support:
- When mouse click after 'r' command, get character that was pointed to.
-Crypt and security:
-8 Also crypt the swapfile, each block separately. Change mf_write() and
- mf_read(). How to get b_p_key to these functions?
-
-
Argument list:
6 Add command to put all filenames from the tag files in the argument list.
When given an argument, only use the files where that argument matches
View
@@ -12,7 +12,8 @@ The basics are explained in section |02.5| of the user manual.
2. Two ways of undo |undo-two-ways|
3. Undo blocks |undo-blocks|
4. Undo branches |undo-branches|
-5. Remarks about undo |undo-remarks|
+5. Undo persistence |undo-persistence|
+6. Remarks about undo |undo-remarks|
==============================================================================
1. Undo and redo commands *undo-commands*
@@ -22,7 +23,7 @@ u Undo [count] changes. {Vi: only one level}
*:u* *:un* *:undo*
:u[ndo] Undo one change. {Vi: only one level}
-
+ *E830*
:u[ndo] {N} Jump to after change number {N}. See |undo-branches|
for the meaning of {N}. {not in Vi}
@@ -109,6 +110,8 @@ change.
To do the opposite, break a change into two undo blocks, in Insert mode use
CTRL-G u. This is useful if you want an insert command to be undoable in
parts. E.g., for each sentence. |i_CTRL-G_u|
+Setting the value of 'undolevels' also breaks undo. Even when the new value
+is equal to the old value.
==============================================================================
4. Undo branches *undo-branches* *undo-tree*
@@ -201,7 +204,88 @@ Note that using "u" and CTRL-R will not get you to all possible text states
while repeating "g-" and "g+" does.
==============================================================================
-5. Remarks about undo *undo-remarks*
+5. Undo persistence *undo-persistence* *persistent-undo*
+
+When unloading a buffer Vim normally destroys the tree of undos created for
+that buffer. By setting the 'undofile' option, Vim will automatically save
+your undo history when you write a file and restore undo history when you edit
+the file again.
+
+The 'undofile' option is checked after writing a file, before the BufWritePost
+autocommands. If you want to control what files to write undo information
+for, you can use a BufWritePre autocommand: >
+ au BufWritePre /tmp/* setlocal noundofile
+
+Vim saves undo trees in a separate undo file, one for each edited file, using
+a simple scheme that maps filesystem paths directly to undo files. Vim will
+detect if an undo file is no longer synchronized with the file it was written
+for (with a hash of the file contents) and ignore it when the file was changed
+after the undo file was written, to prevent corruption.
+
+Undo files are normally saved in the same directory as the file. This can be
+changed with the 'undodir' option.
+
+You can also save and restore undo histories by using ":wundo" and ":rundo"
+respectively:
+ *:wundo* *:rundo*
+:wundo[!] {file}
+ Write undo history to {file}.
+ When {file} exists and it does not look like an undo file
+ (the magic number at the start of the file is wrong), then
+ this fails, unless the ! was added.
+ If it exists and does look like an undo file it is
+ overwritten.
+ {not in Vi}
+
+:rundo {file} Read undo history from {file}.
+ {not in Vi}
+
+You can use these in autocommands to explicitly specify the name of the
+history file. E.g.: >
+
+ au BufReadPost * rundo %:h/UNDO/%:t
+ au BufWritePost * wundo %:h/UNDO/%:t
+
+You should keep 'undofile' off, otherwise you end up with two undo files for
+every write.
+Note: I did not verify this always works!
+
+Note that while reading/writing files and 'undofile' is set most errors will
+be silent, unless 'verbose' is set. With :wundo and :rundo you will get more
+error messages, e.g., when the file cannot be read or written.
+
+NOTE: undo files are never deleted by Vim. You need to delete them yourself.
+
+Reading an existing undo file may fail for several reasons:
+*E822* It cannot be opened, because the file permissions don't allow it.
+*E823* The magic number at the start of the file doesn't match. This usually
+ means it is not an undo file.
+*E824* The version number of the undo file indicates that it's written by a
+ newer version of Vim. You need that newer version to open it. Don't
+ write the buffer if you want to keep the undo info in the file.
+"Undo file contents changed"
+ The file text differs from when the undo file was written. This means
+ the undo file cannot be used, it would corrupt the text.
+*E825* *E826* The undo file does not contain valid contents and cannot be
+ used.
+*E827* The magic number at the end of the file was not found. This usually
+ means the file was truncated.
+
+Writing an undo file may fail for these reasons:
+*E828* The file to be written cannot be created. Perhaps you do not have
+ write permissions in the directory.
+"Will not overwrite with undo file, cannot read"
+ A file exists with the name of the undo file to be written, but it
+ cannot be read. You may want to delete this file or rename it.
+"Will not overwrite, this is not an undo file"
+ A file exists with the name of the undo file to be written, but it
+ does not start with the right magic number. You may want to delete
+ this file or rename it.
+*E829* An error occurred while writing the undo file. You may want to try
+ again.
+
+==============================================================================
+6. Remarks about undo *undo-remarks*
The number of changes that are remembered is set with the 'undolevels' option.
If it is zero, the Vi-compatible way is always used. If it is negative no
View
@@ -359,6 +359,7 @@ m *+ole* Win32 GUI only: |ole-interface|
N *+path_extra* Up/downwards search in 'path' and 'tags'
m *+perl* Perl interface |perl|
m *+perl/dyn* Perl interface |perl-dynamic| |/dyn|
+H *+persistent_undo* Persistent undo |undo-persistence|
*+postscript* |:hardcopy| writes a PostScript file
N *+printer* |:hardcopy| command
H *+profile* |:profile| command
View
@@ -7170,6 +7170,10 @@ the buffer is marked as modified.
Added *added-7.3*
-----
+Persistent undo: store undo information in a file. Can undo to before when
+the file was read, also for unloaded buffers. |undo-persistence|
+(partly by Jordan Lewis)
+
Added the 'relativenumber' option. (Markus Heidelberg)
Support for Blowfish encryption. Added the 'cryptmethod' option.
View
@@ -1032,6 +1032,10 @@ if has("vertsplit")
call append("$", "cmdwinheight\theight of the command-line window")
call <SID>OptionG("cwh", &cwh)
endif
+call append("$", "undofile\tautomatically save and restore undo history")
+call <SID>BinOptionG("udf", &udf)
+call append("$", "undodir\tlist of directories for undo files")
+call <SID>OptionG("udir", &udir)
call <SID>Header("executing external commands")
View
@@ -288,7 +288,7 @@ NOTA: Se batti solo il movimento mentre sei in Modalit
2. Batti d2w per cancellare le due parole MAIUSCOLE
- 3. Ripeti i passi 1 e 2 con un contatore diverso per cancellare la parole
+ 3. Ripeti i passi 1 e 2 con un contatore diverso per cancellare le parole
MAIUSCOLE consecutive con un solo comando
---> questa ABC DE linea FGHI JK LMN OP di parole � Q RS TUV ora ripulita.
@@ -288,7 +288,7 @@ NOTA: Se batti solo il movimento mentre sei in Modalità Normale, senza
2. Batti d2w per cancellare le due parole MAIUSCOLE
- 3. Ripeti i passi 1 e 2 con un contatore diverso per cancellare la parole
+ 3. Ripeti i passi 1 e 2 con un contatore diverso per cancellare le parole
MAIUSCOLE consecutive con un solo comando
---> questa ABC DE linea FGHI JK LMN OP di parole è Q RS TUV ora ripulita.
View
@@ -61,8 +61,9 @@ static void buf_delete_signs __ARGS((buf_T *buf));
#endif
/*
- * Open current buffer, that is: open the memfile and read the file into memory
- * return FAIL for failure, OK otherwise
+ * Open current buffer, that is: open the memfile and read the file into
+ * memory.
+ * Return FAIL for failure, OK otherwise.
*/
int
open_buffer(read_stdin, eap)
Oops, something went wrong.

0 comments on commit def17d9

Please sign in to comment.