cpp.kak: smarter alt command

This commit is contained in:
Maxime Coste 2012-09-06 13:38:51 +02:00
parent 41b0751a5d
commit ddd5236b08

View File

@ -33,17 +33,19 @@ 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> 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>
} }
def alt %{ edit %sh{ def alt %{ %sh{
shopt -s extglob
case ${kak_bufname} in case ${kak_bufname} in
*.c) echo ${kak_bufname/%c/h} ;; *.c|*.cc|*.cpp|*.cxx|*.C)
*.cc) echo ${kak_bufname/%cc/hh} ;; altname=$(ls -1 "${kak_bufname%.*}".@(h|hh|hpp|hxx|H) 2> /dev/null | head -n 1)
*.cpp) echo ${kak_bufname/%cpp/hpp} ;; ;;
*.cxx) echo ${kak_bufname/%cxx/hxx} ;; *.h|*.hh|*.hpp|*.hxx|*.H)
*.C) echo ${kak_bufname/%C/H} ;; altname=$(ls -1 "${kak_bufname%.*}".@(c|cc|cpp|cxx|C) 2> /dev/null | head -n 1)
*.h) echo ${kak_bufname/%h/c} ;; ;;
*.hh) echo ${kak_bufname/%hh/cc} ;;
*.hpp) echo ${kak_bufname/%hpp/cpp} ;;
*.hxx) echo ${kak_bufname/%hxx/cxx} ;;
*.H) echo ${kak_bufname/%H/C} ;;
esac esac
}} if [[ -e ${altname} ]]; then
echo edit "'${altname}'"
else
echo echo "'alternative file not found'"
fi
}}