aboutsummaryrefslogtreecommitdiffstats
path: root/dotvimrc
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-12-25 04:00:07 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-12-25 04:02:46 +0100
commit275789f22eb68aab34161c35a7f084e638e94481 (patch)
treefde11be43d9fd547a81ef4cebf079d994ee289ef /dotvimrc
parenta36f88a6aa167a2b450178a80adf11d7ded2f0af (diff)
downloadvimrc-275789f22eb68aab34161c35a7f084e638e94481.tar.gz
vimrc-275789f22eb68aab34161c35a7f084e638e94481.tar.bz2
vimrc-275789f22eb68aab34161c35a7f084e638e94481.zip
Improve c/h flip
Diffstat (limited to 'dotvimrc')
-rw-r--r--dotvimrc36
1 files changed, 18 insertions, 18 deletions
diff --git a/dotvimrc b/dotvimrc
index 083c95e..e0121fe 100644
--- a/dotvimrc
+++ b/dotvimrc
@@ -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