0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

updated for version 7.0167

This commit is contained in:
Bram Moolenaar 2005-12-11 21:29:51 +00:00
parent cdbac1ee33
commit 292ad19e92
4 changed files with 139 additions and 14 deletions

View File

@ -12,11 +12,19 @@ The other files contain some handy utilities. They also serve as examples for
how to use Vi and Vim functionality. how to use Vi and Vim functionality.
dvorak for when you use a Dvorak keyboard dvorak for when you use a Dvorak keyboard
justify.vim user function for justifying text justify.vim user function for justifying text
matchit.vim + matchit.txt make % match if-fi, HTML tags, and much more matchit.vim + matchit.txt make % match if-fi, HTML tags, and much more
less.sh + less.vim make Vim work like less (or more) less.sh + less.vim make Vim work like less (or more)
shellmenu.vim menus for editing shell scripts in the GUI version shellmenu.vim menus for editing shell scripts in the GUI version
swapmous.vim swap left and right mouse buttons swapmous.vim swap left and right mouse buttons
editexisting.vim when editing a file that is already edited with
another Vim instance
This one is only for Unix. It can be found in the extra archive: This one is only for Unix. It can be found in the extra archive:
file_select.vim macros that make a handy file selector file_select.vim macros that make a handy file selector

View File

@ -0,0 +1,97 @@
" Vim Plugin: Edit the file with an existing Vim if possible
" Maintainer: Bram Moolenaar
" Last Change: 2005 Dec 11
" This is a plugin, drop it in your (Unix) ~/.vim/plugin or (Win32)
" $VIM/vimfiles/plugin directory.
" This plugin serves two purposes:
" 1. On startup, if we were invoked with one file name argument and the file
" is not modified then try to find another Vim instance that is editing
" this file. If there is one then bring it to the foreground and exit.
" 2. When a file is edited and a swap file exists for it, try finding that
" other Vim and bring it to the foreground. Requires Vim 7, because it
" uses the SwapExists autocommand event.
" Function that finds the Vim instance that is editing "filename" and brings
" it to the foreground.
func s:EditElsewhere(filename)
let fname_esc = substitute(a:filename, "'", "''", "g")
let servers = serverlist()
while servers != ''
" Get next server name in "servername"; remove it from "servers".
let i = match(servers, "\n")
if i == -1
let servername = servers
let servers = ''
else
let servername = strpart(servers, 0, i)
let servers = strpart(servers, i + 1)
endif
" Skip ourselves.
if servername ==? v:servername
continue
endif
" Check if this server is editing our file.
if remote_expr(servername, "bufloaded('" . fname_esc . "')")
" Yes, bring it to the foreground.
if has("win32")
call remote_foreground(servername)
endif
call remote_expr(servername, "foreground()")
" Make sure the file is visible in a window (not hidden).
" If v:swapcommand exists and is set, send it to the server.
if exists("v:swapcommand")
let c = substitute(v:swapcommand, "'", "''", "g")
call remote_expr(servername, "EditExisting('" . fname_esc . "', '" . c . "')")
else
call remote_expr(servername, "EditExisting('" . fname_esc . "', '')")
endif
if !(has('vim_starting') && has('gui_running') && has('gui_win32'))
" Tell the user what is happening. Not when the GUI is starting
" though, it would result in a message box.
echomsg "File is being edited by " . servername
sleep 2
endif
return 'q'
endif
endwhile
return ''
endfunc
" When the plugin is loaded and there is one file name argument: Find another
" Vim server that is editing this file right now.
if argc() == 1 && !&modified
if s:EditElsewhere(expand("%:p")) == 'q'
quit
endif
endif
" Setup for handling the situation that an existing swap file is found.
try
au! SwapExists * let v:swapchoice = s:EditElsewhere(expand("<afile>:p"))
catch
" Without SwapExists we don't do anything for ":edit" commands
endtry
" Function used on the server to make the file visible and possibly execute a
" command.
func! EditExisting(fname, command)
let n = bufwinnr(a:fname)
if n > 0
exe n . "wincmd w"
else
exe "split " . escape(a:fname, ' #%"|')
endif
if a:command != ''
exe "normal " . a:command
endif
redraw
endfunc

View File

