From d5726c0cfd3f4e872c6f85c6596ecb78614589f2 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Mon, 15 May 2017 22:27:22 +0300 Subject: [PATCH 1/3] kakrc: Simplify and optimize the autoload function --- share/kak/kakrc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/share/kak/kakrc b/share/kak/kakrc index 4b234fc3b..7a9f1692c 100644 --- a/share/kak/kakrc +++ b/share/kak/kakrc @@ -24,17 +24,8 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ %sh{ autoload_directory() { - dir=$1 - for rcfile in ${dir}/*.kak; do - if [ -f "$rcfile" ]; then - echo "try %{ source '${rcfile}' } catch %{ echo -debug Autoload: could not load '${rcfile}' }"; - fi - done - for subdir in ${dir}/*; do - if [ -d "$subdir" ]; then - autoload_directory $subdir - fi - done + find -L "$1" -type f -name '*\.kak' \ + -exec printf 'try %%{ source "%s" } catch %%{ echo -debug Autoload: could not load "%s" }\n' '{}' '{}' \; } localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak From 56837eaecee6da148677f56a34fe8de797063ace Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 16 May 2017 15:18:45 +0300 Subject: [PATCH 2/3] rc: Use POSIX `command -v` instead of `which` --- rc/base/x11.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/base/x11.kak b/rc/base/x11.kak index 0583d1836..61a065fe6 100644 --- a/rc/base/x11.kak +++ b/rc/base/x11.kak @@ -11,7 +11,7 @@ decl str termcmd %sh{ 'gnome-terminal -e ' \ 'xfce4-terminal -e ' ; do terminal=${termcmd%% *} - if which $terminal > /dev/null 2>&1; then + if command -v $terminal >/dev/null 2>&1; then printf %s\\n "'$termcmd'" exit fi From d59bafa2c1ee6c8175fb1bcb1c0abf03407f0f84 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 16 May 2017 15:34:29 +0300 Subject: [PATCH 3/3] rc: Simplify and optimize the `alt` command --- rc/core/c-family.kak | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 26d3222cf..ea4351ec0 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -283,30 +283,35 @@ def -hidden c-family-insert-include-guards %{ hook global BufNewFile .*\.(h|hh|hpp|hxx|H) c-family-insert-include-guards -decl str-list alt_dirs ".;.." +decl str-list alt_dirs ".:.." def c-family-alternative-file -docstring "Jump to the alternate file (header/implementation)" %{ %sh{ - alt_dirs=$(printf %s\\n "${kak_opt_alt_dirs}" | sed -e 's/;/ /g') - file=$(basename "${kak_buffile}") + alt_dirs=$(printf %s\\n "${kak_opt_alt_dirs}" | tr ':' '\n') + file="${kak_buffile##*/}" + file_noext="${file%.*}" dir=$(dirname "${kak_buffile}") case ${file} in *.c|*.cc|*.cpp|*.cxx|*.C|*.inl|*.m) for alt_dir in ${alt_dirs}; do for ext in h hh hpp hxx H; do - altname="${dir}/${alt_dir}/${file%.*}.${ext}" - [ -f ${altname} ] && break + altname="${dir}/${alt_dir}/${file_noext}.${ext}" + if [ -f ${altname} ]; then + printf 'edit %%{%s}\n' "${altname}" + exit + fi done - [ -f ${altname} ] && break done ;; *.h|*.hh|*.hpp|*.hxx|*.H) for alt_dir in ${alt_dirs}; do for ext in c cc cpp cxx C m; do - altname="${dir}/${alt_dir}/${file%.*}.${ext}" - [ -f ${altname} ] && break + altname="${dir}/${alt_dir}/${file_noext}.${ext}" + if [ -f ${altname} ]; then + printf 'edit %%{%s}\n' "${altname}" + exit + fi done - [ -f ${altname} ] && break done ;; *) @@ -314,9 +319,5 @@ def c-family-alternative-file -docstring "Jump to the alternate file (header/imp exit ;; esac - if [ -f ${altname} ]; then - printf %s\\n "edit '${altname}'" - else - echo "echo -color Error 'alternative file not found'" - fi + echo "echo -color Error 'alternative file not found'" }}