From a6ba65c121c49616f577397026a35247ca7cb643 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 31 May 2018 21:03:35 +1000 Subject: [PATCH] doc.kak: Fix post list syntax refactoring --- rc/core/doc.kak | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/rc/core/doc.kak b/rc/core/doc.kak index 1f14cfcf..45d1541d 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -12,9 +12,11 @@ define-command -hidden -params 4 doc-render-regex %{ execute-keys -draft s %arg{2} d execute-keys "%arg{3}" evaluate-commands %sh{ - ranges=$(echo "$kak_selections_desc" | sed -e "s/:/|$4:/g; s/\$/|$4/") + face="$4" + eval "set -- $kak_selections_desc" + for desc in "$@"; do ranges="$ranges '$desc|$face'"; done echo "update-option buffer doc_render_ranges" - echo "set-option -add buffer doc_render_ranges '$ranges'" + echo "set-option -add buffer doc_render_ranges $ranges" } } } } @@ -39,7 +41,7 @@ define-command -hidden doc-parse-anchors %{ # Find sections as add them as imlicit anchors execute-keys \%s ^={2,}\h+([^\n]+)$ evaluate-commands -itersel %{ - set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' \"$kak_reg_1\" | tr '[A-Z ]' '[a-z-]'}" + set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' ""$kak_reg_1"" | tr '[A-Z ]' '[a-z-]'}" } # Parse explicit anchors and remove their text @@ -55,19 +57,25 @@ define-command -hidden doc-parse-anchors %{ define-command doc-jump-to-anchor -params 1 %{ update-option buffer doc_anchors evaluate-commands %sh{ - range=$(printf "%s" "$kak_opt_doc_anchors" | tr ':' '\n' | grep "$1" | head -n1) - if [ -n "$range" ]; then - printf '%s\n' "select '${range%|*}'; execute-keys vv" - else - printf '%s\n' "echo -markup %{{Error}No such anchor '$1'}" - fi + anchor="$1" + eval "set -- $kak_opt_doc_anchors" + for range in "$@"; do + if [ "${range#*|}" == "$anchor" ]; then + printf '%s\n' "select '${range%|*}'; execute-keys vv" + exit + fi + done + printf '%s\n' "echo -markup %{{Error}No such anchor '$1'}" } } define-command doc-follow-link %{ update-option buffer doc_links evaluate-commands %sh{ - printf "%s" "$kak_opt_doc_links" | awk -v RS=':' -v FS='[.,|#]' ' + eval "set -- $kak_opt_doc_links" + for link in "$@"; do + printf '%s\n' "$link" + done | awk -v FS='[.,|#]' ' BEGIN { l=ENVIRON["kak_cursor_line"]; c=ENVIRON["kak_cursor_column"];