To: [email protected]
Subject: patch 5.5a.3
Fcc: outbox
From: Bram Moolenaar <[email protected]>
------------

Patch 5.5a.3
Problem:    Editing compressed ".gz" files doesn't work on non-Unix systems,
           because there is no "mv" command.
Solution:   Add the rename() function and use it instead of ":!mv".
           Also: Disable the automatic jump to the last position, because it
           changes the jumplist.
Files:      src/eval.c, runtime/doc/eval.txt, runtime/vimrc_example.vim


*** ../vim-5.5a.2/src/eval.c    Wed Sep  1 17:48:59 1999
--- src/eval.c  Wed Sep  1 11:34:20 1999
***************
*** 193,198 ****
--- 193,199 ----
 static void f_matchend __ARGS((VAR argvars, VAR retvar));
 static void f_matchstr __ARGS((VAR argvars, VAR retvar));
 static void f_nr2char __ARGS((VAR argvars, VAR retvar));
+ static void f_rename __ARGS((VAR argvars, VAR retvar));
 static void f_setline __ARGS((VAR argvars, VAR retvar));
 static void f_some_match __ARGS((VAR argvars, VAR retvar, int start));
 static void f_strftime __ARGS((VAR argvars, VAR retvar));
***************
*** 1866,1871 ****
--- 1867,1873 ----
     {"matchend",      2, 2, f_matchend},
     {"matchstr",      2, 2, f_matchstr},
     {"nr2char",               1, 1, f_nr2char},
+     {"rename",                2, 2, f_rename},
     {"setline",               2, 2, f_setline},
 #ifdef HAVE_STRFTIME
     {"strftime",      1, 2, f_strftime},
***************
*** 3548,3553 ****
--- 3550,3569 ----
     buf[0] = (char_u)get_var_number(&argvars[0]);
     retvar->var_type = VAR_STRING;
     retvar->var_val.var_string = vim_strnsave(buf, 1);
