16
16
if exists (" loaded_alternateFile" )
17
17
finish
18
18
endif
19
+ if (v: progname == " ex" )
20
+ finish
21
+ endif
19
22
let loaded_alternateFile = 1
20
23
21
24
" setup the default set of alternate extensions. The user can override in thier
@@ -47,6 +50,7 @@ function! <SID>AddAlternateExtensionMapping(extension, alternates)
47
50
" This code handles extensions which contains a dot. exists() fails with
48
51
" such names.
49
52
let v: errmsg = " "
53
+ " FIXME this line causes ex to return 1 instead of 0 for some reason??
50
54
silent ! echo g: alternateExtensions_ {a: extension }
51
55
if (v: errmsg != " " )
52
56
let g: alternateExtensions_ {a: extension } = a: alternates
@@ -58,6 +62,7 @@ function! <SID>AddAlternateExtensionMapping(extension, alternates)
58
62
endif
59
63
endfunction
60
64
65
+
61
66
" Add all the default extensions
62
67
" Mappings for C and C++
63
68
call <SID> AddAlternateExtensionMapping (' h' ," c,cpp,cxx,cc,CC" )
@@ -233,6 +238,47 @@ function! <SID>FindFileInSearchPath(fileName, pathList, relPathBase)
233
238
return filepath
234
239
endfunction
235
240
241
+ " Function : FindFileInSearchPathEx (PRIVATE)
242
+ " Purpose : Searches for a file in the search path list
243
+ " Args : filename -- name of the file to search for
244
+ " pathList -- the path list to search
245
+ " relPathBase -- the path which relative paths are expanded from
246
+ " count -- find the count'th occurence of the file on the path
247
+ " Returns : An expanded filename if found, the empty string otherwise
248
+ " Author : Michael Sharpe ([email protected] )
249
+ " History : Based on <SID>FindFileInSearchPath() but with extensions
250
+ function ! <SID> FindFileInSearchPathEx (fileName, pathList, relPathBase, count )
251
+ let filepath = " "
252
+ let m = 1
253
+ let spath = " "
254
+ let pathListLen = strlen (a: pathList )
255
+ if (pathListLen > 0 )
256
+ while (1 )
257
+ let pathSpec = <SID> GetNthItemFromList (a: pathList , m )
258
+ if (pathSpec != " " )
259
+ let path = <SID> ExpandAlternatePath (pathSpec, a: relPathBase )
260
+ if (spath != " " )
261
+ let spath = spath . ' ,'
262
+ endif
263
+ let spath = spath . path
264
+ else
265
+ break
266
+ endif
267
+ let m = m + 1
268
+ endwhile
269
+ endif
270
+
271
+ if (&path != " " )
272
+ if (spath != " " )
273
+ let spath = spath . ' ,'
274
+ endif
275
+ let spath = spath . &path
276
+ endif
277
+
278
+ let filepath = findfile (a: fileName , spath, a: count )
279
+ return filepath
280
+ endfunction
281
+
236
282
" Function : EnumerateFilesByExtension (PRIVATE)
237
283
" Purpose : enumerates all files by a particular list of alternate extensions.
238
284
" Args : path -- path of a file (not including the file)
@@ -412,11 +458,87 @@ function! AlternateFile(splitWindow, ...)
412
458
endif
413
459
endfunction
414
460
461
+ " Function : AlternateOpenFileUnderCursor (PUBLIC)
462
+ " Purpose : Opens file under the cursor
463
+ " Args : splitWindow -- indicates how to open the file
464
+ " Returns : Nothing
465
+ " Author : Michael Sharpe ([email protected] ) www.irendi.com
466
+ function ! AlternateOpenFileUnderCursor (splitWindow,... )
467
+ let cursorFile = (a: 0 > 0 ) ? a: 1 : expand (" <cfile>" )
468
+ let currentPath = expand (" %:p:h" )
469
+ let openCount = 1
470
+
471
+ let fileName = <SID> FindFileInSearchPathEx (cursorFile, g: alternateSearchPath , currentPath, openCount)
472
+ if (fileName != " " )
473
+ call <SID> FindOrCreateBuffer (fileName, a: splitWindow , 1 )
474
+ let b: openCount = openCount
475
+ let b: cursorFile = cursorFile
476
+ let b: currentPath = currentPath
477
+ else
478
+ echo " Can't find file"
479
+ endif
480
+ endfunction
481
+
482
+ " Function : AlternateOpenNextFile (PUBLIC)
483
+ " Purpose : Opens the next file corresponding to the search which found the
484
+ " current file
485
+ " Args : bang -- indicates what to do if the current file has not been
486
+ " saved
487
+ " Returns : nothing
488
+ " Author : Michael Sharpe ([email protected] ) www.irendi.com
489
+ function ! AlternateOpenNextFile (bang )
490
+ let cursorFile = " "
491
+ if (exists (" b:cursorFile" ))
492
+ let cursorFile = b: cursorFile
493
+ endif
494
+
495
+ let currentPath = " "
496
+ if (exists (" b:currentPath" ))
497
+ let currentPath = b: currentPath
498
+ endif
499
+
500
+ let openCount = 0
501
+ if (exists (" b:openCount" ))
502
+ let openCount = b: openCount + 1
503
+ endif
504
+
505
+ if (cursorFile != " " && currentPath != " " && openCount != 0 )
506
+ let fileName = <SID> FindFileInSearchPathEx (cursorFile, g: alternateSearchPath , currentPath, openCount)
507
+ if (fileName != " " )
508
+ call <SID> FindOrCreateBuffer (fileName, " n" .a: bang , 0 )
509
+ let b: openCount = openCount
510
+ let b: cursorFile = cursorFile
511
+ let b: currentPath = currentPath
512
+ else
513
+ let fileName = <SID> FindFileInSearchPathEx (cursorFile, g: alternateSearchPath , currentPath, 1 )
514
+ if (fileName != " " )
515
+ call <SID> FindOrCreateBuffer (fileName, " n" .a: bang , 0 )
516
+ let b: openCount = 1
517
+ let b: cursorFile = cursorFile
518
+ let b: currentPath = currentPath
519
+ else
520
+ echo " Can't find next file"
521
+ endif
522
+ endif
523
+ endif
524
+ endfunction
525
+
526
+ comm! -nargs =? - bang IH call AlternateOpenFileUnderCursor (" n<bang>" , <f-args> )
527
+ comm! -nargs =? - bang IHS call AlternateOpenFileUnderCursor (" h<bang>" , <f-args> )
528
+ comm! -nargs =? - bang IHV call AlternateOpenFileUnderCursor (" v<bang>" , <f-args> )
529
+ comm! -nargs =? - bang IHT call AlternateOpenFileUnderCursor (" t<bang>" , <f-args> )
530
+ comm! -nargs =? - bang IHN call AlternateOpenNextFile (" <bang>" )
531
+ imap <Leader> ih <ESC> :IHS<CR>
532
+ nmap <Leader> ih :IHS<CR>
533
+ imap <Leader> is <ESC> :IHS<CR> :A<CR>
534
+ nmap <Leader> is :IHS<CR> :A<CR>
535
+ imap <Leader> ihn <ESC> :IHN<CR>
536
+ nmap <Leader> ihn :IHN<CR>
537
+
415
538
" function! <SID>PrintList(theList)
416
539
" let n = 1
417
540
" let oneFile = <SID>GetNthItemFromList(a:theList, n)
418
541
" while (oneFile != "")
419
- " Decho "list[".n."]=".oneFile
420
542
" let n = n + 1
421
543
" let oneFile = <SID>GetNthItemFromList(a:theList, n)
422
544
" endwhile
@@ -669,7 +791,7 @@ endfunction
669
791
" Function : EqualFilePaths (PRIVATE)
670
792
" Purpose : Compares two paths. Do simple string comparison anywhere but on
671
793
" Windows. On Windows take into account that file paths could differ
672
- " in usage of separators and the fact that case does not metter .
794
+ " in usage of separators and the fact that case does not matter .
673
795
" "c:\WINDOWS" is the same path as "c:/windows". has("win32unix") Vim
674
796
" version does not count as one having Windows path rules.
675
797
" Args : path1 (IN) -- first path
0 commit comments