PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/extman/scite_lua/switch_headers.lua

http://github.com/davidm/lua-inspect
Lua | 37 lines | 33 code | 3 blank | 1 comment | 7 complexity | 272b9acb996aa2ac05de57938b56cd56 MD5 | raw file
 1-- toggles between C++ source files and corresponding header files
 2scite_Command('Switch Source/Header|switch_source_header|*.c|Shift+Ctrl+H')
 3local cpp_exts = {'cpp','cxx','c++','c'}
 4local hpp_exts = {'h','hpp'}
 5
 6local function within(list,val)
 7  for i,v in list do
 8     if val == v then return true end
 9  end
10  return false
11end
12
13local function does_exist(basename,extensions)
14  for i,ext in extensions do
15    local f = basename..'.'..ext
16    if scite_FileExists(f) then return f end
17  end
18  return nil
19end
20
21function switch_source_header()
22   local file = props['FilePath']
23   local ext = props['FileExt']
24   local basename = props['FileDir']..'/'..props['FileName']
25   if within(cpp_exts,ext) then
26      other = does_exist(basename,hpp_exts)
27   elseif within(hpp_exts,ext) then
28      other = does_exist(basename,cpp_exts)
29   else
30      print('not a C++ file',file); return
31   end
32   if not other then 
33      print('source/header does not exist',file)
34   else
35      scite.Open(other)
36   end
37 end