/extman/scite_lua/switch_headers.lua

http://github.com/davidm/lua-inspect · Lua · 37 lines · 33 code · 3 blank · 1 comment · 8 complexity · 272b9acb996aa2ac05de57938b56cd56 MD5 · raw file

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