1+ " Copyright (c) 1998-2001
2+ " Michael Sharpe <feline@irendi.com>
3+ "
4+ " We grant permission to use, copy modify, distribute, and sell this
5+ " software for any purpose without fee, provided that the above copyright
6+ " notice and this text are not removed. We make no guarantee about the
7+ " sutability of this software for any purpose and we are not liable
8+ " for any damages resulting from its use. Further, we are under no
9+ " obligation to maintain or extend this software. It is provided on an
10+ " "as is" basis without any express or implied warranty.
11+
112" Function : AlternateFile (PUBLIC)
213" Purpose : Opens a new buffer by looking at the extension of the current
314" buffer and finding the corresponding file. E.g. foo.c <--> foo.h
415" Args : accepts one argument. If present it used the argument as the new
516" extension.
617" Returns : nothing
7- " Author : Michael Sharpe ( feline@irendi.com)
18+ " Author : Michael Sharpe < feline@irendi.com>
819func ! AlternateFile (splitWindow, ... )
920 let baseName = expand (" %<" )
1021 " before 5.6 if (a:1 != "") is needed instead of the following...
@@ -13,19 +24,47 @@ func! AlternateFile(splitWindow, ...)
1324 else
1425 let currentFile = expand (" %" )
1526 let extension = fnamemodify (currentFile," :e" )
16- if (extension == " c" )
27+ if (extension == " c" )
1728 let newFilename = baseName." .h"
1829 elseif (extension == " cpp" )
1930 let newFilename = baseName . " .h"
31+ elseif (extension == " cc" )
32+ let newFilename = baseName . " .h"
33+ elseif (extension == " C" )
34+ let newFilename = baseName . " .h"
35+ elseif (extension == " cxx" )
36+ let newFilename = baseName . " .h"
2037 elseif (extension == " psl" )
2138 let newFilename = baseName . " .ph"
2239 elseif (extension == " ph" )
2340 let newFilename = baseName . " .psl"
2441 elseif (extension == " h" )
42+ " check to see if a .c file exists
2543 let newFilename = baseName . " .c"
2644 let fileExistsCheck = filereadable (newFilename)
2745 if (fileExistsCheck == 0 )
46+ " no .c try for a .cpp
2847 let newFilename = baseName . " .cpp"
48+ let fileExistsCheck = filereadable (newFilename)
49+ if (fileExistsCheck == 0 )
50+ " no .c or .cpp try for a .cc
51+ let newFilename = baseName . " .cc"
52+ let fileExistsCheck = filereadable (newFilename)
53+ if (fileExistsCheck == 0 )
54+ " no .c, .cpp or .cc try for a .C
55+ let newFilename = baseName . " .C"
56+ let fileExistsCheck = filereadable (newFilename)
57+ if (fileExistsCheck == 0 )
58+ " no .c, .cpp, .cc or .C try for a .cxx
59+ let newFilename = baseName . " .cxx"
60+ let fileExistsCheck = filereadable (newFilename)
61+ if (fileExistsCheck == 0 )
62+ " no .c, .cpp, .cc, .C or .cxx exists default to .cpp
63+ let newFilename = baseName . " .cpp"
64+ endif
65+ endif
66+ endif
67+ endif
2968 endif
3069 else
3170 echo " AlternameFile: unknown extension"
@@ -37,6 +76,7 @@ endfunc
3776comm! -nargs =? A call AlternateFile (0 , <f-args> )
3877comm! -nargs =? AS call AlternateFile (1 , <f-args> )
3978
79+
4080" Function : FindOrCreateBuffer (PRIVATE)
4181" Purpose : searches the buffer list (:ls) for the specified filename. If
4282" found, checks the window list for the buffer. If the buffer is in
@@ -46,7 +86,7 @@ comm! -nargs=? AS call AlternateFile(1, <f-args>)
4686" Args : filename (IN) -- the name of the file
4787" doSplit (IN) -- indicates whether the window should be split
4888" Returns : nothing
49- " Author : Michael Sharpe ( feline@irendi.com)
89+ " Author : Michael Sharpe < feline@irendi.com>
5090function ! FindOrCreateBuffer (filename, doSplit)
5191 " Check to see if the buffer is already open before re-opening it.
5292 let bufName = bufname (a: filename )
0 commit comments