diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-12-25 04:00:07 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-12-25 04:02:46 +0100 |
commit | 275789f22eb68aab34161c35a7f084e638e94481 (patch) | |
tree | fde11be43d9fd547a81ef4cebf079d994ee289ef /dotvimrc | |
parent | a36f88a6aa167a2b450178a80adf11d7ded2f0af (diff) | |
download | vimrc-275789f22eb68aab34161c35a7f084e638e94481.tar.gz vimrc-275789f22eb68aab34161c35a7f084e638e94481.tar.bz2 vimrc-275789f22eb68aab34161c35a7f084e638e94481.zip |
Improve c/h flip
Diffstat (limited to 'dotvimrc')
-rw-r--r-- | dotvimrc | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -212,24 +212,24 @@ def loadfile(filename): currentfile = vim.eval('expand("%")') -if currentfile.endswith(".c"): - loadfile(currentfile[:-2] + ".h") -elif currentfile.endswith(".h"): - basename = currentfile[:-2] - if os.path.exists(basename + ".cpp"): - loadfile(basename + ".cpp") - else: - loadfile(basename + ".c") -elif currentfile.endswith(".cpp"): - basename = currentfile[:-4] - if os.path.exists(basename + ".h"): - loadfile(basename + ".h") - else: - loadfile(basename + ".hpp") -elif currentfile.endswith(".hpp"): - basename = currentfile[:-4] - loadfile(basename + ".cpp") - +c_exts = ["c", "cpp", "cc"] +h_exts = ["h", "hpp"] + +currentfile_split = currentfile.split(".") +if len(currentfile_split) > 0: + ext = currentfile_split[-1] + basename = currentfile[:-(1+len(ext))] + + if ext in c_exts: + for h_ext in h_exts: + h_filename = basename + "." + h_ext + if os.path.exists(h_filename): + loadfile(h_filename) + elif ext in h_exts: + for c_ext in c_exts: + c_filename = basename + "." + c_ext + if os.path.exists(c_filename): + loadfile(c_filename) endpython endfun |