+ }
+
+ /*
+  * "rename({from}, {to})" function
+  */
+     static void
+ f_rename(argvars, retvar)
+     VAR               argvars;
+     VAR               retvar;
+ {
+     char_u    buf[NUMBUFLEN];
+
+     retvar->var_val.var_number = vim_rename(get_var_string(&argvars[0]),
+                                       get_var_string_buf(&argvars[1], buf));
 }

 /*
*** ../vim-5.5a.2/runtime/doc/eval.txt  Mon Aug 30 10:41:10 1999
--- runtime/doc/eval.txt        Wed Sep  1 11:35:41 1999
***************
*** 1,4 ****
! *eval.txt*      For Vim version 5.5a.  Last change: 1999 Aug 22


                 VIM REFERENCE MANUAL    by Bram Moolenaar
--- 1,4 ----
! *eval.txt*      For Vim version 5.5a.  Last change: 1999 Sep 01


                 VIM REFERENCE MANUAL    by Bram Moolenaar
***************
*** 487,492 ****
--- 487,493 ----
 matchend( {expr}, {pat})      Number  position where {pat} ends in {expr}
 matchstr( {expr}, {pat})      String  match of {pat} in {expr}
 nr2char( {expr})              String  single char with ASCII value {expr}
+ rename({from}, {to})          Number  rename (move) file from {from} to {to}
 setline( {lnum}, {line})      Number  set line {lnum} to {line}
 strftime( {format}[, {time}]) String  time in specified format
 strlen( {expr})                       Number  length of the String {expr}
***************
*** 688,695 ****
               to avoid triggering the FileType event again in the scripts
               that detect the file type. |FileType|

!                                                       *escape()*
! escape({string}, {chars})
               Escape the characters in {chars} that occur in {string} with a
               backslash.  Example:
 >                     :echo escape('c:\program files\vim', ' \')
--- 689,695 ----
               to avoid triggering the FileType event again in the scripts
               that detect the file type. |FileType|

! escape({string}, {chars})                             *escape()*
               Escape the characters in {chars} that occur in {string} with a
               backslash.  Example:
 >                     :echo escape('c:\program files\vim', ' \')
***************
*** 1102,1107 ****
--- 1102,1113 ----
               value {expr}.  Examples:
 >                     nr2char(64)             returns "@"
 >                     nr2char(32)             returns " "
+
+ rename({from}, {to})                                  *rename()*
+               Rename the file by the name {from} to the name {to}.  This
+               should also work to move files across file systems.  The
+               result is a Number, which is 0 if the file was renamed
+               successfully, and non-zero when the renaming failed.

                                                       *setline()*
 setline({lnum}, {line})
*** ../vim-5.5a.2/runtime/vimrc_example.vim     Mon Aug 30 10:41:16 1999
--- runtime/vimrc_example.vim   Wed Sep  1 17:34:55 1999
***************
*** 1,7 ****
 " An example for a vimrc file.
 "
 " Maintainer: Bram Moolenaar <[email protected]>
! " Last change:        1999 Aug 29
 "
 " To use it, copy it to
 "     for Unix and OS/2:  ~/.vimrc
--- 1,7 ----
 " An example for a vimrc file.
 "
 " Maintainer: Bram Moolenaar <[email protected]>
! " Last change:        1999 Sep 01
 "
 " To use it, copy it to
 "     for Unix and OS/2:  ~/.vimrc
***************
*** 17,28 ****
 set history=50                " keep 50 lines of command line history
 set ruler             " show the cursor position all the time

- " Only do this part when compiled with support for autocommands.
- if has("autocmd")
-   " In text files, always limit the width of text to 78 characters
-   autocmd BufRead *.txt set tw=78
- endif
-
 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
 " let &guioptions = substitute(&guioptions, "t", "", "g")

--- 17,22 ----
***************
*** 36,42 ****
--- 30,41 ----
   set hlsearch
 endif

+ " Only do this part when compiled with support for autocommands.
 if has("autocmd")
+
+  " In text files, always limit the width of text to 78 characters
+  autocmd BufRead *.txt set tw=78
+
  augroup cprog
   " Remove all cprog autocommands
   au!
***************
*** 77,98 ****

   " After writing compressed file: Compress written file with "cmd"
   fun! GZIP_write(cmd)
!     !mv <afile> <afile>:r
!     execute "!" . a:cmd . " <afile>:r"
   endfun

   " Before appending to compressed file: Uncompress file with "cmd"
   fun! GZIP_appre(cmd)
     execute "!" . a:cmd . " <afile>"
!     !mv <afile>:r <afile>
   endfun

  augroup END
- endif

! " Only do this part when compiled with support for autocommands.
! if has("autocmd")
   " When editing a file, always jump to the last cursor position.
   " This must be after the uncompress commands.
!   autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif
! endif
--- 76,100 ----

   " After writing compressed file: Compress written file with "cmd"
   fun! GZIP_write(cmd)
!     if rename(expand("<afile>"), expand("<afile>:r")) == 0
!       execute "!" . a:cmd . " <afile>:r"
!     endif
   endfun

   " Before appending to compressed file: Uncompress file with "cmd"
   fun! GZIP_appre(cmd)
     execute "!" . a:cmd . " <afile>"
!     call rename(expand("<afile>:r"), expand("<afile>"))
   endfun

  augroup END

!  " This is disabled, because it changes the jumplist.  Can't use CTRL-O to go
!  " back to positions in previous files more than once.
!  if 0
   " When editing a file, always jump to the last cursor position.
   " This must be after the uncompress commands.
!    autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif
!  endif
!
! endif " has("autocmd")
*** ../vim-5.5a.2/src/version.c Wed Sep  1 17:48:59 1999
--- src/version.c       Wed Sep  1 17:52:55 1999
***************
*** 420,420 ****
--- 420,421 ----
 {   /* Add new patch number below this line */
+     3,

--
WOMAN:   King of the who?
ARTHUR:  The Britons.
WOMAN:   Who are the Britons?
ARTHUR:  Well, we all are. we're all Britons and I am your king.
                                 The Quest for the Holy Grail (Monty Python)

--/-/---- Bram Moolenaar ---- [email protected] ---- [email protected] ---\-\--
 \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /