From 4ba7c7a2c4152e603b7c58b2a3def2820c04c77b Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 1 Mar 2017 16:14:02 +0300 Subject: [PATCH 1/3] rc: POSIX and cosmetic fixes in the `spell` script` --- rc/base/spell.kak | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rc/base/spell.kak b/rc/base/spell.kak index ab81f67b..865c3ec9 100644 --- a/rc/base/spell.kak +++ b/rc/base/spell.kak @@ -16,9 +16,9 @@ Formats of language supported: } %sh{ if [ $# -ge 1 ]; then - if [ ${#1} -ne 2 -a ${#1} -ne 5 ]; then + if [ ${#1} -ne 2 ] && [ ${#1} -ne 5 ]; then echo 'echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)' - rm -r "$(dirname "$kak_opt_spell_tmp_file")" + rm -rf "$(dirname "$kak_opt_spell_tmp_file")" exit 1 else options="-l '$1'" @@ -50,18 +50,18 @@ Formats of language supported: printf 'set "buffer=%s" spell_regions %%{%s}' "${kak_bufname}" "${regions}" \ | kak -p "${kak_session}" } - rm -r $(dirname "$kak_opt_spell_tmp_file") + rm -rf $(dirname "$kak_opt_spell_tmp_file") } /dev/null 2>&1 & } } -def spell-replace %{%sh{ - suggestions=$(echo "$kak_selection" | aspell -a | grep '^&' | cut -d: -f2) - menu=$(echo "${suggestions#?}" | awk -F', ' ' - { - for (i=1; i<=NF; i++) - printf "%s", "%{"$i"}" "%{exec -itersel c"$i"be}" - } +def spell-replace %{ %sh{ + suggestions=$(printf %s "$kak_selection" | aspell -a | grep '^&' | cut -d: -f2) + menu=$(printf %s "${suggestions#?}" | awk -F', ' ' + { + for (i=1; i<=NF; i++) + printf "%s", "%{"$i"}" "%{exec -itersel c"$i"be}" + } ') - printf '%s\n' "try %{ menu -auto-single $menu }" -}} + printf 'try %%{ menu -auto-single %s }' "${menu}" +} } From 947b518f035e800b22f7a6217b63477f35070eff Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 1 Mar 2017 16:14:47 +0300 Subject: [PATCH 2/3] rc: add a `spell-next` command --- rc/base/spell.kak | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/rc/base/spell.kak b/rc/base/spell.kak index 865c3ec9..8be4f12e 100644 --- a/rc/base/spell.kak +++ b/rc/base/spell.kak @@ -55,6 +55,50 @@ Formats of language supported: } } +def spell-next %{ %sh{ + anchor_line="${kak_selection_desc%%.*}" + anchor_col="${kak_selection_desc%%,*}" + anchor_col="${anchor_col##*.}" + + start_first="${kak_opt_spell_regions#*:}" + start_first="${start_first%%|*}" + + find_next_word_desc() { + ## XXX: the `spell` command adds sorted selection descriptions to the range + printf %s\\n "${1}" \ + | sed -e 's/^[0-9]*://' -e 's/|[^:]*//g' -e 's/,/ /g' \ + | tr ':' '\n' \ + | while read -r start end; do + start_line="${start%.*}" + start_col="${start#*.}" + end_line="${end%.*}" + end_col="${end#*.}" + + if [ "${start_line}" -lt "${anchor_line}" ]; then + continue + elif [ "${start_line}" -eq "${anchor_line}" ] \ + && [ "${start_col}" -le "${anchor_col}" ]; then + continue + fi + + printf 'select %s,%s\n' "${start}" "${end}" + break + done + } + + # no selection descriptions are in `spell_regions` + if ! expr "${start_first}" : '[0-9][0-9]*\.[0-9][0-9]*,[0-9][0-9]*\.[0-9]' >/dev/null; then + exit + fi + + next_word_desc=$(find_next_word_desc "${kak_opt_spell_regions}") + if [ -n "${next_word_desc}" ]; then + printf %s\\n "${next_word_desc}" + else + printf 'select %s\n' "${start_first}" + fi +} } + def spell-replace %{ %sh{ suggestions=$(printf %s "$kak_selection" | aspell -a | grep '^&' | cut -d: -f2) menu=$(printf %s "${suggestions#?}" | awk -F', ' ' From aecc0fbb0f0cfcfec749c2ee873f33b8d7ba1822 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 1 Mar 2017 22:16:35 +0300 Subject: [PATCH 3/3] src: Fix the string conversion of range faces Fixes #1250 --- src/display_buffer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display_buffer.cc b/src/display_buffer.cc index e6c74c8b..d24d65f2 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -14,7 +14,7 @@ String option_to_string(BufferRange range) { return format("{}.{},{}.{}", range.begin.line+1, range.begin.column+1, - range.end.line, range.end.column); + range.end.line+1, range.end.column); } void option_from_string(StringView str, BufferRange& opt)