@ -2534,15 +2534,16 @@ set_file_time(fname, atime, mtime)
#endif #endif
/* /*
* buf_write() - write to file 'fname' lines 'start' through 'end' * buf_write() - write to file "fname" lines "start" through "end"
* *
* We do our own buffering here because fwrite() is so slow. * We do our own buffering here because fwrite() is so slow.
* *
* If forceit is true, we don't care for errors when attempting backups (jw). * If "forceit" is true, we don't care for errors when attempting backups.
* In case of an error everything possible is done to restore the original file. * In case of an error everything possible is done to restore the original
* But when forceit is TRUE, we risk loosing it. * file. But when "forceit" is TRUE, we risk loosing it.
* When reset_changed is TRUE and start == 1 and end == *
* curbuf->b_ml.ml_line_count, reset curbuf->b_changed. * When "reset_changed" is TRUE and "append" == FALSE and "start" == 1 and
* "end" == curbuf->b_ml.ml_line_count, reset curbuf->b_changed.
* *
* This function must NOT use NameBuff (because it's called by autowrite()). * This function must NOT use NameBuff (because it's called by autowrite()).
* *
@ -2557,7 +2558,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
linenr_T start, end; linenr_T start, end;
exarg_T *eap; /* for forced 'ff' and 'fenc', can be exarg_T *eap; /* for forced 'ff' and 'fenc', can be
NULL! */ NULL! */
int append; int append; /* append to the file */
int forceit; int forceit;
int reset_changed; int reset_changed;
int filtering; int filtering;
@ -2652,7 +2653,8 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
* If there is no file name yet, use the one for the written file. * If there is no file name yet, use the one for the written file.
* BF_NOTEDITED is set to reflect this (in case the write fails). * BF_NOTEDITED is set to reflect this (in case the write fails).
* Don't do this when the write is for a filter command. * Don't do this when the write is for a filter command.
* Only do this when 'cpoptions' contains the 'f' flag. * Don't do this when appending.
* Only do this when 'cpoptions' contains the 'F' flag.
*/ */
if (reset_changed if (reset_changed
&& whole && whole
@ -2662,6 +2664,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
#endif #endif
&& buf->b_ffname == NULL && buf->b_ffname == NULL
&& !filtering && !filtering
&& (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL)
&& vim_strchr(p_cpo, CPO_FNAMEW) != NULL) && vim_strchr(p_cpo, CPO_FNAMEW) != NULL)
{ {
#ifdef FEAT_AUTOCMD #ifdef FEAT_AUTOCMD
@ -2826,9 +2829,12 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
{ {
/* Assume the buffer was written, update the timestamp. */ /* Assume the buffer was written, update the timestamp. */
ml_timestamp(buf); ml_timestamp(buf);
buf->b_flags &= ~BF_WRITE_MASK; if (append)
buf->b_flags &= ~BF_NEW;
else
buf->b_flags &= ~BF_WRITE_MASK;
} }
if (reset_changed && buf->b_changed if (reset_changed && buf->b_changed && !append
&& (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)) && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL))
/* Buffer still changed, the autocommands didn't work /* Buffer still changed, the autocommands didn't work
* properly. */ * properly. */
@ -4232,7 +4238,7 @@ restore_backup:
/* When written everything correctly: reset 'modified'. Unless not /* When written everything correctly: reset 'modified'. Unless not
* writing to the original file and '+' is not in 'cpoptions'. */ * writing to the original file and '+' is not in 'cpoptions'. */
if (reset_changed && whole if (reset_changed && whole && !append
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
&& !write_info.bw_conv_error && !write_info.bw_conv_error
#endif #endif
@ -4250,7 +4256,10 @@ restore_backup:
if (overwriting) if (overwriting)
{ {
ml_timestamp(buf); ml_timestamp(buf);
buf->b_flags &= ~BF_WRITE_MASK; if (append)
buf->b_flags &= ~BF_NEW;
else
buf->b_flags &= ~BF_WRITE_MASK;
} }
/* /*

View File

@ -843,11 +843,22 @@ do_tag(tag, type, count, forceit, verbose)
} }
} }
#ifdef FEAT_AUTOCMD
/* Let the SwapExists event know what tag we are jumping to. */
vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name);
set_vim_var_string(VV_SWAPCOMMAND, IObuff, -1);
#endif
/* /*
* Jump to the desired match. * Jump to the desired match.
*/ */
if (jumpto_tag(matches[cur_match], forceit, type != DT_CSCOPE) i = jumpto_tag(matches[cur_match], forceit, type != DT_CSCOPE);
== NOTAGFILE)
#ifdef FEAT_AUTOCMD
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
#endif
if (i == NOTAGFILE)
{ {
/* File not found: try again with another matching tag */ /* File not found: try again with another matching tag */
if ((type == DT_PREV && cur_match > 0) if ((type == DT_PREV && cur_match > 0)