summaryrefslogtreecommitdiff
path: root/src/rc/cpp.kak
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-03-22 14:30:09 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-03-22 14:30:09 +0100
commitd04a6b1e183c5bfbc0958d51d9802ea526568792 (patch)
tree88db9713a2b13bfad135bf5901656cbcff658aac /src/rc/cpp.kak
parent07866e6ae96ce8ebd1ae30bcf92dcf021687ce58 (diff)
cpp.kak: alt supports an alt_dirs options for directories to search
Diffstat (limited to 'src/rc/cpp.kak')
-rw-r--r--src/rc/cpp.kak18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak
index d6af08b0..372a02f9 100644
--- a/src/rc/cpp.kak
+++ b/src/rc/cpp.kak
@@ -34,14 +34,26 @@ hook global BufNew .*\.(h|hh|hpp|hxx|H) %{
exec ggi<c-r>%<ret><esc>ggxs\.<ret>c_<esc><space>A_INCLUDED<esc>ggxyppI#ifndef<space><esc>jI#define<space><esc>jI#endif<space>//<space><esc>O<esc>
}
+decl str-list alt_dirs ".,.."
+
def alt %{ %sh{
shopt -s extglob
- case ${kak_bufname} in
+ alt_dirs=${kak_opt_alt_dirs/,/ }
+ file=$(basename ${kak_bufname})
+ dir=$(dirname ${kak_bufname})
+
+ case ${file} in
*.c|*.cc|*.cpp|*.cxx|*.C)
- altname=$(ls -1 "${kak_bufname%.*}".@(h|hh|hpp|hxx|H) 2> /dev/null | head -n 1)
+ for alt_dir in ${alt_dirs}; do
+ altname=$(ls -1 "${dir}/${alt_dir}/${file%.*}".@(h|hh|hpp|hxx|H) 2> /dev/null | head -n 1)
+ [[ -n ${altname} ]] && break
+ done
;;
*.h|*.hh|*.hpp|*.hxx|*.H)
- altname=$(ls -1 "${kak_bufname%.*}".@(c|cc|cpp|cxx|C) 2> /dev/null | head -n 1)
+ for alt_dir in ${alt_dirs}; do
+ altname=$(ls -1 "${dir}/${alt_dir}/${file%.*}".@(c|cc|cpp|cxx|C) 2> /dev/null | head -n 1)
+ [[ -n ${altname} ]] && break
+ done
;;
esac
if [[ -e ${altname} ]]; then