Created
February 17, 2018 21:34
-
-
Save casimir/384332d38ea09165f827f315a1fec0d6 to your computer and use it in GitHub Desktop.
sed → awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/rc/base/lint.kak b/rc/base/lint.kak | |
index 41ad1144..ec390738 100644 | |
--- a/rc/base/lint.kak | |
+++ b/rc/base/lint.kak | |
@@ -45,11 +45,11 @@ define-command lint -docstring 'Parse the current buffer with a linter' %{ | |
errors = errors ":" $2 "." $3 "," $2 "." $3 "|" substr($4,2) | |
# fix case where $5 is not the last field because of extra :s in the message | |
for (i=5; i<=NF; i++) errors = errors "\\:" $i | |
- errors = substr(errors, 1, length(errors)-1) " (col " $3 ")" | |
+ errors = substr(errors, 1, length(errors)) " (col " $3 ")" | |
} | |
END { | |
- print "set-option \"buffer=" file "\" lint_flags %{" stamp ":" substr(flags, 1, length(flags)-1) "}" | |
- errors = substr(errors, 1, length(errors)-1) | |
+ print "set-option \"buffer=" file "\" lint_flags %{" stamp ":" substr(flags, 1, length(flags)-1) "}" | |
+ errors = substr(errors, 1, length(errors)) | |
gsub("~", "\\~", errors) | |
print "set-option \"buffer=" file "\" lint_errors %~" stamp errors "~" | |
} | |
@@ -64,12 +64,25 @@ define-command lint -docstring 'Parse the current buffer with a linter' %{ | |
define-command -hidden lint-show %{ | |
update-option buffer lint_errors | |
%sh{ | |
- desc=$(printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | | |
- sed -ne "/^$kak_cursor_line\.[^|]\+|.*/ { s/^[^|]\+|//g; s/'/\\\\'/g; s/\\\\:/:/g; p; }") | |
+ desc=$(printf '%s\n' "$kak_opt_lint_errors" | awk -v lnum=$kak_cursor_line -v q="'" -F: '{ | |
+ regex = "^" lnum "\\.[^|]+\\|.*" | |
+ gsub(/\\:/, SUBSEP) | |
+ for (i = 2; i <= NF; i++) { | |
+ it = $i | |
+ gsub(SUBSEP, ":", it) | |
+ if (it ~ regex) { | |
+ split(it, a, "|") | |
+ out = a[2] | |
+ gsub(q, "\\" q, out) | |
+ print out | |
+ } | |
+ } | |
+ }') | |
if [ -n "$desc" ]; then | |
printf '%s\n' "info -anchor $kak_cursor_line.$kak_cursor_column '$desc'" | |
fi | |
- } } | |
+ } | |
+} | |
define-command lint-enable -docstring "Activate automatic diagnostics of the code" %{ | |
add-highlighter window flag_lines default lint_flags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment