From ba3c7bab06afce8fd18f0ace381a34937a251f5b Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 14 Jul 2016 16:40:08 +0300 Subject: [PATCH 1/3] Fix paragraph wrapping in the autowrap script --- rc/base/autowrap.kak | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/rc/base/autowrap.kak b/rc/base/autowrap.kak index 55c84f59..196431d9 100644 --- a/rc/base/autowrap.kak +++ b/rc/base/autowrap.kak @@ -7,14 +7,16 @@ decl bool autowrap_format_paragraph yes # Command to which the paragraphs to wrap will be passed, all occurences of '%c' are replaced with `autowrap_column` decl str autowrap_fmtcmd 'fold -s -w %c' -def -hidden autowrap-cursor %{ eval -draft %{ +def -hidden autowrap-cursor %{ eval -save-regs '/"|^@m' %{ try %{ ## if the line isn't too long, do nothing - exec -draft "^[^\n]{%opt{autowrap_column},}" + exec -draft "^[^\n]{%opt{autowrap_column},}[^\n]" try %{ + reg m "%val{selections_desc}" + ## if we're adding characters past the limit, just wrap them around - exec ".{%opt{autowrap_column},}1s(\h+)[^\h]+\'c" + exec ".{%opt{autowrap_column},}\h*[^\s]1s.{%opt{autowrap_column}}[^\h]*(\h+)c" } catch %{ ## if we're adding characters in the middle of a sentence, use ## the `fmtcmd` command to wrap the entire paragraph @@ -22,9 +24,12 @@ def -hidden autowrap-cursor %{ eval -draft %{ if [[ "${kak_opt_autowrap_format_paragraph}" = true ]] \ && [[ -n "${kak_opt_autowrap_fmtcmd}" ]]; then format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \ - | sed -e "s/%c/${kak_opt_autowrap_column}/g" \ - -e 's/ //g') - printf %s "exec -draft p|${format_cmd}" + | sed "s/%c/${kak_opt_autowrap_column}/g") + printf %s " + exec 'p|${format_cmd}' + try %{ exec s\h+$ d } + select '${kak_reg_m}' + " fi } } From 712c99059261e14d03105bbc755f55da16639001 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 14 Jul 2016 17:21:35 +0300 Subject: [PATCH 2/3] Fix the selection patterns on corner cases --- rc/base/autowrap.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/base/autowrap.kak b/rc/base/autowrap.kak index 196431d9..e925407f 100644 --- a/rc/base/autowrap.kak +++ b/rc/base/autowrap.kak @@ -16,7 +16,7 @@ def -hidden autowrap-cursor %{ eval -save-regs '/"|^@m' %{ reg m "%val{selections_desc}" ## if we're adding characters past the limit, just wrap them around - exec ".{%opt{autowrap_column},}\h*[^\s]1s.{%opt{autowrap_column}}[^\h]*(\h+)c" + exec -draft ".{%opt{autowrap_column}}\h*[^\s]*1s(\h+)[^\h]*\'c" } catch %{ ## if we're adding characters in the middle of a sentence, use ## the `fmtcmd` command to wrap the entire paragraph From 843d03f2e7ea9b0530cd435ccca3a236ed302594 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 14 Jul 2016 17:32:56 +0300 Subject: [PATCH 3/3] Disable automatic paragraph formatting by default, work around the lack of string refill in `fold` --- rc/base/autowrap.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/base/autowrap.kak b/rc/base/autowrap.kak index e925407f..0b7bc44b 100644 --- a/rc/base/autowrap.kak +++ b/rc/base/autowrap.kak @@ -3,7 +3,7 @@ decl int autowrap_column 80 # If enabled, paragraph formatting will reformat the whole paragraph in which characters are being inserted # This can potentially break formatting of documents containing markup (e.g. markdown) -decl bool autowrap_format_paragraph yes +decl bool autowrap_format_paragraph no # Command to which the paragraphs to wrap will be passed, all occurences of '%c' are replaced with `autowrap_column` decl str autowrap_fmtcmd 'fold -s -w %c' @@ -26,7 +26,7 @@ def -hidden autowrap-cursor %{ eval -save-regs '/"|^@m' %{ format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \ | sed "s/%c/${kak_opt_autowrap_column}/g") printf %s " - exec 'p|${format_cmd}' + exec 'p|${format_cmd}' try %{ exec s\h+$ d } select '${kak_reg_m}' "