From 79fa50dc3e47c1be95ecde34e70a3bc0c73f4c26 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:24:06 -0600 Subject: [PATCH 01/27] Add namespacing to crystal hooks --- rc/filetype/crystal.kak | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index ae1ce819..b57f1518 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -7,12 +7,15 @@ hook global BufCreate '.*\.cr' %{ hook global WinSetOption filetype=crystal %{ require-module crystal - evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} + add-highlighter window/crystal ref crystal - hook -group crystal window InsertChar '\n' crystal-new-line-inserted + evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} + + hook window InsertChar '\n' -group crystal-indent crystal-new-line-inserted + hook -always -once window WinSetOption filetype=.* %{ remove-highlighter window/crystal - remove-hooks window crystal + remove-hooks window crystal-.+ } } From dc378da87f711bb64f21b15ef9eb9683b35f6497 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:27:21 -0600 Subject: [PATCH 02/27] Add section comments to crystal.kak --- rc/filetype/crystal.kak | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index b57f1518..0a5a9047 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -1,10 +1,16 @@ # Crystal # https://crystal-lang.org +# Detection +# ‾‾‾‾‾‾‾‾‾ + hook global BufCreate '.*\.cr' %{ set-option buffer filetype crystal } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + hook global WinSetOption filetype=crystal %{ require-module crystal @@ -26,6 +32,9 @@ provide-module crystal %🐈 declare-option -hidden str-list crystal_operators '+' '-' '*' '/' '//' '%' '|' '&' '^' '~' '**' '<<' '<' '<=' '==' '!=' '=~' '!~' '>>' '>' '>=' '<=>' '===' '[]' '[]=' '[]?' '[' '&+' '&-' '&*' '&**' declare-option -hidden str-list crystal_objects 'Adler32' 'ArgumentError' 'Array' 'Atomic' 'Base64' 'Benchmark' 'BigDecimal' 'BigFloat' 'BigInt' 'BigRational' 'BitArray' 'Bool' 'Box' 'Bytes' 'Channel' 'Char' 'Class' 'Colorize' 'Comparable' 'Complex' 'Concurrent' 'ConcurrentExecutionException' 'CRC32' 'Crypto' 'Crystal' 'CSV' 'Debug' 'Deprecated' 'Deque' 'Digest' 'Dir' 'DivisionByZeroError' 'DL' 'ECR' 'Enum' 'Enumerable' 'ENV' 'Errno' 'Exception' 'Fiber' 'File' 'FileUtils' 'Flags' 'Flate' 'Float' 'Float32' 'Float64' 'GC' 'Gzip' 'Hash' 'HTML' 'HTTP' 'Indexable' 'IndexError' 'INI' 'Int' 'Int128' 'Int16' 'Int32' 'Int64' 'Int8' 'InvalidBigDecimalException' 'InvalidByteSequenceError' 'IO' 'IPSocket' 'Iterable' 'Iterator' 'JSON' 'KeyError' 'Levenshtein' 'Link' 'LLVM' 'Logger' 'Markdown' 'Math' 'MIME' 'Mutex' 'NamedTuple' 'Nil' 'NilAssertionError' 'NotImplementedError' 'Number' 'OAuth' 'OAuth2' 'Object' 'OpenSSL' 'OptionParser' 'OverflowError' 'PartialComparable' 'Path' 'Pointer' 'PrettyPrint' 'Proc' 'Process' 'Random' 'Range' 'Readline' 'Reference' 'Reflect' 'Regex' 'SemanticVersion' 'Set' 'Signal' 'Slice' 'Socket' 'Spec' 'StaticArray' 'String' 'StringPool' 'StringScanner' 'Struct' 'Symbol' 'System' 'TCPServer' 'TCPSocket' 'Termios' 'Time' 'Tuple' 'TypeCastError' 'UDPSocket' 'UInt128' 'UInt16' 'UInt32' 'UInt64' 'UInt8' 'Unicode' 'Union' 'UNIXServer' 'UNIXSocket' 'URI' 'UUID' 'VaList' 'Value' 'WeakRef' 'XML' 'YAML' 'Zip' 'Zlib' + # Highlighters + # ‾‾‾‾‾‾‾‾‾‾‾‾ + add-highlighter shared/crystal regions add-highlighter shared/crystal/code default-region group @@ -162,6 +171,9 @@ provide-module crystal %🐈 done ] + # Commands + # ‾‾‾‾‾‾‾‾ + define-command -hidden crystal-new-line-inserted %{ # Copy previous line indent try %{ From 5c124db5d9b0102008eb5bb7401d22a7fa887a25 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:30:12 -0600 Subject: [PATCH 03/27] Replace cat emojis with section signs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many terminal emulators or fonts don't support the cat emoji, and the section sign (§) is more semantically correct than a cat. --- rc/filetype/crystal.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 0a5a9047..20ef637b 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -25,7 +25,7 @@ hook global WinSetOption filetype=crystal %{ } } -provide-module crystal %🐈 +provide-module crystal %§ declare-option -hidden str-list crystal_keywords 'abstract' 'alias' 'annotation' 'as' 'asm' 'begin' 'break' 'case' 'class' 'def' 'do' 'else' 'elsif' 'end' 'ensure' 'enum' 'extend' 'false' 'for' 'fun' 'if' 'include' 'instance_sizeof' 'is_a?' 'lib' 'macro' 'module' 'next' 'nil' 'nil?' 'of' 'offsetof' 'out' 'pointerof' 'private' 'protected' 'require' 'rescue' 'responds_to?' 'return' 'select' 'self' 'sizeof' 'struct' 'super' 'then' 'true' 'type' 'typeof' 'uninitialized' 'union' 'unless' 'until' 'verbatim' 'when' 'while' 'with' 'yield' # https://crystal-lang.org/reference/syntax_and_semantics/methods_and_instance_variables.html#getters-and-setters declare-option -hidden str-list crystal_attributes 'getter' 'setter' 'property' @@ -206,4 +206,4 @@ provide-module crystal %🐈 kak -f '%1sdata-id="github.com/crystal-lang/crystal/(\w+)")y%aa' } } -🐈 +§ From a78b6e6ccbd7b147506d27b5a055948ec7dedbb2 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:34:55 -0600 Subject: [PATCH 04/27] Change 2-space indentation to 4-space --- rc/filetype/crystal.kak | 348 ++++++++++++++++++++-------------------- 1 file changed, 174 insertions(+), 174 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 20ef637b..611158e8 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -5,205 +5,205 @@ # ‾‾‾‾‾‾‾‾‾ hook global BufCreate '.*\.cr' %{ - set-option buffer filetype crystal + set-option buffer filetype crystal } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=crystal %{ - require-module crystal + require-module crystal - add-highlighter window/crystal ref crystal - evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} + add-highlighter window/crystal ref crystal + evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} - hook window InsertChar '\n' -group crystal-indent crystal-new-line-inserted + hook window InsertChar '\n' -group crystal-indent crystal-new-line-inserted - hook -always -once window WinSetOption filetype=.* %{ - remove-highlighter window/crystal - remove-hooks window crystal-.+ - } + hook -always -once window WinSetOption filetype=.* %{ + remove-highlighter window/crystal + remove-hooks window crystal-.+ + } } provide-module crystal %§ - declare-option -hidden str-list crystal_keywords 'abstract' 'alias' 'annotation' 'as' 'asm' 'begin' 'break' 'case' 'class' 'def' 'do' 'else' 'elsif' 'end' 'ensure' 'enum' 'extend' 'false' 'for' 'fun' 'if' 'include' 'instance_sizeof' 'is_a?' 'lib' 'macro' 'module' 'next' 'nil' 'nil?' 'of' 'offsetof' 'out' 'pointerof' 'private' 'protected' 'require' 'rescue' 'responds_to?' 'return' 'select' 'self' 'sizeof' 'struct' 'super' 'then' 'true' 'type' 'typeof' 'uninitialized' 'union' 'unless' 'until' 'verbatim' 'when' 'while' 'with' 'yield' - # https://crystal-lang.org/reference/syntax_and_semantics/methods_and_instance_variables.html#getters-and-setters - declare-option -hidden str-list crystal_attributes 'getter' 'setter' 'property' - declare-option -hidden str-list crystal_operators '+' '-' '*' '/' '//' '%' '|' '&' '^' '~' '**' '<<' '<' '<=' '==' '!=' '=~' '!~' '>>' '>' '>=' '<=>' '===' '[]' '[]=' '[]?' '[' '&+' '&-' '&*' '&**' - declare-option -hidden str-list crystal_objects 'Adler32' 'ArgumentError' 'Array' 'Atomic' 'Base64' 'Benchmark' 'BigDecimal' 'BigFloat' 'BigInt' 'BigRational' 'BitArray' 'Bool' 'Box' 'Bytes' 'Channel' 'Char' 'Class' 'Colorize' 'Comparable' 'Complex' 'Concurrent' 'ConcurrentExecutionException' 'CRC32' 'Crypto' 'Crystal' 'CSV' 'Debug' 'Deprecated' 'Deque' 'Digest' 'Dir' 'DivisionByZeroError' 'DL' 'ECR' 'Enum' 'Enumerable' 'ENV' 'Errno' 'Exception' 'Fiber' 'File' 'FileUtils' 'Flags' 'Flate' 'Float' 'Float32' 'Float64' 'GC' 'Gzip' 'Hash' 'HTML' 'HTTP' 'Indexable' 'IndexError' 'INI' 'Int' 'Int128' 'Int16' 'Int32' 'Int64' 'Int8' 'InvalidBigDecimalException' 'InvalidByteSequenceError' 'IO' 'IPSocket' 'Iterable' 'Iterator' 'JSON' 'KeyError' 'Levenshtein' 'Link' 'LLVM' 'Logger' 'Markdown' 'Math' 'MIME' 'Mutex' 'NamedTuple' 'Nil' 'NilAssertionError' 'NotImplementedError' 'Number' 'OAuth' 'OAuth2' 'Object' 'OpenSSL' 'OptionParser' 'OverflowError' 'PartialComparable' 'Path' 'Pointer' 'PrettyPrint' 'Proc' 'Process' 'Random' 'Range' 'Readline' 'Reference' 'Reflect' 'Regex' 'SemanticVersion' 'Set' 'Signal' 'Slice' 'Socket' 'Spec' 'StaticArray' 'String' 'StringPool' 'StringScanner' 'Struct' 'Symbol' 'System' 'TCPServer' 'TCPSocket' 'Termios' 'Time' 'Tuple' 'TypeCastError' 'UDPSocket' 'UInt128' 'UInt16' 'UInt32' 'UInt64' 'UInt8' 'Unicode' 'Union' 'UNIXServer' 'UNIXSocket' 'URI' 'UUID' 'VaList' 'Value' 'WeakRef' 'XML' 'YAML' 'Zip' 'Zlib' + declare-option -hidden str-list crystal_keywords 'abstract' 'alias' 'annotation' 'as' 'asm' 'begin' 'break' 'case' 'class' 'def' 'do' 'else' 'elsif' 'end' 'ensure' 'enum' 'extend' 'false' 'for' 'fun' 'if' 'include' 'instance_sizeof' 'is_a?' 'lib' 'macro' 'module' 'next' 'nil' 'nil?' 'of' 'offsetof' 'out' 'pointerof' 'private' 'protected' 'require' 'rescue' 'responds_to?' 'return' 'select' 'self' 'sizeof' 'struct' 'super' 'then' 'true' 'type' 'typeof' 'uninitialized' 'union' 'unless' 'until' 'verbatim' 'when' 'while' 'with' 'yield' + # https://crystal-lang.org/reference/syntax_and_semantics/methods_and_instance_variables.html#getters-and-setters + declare-option -hidden str-list crystal_attributes 'getter' 'setter' 'property' + declare-option -hidden str-list crystal_operators '+' '-' '*' '/' '//' '%' '|' '&' '^' '~' '**' '<<' '<' '<=' '==' '!=' '=~' '!~' '>>' '>' '>=' '<=>' '===' '[]' '[]=' '[]?' '[' '&+' '&-' '&*' '&**' + declare-option -hidden str-list crystal_objects 'Adler32' 'ArgumentError' 'Array' 'Atomic' 'Base64' 'Benchmark' 'BigDecimal' 'BigFloat' 'BigInt' 'BigRational' 'BitArray' 'Bool' 'Box' 'Bytes' 'Channel' 'Char' 'Class' 'Colorize' 'Comparable' 'Complex' 'Concurrent' 'ConcurrentExecutionException' 'CRC32' 'Crypto' 'Crystal' 'CSV' 'Debug' 'Deprecated' 'Deque' 'Digest' 'Dir' 'DivisionByZeroError' 'DL' 'ECR' 'Enum' 'Enumerable' 'ENV' 'Errno' 'Exception' 'Fiber' 'File' 'FileUtils' 'Flags' 'Flate' 'Float' 'Float32' 'Float64' 'GC' 'Gzip' 'Hash' 'HTML' 'HTTP' 'Indexable' 'IndexError' 'INI' 'Int' 'Int128' 'Int16' 'Int32' 'Int64' 'Int8' 'InvalidBigDecimalException' 'InvalidByteSequenceError' 'IO' 'IPSocket' 'Iterable' 'Iterator' 'JSON' 'KeyError' 'Levenshtein' 'Link' 'LLVM' 'Logger' 'Markdown' 'Math' 'MIME' 'Mutex' 'NamedTuple' 'Nil' 'NilAssertionError' 'NotImplementedError' 'Number' 'OAuth' 'OAuth2' 'Object' 'OpenSSL' 'OptionParser' 'OverflowError' 'PartialComparable' 'Path' 'Pointer' 'PrettyPrint' 'Proc' 'Process' 'Random' 'Range' 'Readline' 'Reference' 'Reflect' 'Regex' 'SemanticVersion' 'Set' 'Signal' 'Slice' 'Socket' 'Spec' 'StaticArray' 'String' 'StringPool' 'StringScanner' 'Struct' 'Symbol' 'System' 'TCPServer' 'TCPSocket' 'Termios' 'Time' 'Tuple' 'TypeCastError' 'UDPSocket' 'UInt128' 'UInt16' 'UInt32' 'UInt64' 'UInt8' 'Unicode' 'Union' 'UNIXServer' 'UNIXSocket' 'URI' 'UUID' 'VaList' 'Value' 'WeakRef' 'XML' 'YAML' 'Zip' 'Zlib' - # Highlighters - # ‾‾‾‾‾‾‾‾‾‾‾‾ + # Highlighters + # ‾‾‾‾‾‾‾‾‾‾‾‾ - add-highlighter shared/crystal regions - add-highlighter shared/crystal/code default-region group + add-highlighter shared/crystal regions + add-highlighter shared/crystal/code default-region group - # Comments - # https://crystal-lang.org/reference/syntax_and_semantics/comments.html - # Avoid string literals with interpolation - add-highlighter shared/crystal/comment region '#(?!\{)' '$' fill comment + # Comments + # https://crystal-lang.org/reference/syntax_and_semantics/comments.html + # Avoid string literals with interpolation + add-highlighter shared/crystal/comment region '#(?!\{)' '$' fill comment - # String - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html - add-highlighter shared/crystal/string region '"' '(?' regions - add-highlighter shared/crystal/pipe-string region '%Q?\|' '\|' regions - # Raw - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-literals - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-array-literal - # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html#percent-symbol-array-literal - add-highlighter shared/crystal/raw-parenthesis-string region -recurse '\(' '%[qwi]\(' '\)' fill string - add-highlighter shared/crystal/raw-bracket-string region -recurse '\[' '%[qwi]\[' '\]' fill string - add-highlighter shared/crystal/raw-brace-string region -recurse '\{' '%[qwi]\{' '\}' fill string - add-highlighter shared/crystal/raw-angle-string region -recurse '<' '%[qwi]<' '>' fill string - add-highlighter shared/crystal/raw-pipe-string region '%[qwi]\|' '\|' fill string - - # Here document - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#heredoc - add-highlighter shared/crystal/heredoc region -match-capture '<<-(\w+)' '^\h*(\w+)$' regions - # Raw - add-highlighter shared/crystal/raw-heredoc region -match-capture "<<-'(\w+)'" '^\h*(\w+)$' regions - add-highlighter shared/crystal/raw-heredoc/fill default-region fill string - add-highlighter shared/crystal/raw-heredoc/interpolation region -recurse '\{' '#\{' '\}' fill meta - - # Symbol - # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html - add-highlighter shared/crystal/quoted-symbol region ':"' '(?[imx]*' regions - add-highlighter shared/crystal/pipe-regex region '%r?\|' '\|[imx]*' regions - - # Command - # https://crystal-lang.org/reference/syntax_and_semantics/literals/command.html - add-highlighter shared/crystal/command region '`' '(?' regions - add-highlighter shared/crystal/pipe-command region '%x?\|' '\|' regions - - evaluate-commands %sh[ - # Keywords - eval "set -- $kak_quoted_opt_crystal_keywords" - regex="\\b(?:\\Q$1\\E" - shift - for keyword do - regex="$regex|\\Q$keyword\\E" - done - regex="$regex)\\b" - printf 'add-highlighter shared/crystal/code/keywords regex %s 0:keyword\n' "$regex" - - # Attributes - eval "set -- $kak_quoted_opt_crystal_attributes" - regex="\\b(?:\\Q$1\\E" - shift - for attribute do - regex="$regex|\\Q$attribute\\E" - done - regex="$regex)\\b" - printf 'add-highlighter shared/crystal/code/attributes regex %s 0:attribute\n' "$regex" - - # Symbols - eval "set -- $kak_quoted_opt_crystal_operators" - # Avoid to match modules - regex="(?' regions + add-highlighter shared/crystal/pipe-string region '%Q?\|' '\|' regions + # Raw + # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-literals + # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-array-literal + # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html#percent-symbol-array-literal + add-highlighter shared/crystal/raw-parenthesis-string region -recurse '\(' '%[qwi]\(' '\)' fill string + add-highlighter shared/crystal/raw-bracket-string region -recurse '\[' '%[qwi]\[' '\]' fill string + add-highlighter shared/crystal/raw-brace-string region -recurse '\{' '%[qwi]\{' '\}' fill string + add-highlighter shared/crystal/raw-angle-string region -recurse '<' '%[qwi]<' '>' fill string + add-highlighter shared/crystal/raw-pipe-string region '%[qwi]\|' '\|' fill string + + # Here document + # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#heredoc + add-highlighter shared/crystal/heredoc region -match-capture '<<-(\w+)' '^\h*(\w+)$' regions + # Raw + add-highlighter shared/crystal/raw-heredoc region -match-capture "<<-'(\w+)'" '^\h*(\w+)$' regions + add-highlighter shared/crystal/raw-heredoc/fill default-region fill string + add-highlighter shared/crystal/raw-heredoc/interpolation region -recurse '\{' '#\{' '\}' fill meta + + # Symbol + # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html + add-highlighter shared/crystal/quoted-symbol region ':"' '(?[imx]*' regions + add-highlighter shared/crystal/pipe-regex region '%r?\|' '\|[imx]*' regions # Command - for id in command parenthesis-command bracket-command brace-command angle-command pipe-command; do - printf " - add-highlighter shared/crystal/$id/fill default-region fill meta - add-highlighter shared/crystal/$id/interpolation region -recurse '\\{' '#\\{' '\\}' ref crystal - " - done - ] + # https://crystal-lang.org/reference/syntax_and_semantics/literals/command.html + add-highlighter shared/crystal/command region '`' '(?' regions + add-highlighter shared/crystal/pipe-command region '%x?\|' '\|' regions - define-command -hidden crystal-new-line-inserted %{ - # Copy previous line indent - try %{ - execute-keys -draft 'K' - } - # Remove empty line indent - try %{ - execute-keys -draft 'ks^\h+$d' - } - } + evaluate-commands %sh[ + # Keywords + eval "set -- $kak_quoted_opt_crystal_keywords" + regex="\\b(?:\\Q$1\\E" + shift + for keyword do + regex="$regex|\\Q$keyword\\E" + done + regex="$regex)\\b" + printf 'add-highlighter shared/crystal/code/keywords regex %s 0:keyword\n' "$regex" - define-command -hidden crystal-fetch-keywords %{ - set-register dquote %sh{ - curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | - kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' - } - } + # Attributes + eval "set -- $kak_quoted_opt_crystal_attributes" + regex="\\b(?:\\Q$1\\E" + shift + for attribute do + regex="$regex|\\Q$attribute\\E" + done + regex="$regex)\\b" + printf 'add-highlighter shared/crystal/code/attributes regex %s 0:attribute\n' "$regex" - define-command -hidden crystal-fetch-operators %{ - set-register dquote %sh{ - curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/parser.cr | - kak -f '/AtomicWithMethodCheck =x1s:"([^"]+)"y%i''a''a' - } - } + # Symbols + eval "set -- $kak_quoted_opt_crystal_operators" + # Avoid to match modules + regex="(?)y%aa' + # Objects + eval "set -- $kak_quoted_opt_crystal_objects" + regex="\\b(?:\\Q$1\\E" + shift + for object do + regex="$regex|\\Q$object\\E" + done + regex="$regex)\\b" + printf 'add-highlighter shared/crystal/code/objects regex %s 0:builtin\n' "$regex" + + # Interpolation + # String + # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#interpolation + for id in string parenthesis-string bracket-string brace-string angle-string pipe-string heredoc; do + printf " + add-highlighter shared/crystal/$id/fill default-region fill string + add-highlighter shared/crystal/$id/interpolation region -recurse '\\{' '#\\{' '\\}' ref crystal + " + done + + # Regular expressions + # https://crystal-lang.org/reference/syntax_and_semantics/literals/regex.html#interpolation + for id in regex parenthesis-regex bracket-regex brace-regex angle-regex pipe-regex; do + printf " + add-highlighter shared/crystal/$id/fill default-region fill meta + add-highlighter shared/crystal/$id/interpolation region -recurse '\\{' '#\\{' '\\}' ref crystal + " + done + + # Command + for id in command parenthesis-command bracket-command brace-command angle-command pipe-command; do + printf " + add-highlighter shared/crystal/$id/fill default-region fill meta + add-highlighter shared/crystal/$id/interpolation region -recurse '\\{' '#\\{' '\\}' ref crystal + " + done + ] + + # Commands + # ‾‾‾‾‾‾‾‾ + + define-command -hidden crystal-new-line-inserted %{ + # Copy previous line indent + try %{ + execute-keys -draft 'K' + } + # Remove empty line indent + try %{ + execute-keys -draft 'ks^\h+$d' + } + } + + define-command -hidden crystal-fetch-keywords %{ + set-register dquote %sh{ + curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' + } + } + + define-command -hidden crystal-fetch-operators %{ + set-register dquote %sh{ + curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/parser.cr | + kak -f '/AtomicWithMethodCheck =x1s:"([^"]+)"y%i''a''a' + } + } + + define-command -hidden crystal-fetch-objects %{ + set-register dquote %sh{ + curl --location https://crystal-lang.org/api/ | + # Remove Top Level Namespace + kak -f '%1sdata-id="github.com/crystal-lang/crystal/(\w+)")y%aa' + } } - } § From 3248f7279c1b191a85b3e39c01c40aa927dfb17b Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:36:14 -0600 Subject: [PATCH 05/27] Deindent everything in the 'provide-module crystal...' block --- rc/filetype/crystal.kak | 328 ++++++++++++++++++++-------------------- 1 file changed, 165 insertions(+), 163 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 611158e8..5a49c39b 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -26,184 +26,186 @@ hook global WinSetOption filetype=crystal %{ } provide-module crystal %§ - declare-option -hidden str-list crystal_keywords 'abstract' 'alias' 'annotation' 'as' 'asm' 'begin' 'break' 'case' 'class' 'def' 'do' 'else' 'elsif' 'end' 'ensure' 'enum' 'extend' 'false' 'for' 'fun' 'if' 'include' 'instance_sizeof' 'is_a?' 'lib' 'macro' 'module' 'next' 'nil' 'nil?' 'of' 'offsetof' 'out' 'pointerof' 'private' 'protected' 'require' 'rescue' 'responds_to?' 'return' 'select' 'self' 'sizeof' 'struct' 'super' 'then' 'true' 'type' 'typeof' 'uninitialized' 'union' 'unless' 'until' 'verbatim' 'when' 'while' 'with' 'yield' - # https://crystal-lang.org/reference/syntax_and_semantics/methods_and_instance_variables.html#getters-and-setters - declare-option -hidden str-list crystal_attributes 'getter' 'setter' 'property' - declare-option -hidden str-list crystal_operators '+' '-' '*' '/' '//' '%' '|' '&' '^' '~' '**' '<<' '<' '<=' '==' '!=' '=~' '!~' '>>' '>' '>=' '<=>' '===' '[]' '[]=' '[]?' '[' '&+' '&-' '&*' '&**' - declare-option -hidden str-list crystal_objects 'Adler32' 'ArgumentError' 'Array' 'Atomic' 'Base64' 'Benchmark' 'BigDecimal' 'BigFloat' 'BigInt' 'BigRational' 'BitArray' 'Bool' 'Box' 'Bytes' 'Channel' 'Char' 'Class' 'Colorize' 'Comparable' 'Complex' 'Concurrent' 'ConcurrentExecutionException' 'CRC32' 'Crypto' 'Crystal' 'CSV' 'Debug' 'Deprecated' 'Deque' 'Digest' 'Dir' 'DivisionByZeroError' 'DL' 'ECR' 'Enum' 'Enumerable' 'ENV' 'Errno' 'Exception' 'Fiber' 'File' 'FileUtils' 'Flags' 'Flate' 'Float' 'Float32' 'Float64' 'GC' 'Gzip' 'Hash' 'HTML' 'HTTP' 'Indexable' 'IndexError' 'INI' 'Int' 'Int128' 'Int16' 'Int32' 'Int64' 'Int8' 'InvalidBigDecimalException' 'InvalidByteSequenceError' 'IO' 'IPSocket' 'Iterable' 'Iterator' 'JSON' 'KeyError' 'Levenshtein' 'Link' 'LLVM' 'Logger' 'Markdown' 'Math' 'MIME' 'Mutex' 'NamedTuple' 'Nil' 'NilAssertionError' 'NotImplementedError' 'Number' 'OAuth' 'OAuth2' 'Object' 'OpenSSL' 'OptionParser' 'OverflowError' 'PartialComparable' 'Path' 'Pointer' 'PrettyPrint' 'Proc' 'Process' 'Random' 'Range' 'Readline' 'Reference' 'Reflect' 'Regex' 'SemanticVersion' 'Set' 'Signal' 'Slice' 'Socket' 'Spec' 'StaticArray' 'String' 'StringPool' 'StringScanner' 'Struct' 'Symbol' 'System' 'TCPServer' 'TCPSocket' 'Termios' 'Time' 'Tuple' 'TypeCastError' 'UDPSocket' 'UInt128' 'UInt16' 'UInt32' 'UInt64' 'UInt8' 'Unicode' 'Union' 'UNIXServer' 'UNIXSocket' 'URI' 'UUID' 'VaList' 'Value' 'WeakRef' 'XML' 'YAML' 'Zip' 'Zlib' - # Highlighters - # ‾‾‾‾‾‾‾‾‾‾‾‾ +declare-option -hidden str-list crystal_keywords 'abstract' 'alias' 'annotation' 'as' 'asm' 'begin' 'break' 'case' 'class' 'def' 'do' 'else' 'elsif' 'end' 'ensure' 'enum' 'extend' 'false' 'for' 'fun' 'if' 'include' 'instance_sizeof' 'is_a?' 'lib' 'macro' 'module' 'next' 'nil' 'nil?' 'of' 'offsetof' 'out' 'pointerof' 'private' 'protected' 'require' 'rescue' 'responds_to?' 'return' 'select' 'self' 'sizeof' 'struct' 'super' 'then' 'true' 'type' 'typeof' 'uninitialized' 'union' 'unless' 'until' 'verbatim' 'when' 'while' 'with' 'yield' +# https://crystal-lang.org/reference/syntax_and_semantics/methods_and_instance_variables.html#getters-and-setters +declare-option -hidden str-list crystal_attributes 'getter' 'setter' 'property' +declare-option -hidden str-list crystal_operators '+' '-' '*' '/' '//' '%' '|' '&' '^' '~' '**' '<<' '<' '<=' '==' '!=' '=~' '!~' '>>' '>' '>=' '<=>' '===' '[]' '[]=' '[]?' '[' '&+' '&-' '&*' '&**' +declare-option -hidden str-list crystal_objects 'Adler32' 'ArgumentError' 'Array' 'Atomic' 'Base64' 'Benchmark' 'BigDecimal' 'BigFloat' 'BigInt' 'BigRational' 'BitArray' 'Bool' 'Box' 'Bytes' 'Channel' 'Char' 'Class' 'Colorize' 'Comparable' 'Complex' 'Concurrent' 'ConcurrentExecutionException' 'CRC32' 'Crypto' 'Crystal' 'CSV' 'Debug' 'Deprecated' 'Deque' 'Digest' 'Dir' 'DivisionByZeroError' 'DL' 'ECR' 'Enum' 'Enumerable' 'ENV' 'Errno' 'Exception' 'Fiber' 'File' 'FileUtils' 'Flags' 'Flate' 'Float' 'Float32' 'Float64' 'GC' 'Gzip' 'Hash' 'HTML' 'HTTP' 'Indexable' 'IndexError' 'INI' 'Int' 'Int128' 'Int16' 'Int32' 'Int64' 'Int8' 'InvalidBigDecimalException' 'InvalidByteSequenceError' 'IO' 'IPSocket' 'Iterable' 'Iterator' 'JSON' 'KeyError' 'Levenshtein' 'Link' 'LLVM' 'Logger' 'Markdown' 'Math' 'MIME' 'Mutex' 'NamedTuple' 'Nil' 'NilAssertionError' 'NotImplementedError' 'Number' 'OAuth' 'OAuth2' 'Object' 'OpenSSL' 'OptionParser' 'OverflowError' 'PartialComparable' 'Path' 'Pointer' 'PrettyPrint' 'Proc' 'Process' 'Random' 'Range' 'Readline' 'Reference' 'Reflect' 'Regex' 'SemanticVersion' 'Set' 'Signal' 'Slice' 'Socket' 'Spec' 'StaticArray' 'String' 'StringPool' 'StringScanner' 'Struct' 'Symbol' 'System' 'TCPServer' 'TCPSocket' 'Termios' 'Time' 'Tuple' 'TypeCastError' 'UDPSocket' 'UInt128' 'UInt16' 'UInt32' 'UInt64' 'UInt8' 'Unicode' 'Union' 'UNIXServer' 'UNIXSocket' 'URI' 'UUID' 'VaList' 'Value' 'WeakRef' 'XML' 'YAML' 'Zip' 'Zlib' - add-highlighter shared/crystal regions - add-highlighter shared/crystal/code default-region group +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ - # Comments - # https://crystal-lang.org/reference/syntax_and_semantics/comments.html - # Avoid string literals with interpolation - add-highlighter shared/crystal/comment region '#(?!\{)' '$' fill comment +add-highlighter shared/crystal regions +add-highlighter shared/crystal/code default-region group +# Comments +# https://crystal-lang.org/reference/syntax_and_semantics/comments.html +# Avoid string literals with interpolation +add-highlighter shared/crystal/comment region '#(?!\{)' '$' fill comment + +# String +# https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html +add-highlighter shared/crystal/string region '"' '(?' regions +add-highlighter shared/crystal/pipe-string region '%Q?\|' '\|' regions +# Raw +# https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-literals +# https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-array-literal +# https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html#percent-symbol-array-literal +add-highlighter shared/crystal/raw-parenthesis-string region -recurse '\(' '%[qwi]\(' '\)' fill string +add-highlighter shared/crystal/raw-bracket-string region -recurse '\[' '%[qwi]\[' '\]' fill string +add-highlighter shared/crystal/raw-brace-string region -recurse '\{' '%[qwi]\{' '\}' fill string +add-highlighter shared/crystal/raw-angle-string region -recurse '<' '%[qwi]<' '>' fill string +add-highlighter shared/crystal/raw-pipe-string region '%[qwi]\|' '\|' fill string + +# Here document +# https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#heredoc +add-highlighter shared/crystal/heredoc region -match-capture '<<-(\w+)' '^\h*(\w+)$' regions +# Raw +add-highlighter shared/crystal/raw-heredoc region -match-capture "<<-'(\w+)'" '^\h*(\w+)$' regions +add-highlighter shared/crystal/raw-heredoc/fill default-region fill string +add-highlighter shared/crystal/raw-heredoc/interpolation region -recurse '\{' '#\{' '\}' fill meta + +# Symbol +# https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html +add-highlighter shared/crystal/quoted-symbol region ':"' '(?[imx]*' regions +add-highlighter shared/crystal/pipe-regex region '%r?\|' '\|[imx]*' regions + +# Command +# https://crystal-lang.org/reference/syntax_and_semantics/literals/command.html +add-highlighter shared/crystal/command region '`' '(?' regions +add-highlighter shared/crystal/pipe-command region '%x?\|' '\|' regions + +evaluate-commands %sh[ + # Keywords + eval "set -- $kak_quoted_opt_crystal_keywords" + regex="\\b(?:\\Q$1\\E" + shift + for keyword do + regex="$regex|\\Q$keyword\\E" + done + regex="$regex)\\b" + printf 'add-highlighter shared/crystal/code/keywords regex %s 0:keyword\n' "$regex" + + # Attributes + eval "set -- $kak_quoted_opt_crystal_attributes" + regex="\\b(?:\\Q$1\\E" + shift + for attribute do + regex="$regex|\\Q$attribute\\E" + done + regex="$regex)\\b" + printf 'add-highlighter shared/crystal/code/attributes regex %s 0:attribute\n' "$regex" + + # Symbols + eval "set -- $kak_quoted_opt_crystal_operators" + # Avoid to match modules + regex="(?' regions - add-highlighter shared/crystal/pipe-string region '%Q?\|' '\|' regions - # Raw - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-literals - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-array-literal - # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html#percent-symbol-array-literal - add-highlighter shared/crystal/raw-parenthesis-string region -recurse '\(' '%[qwi]\(' '\)' fill string - add-highlighter shared/crystal/raw-bracket-string region -recurse '\[' '%[qwi]\[' '\]' fill string - add-highlighter shared/crystal/raw-brace-string region -recurse '\{' '%[qwi]\{' '\}' fill string - add-highlighter shared/crystal/raw-angle-string region -recurse '<' '%[qwi]<' '>' fill string - add-highlighter shared/crystal/raw-pipe-string region '%[qwi]\|' '\|' fill string - - # Here document - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#heredoc - add-highlighter shared/crystal/heredoc region -match-capture '<<-(\w+)' '^\h*(\w+)$' regions - # Raw - add-highlighter shared/crystal/raw-heredoc region -match-capture "<<-'(\w+)'" '^\h*(\w+)$' regions - add-highlighter shared/crystal/raw-heredoc/fill default-region fill string - add-highlighter shared/crystal/raw-heredoc/interpolation region -recurse '\{' '#\{' '\}' fill meta - - # Symbol - # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html - add-highlighter shared/crystal/quoted-symbol region ':"' '(?[imx]*' regions - add-highlighter shared/crystal/pipe-regex region '%r?\|' '\|[imx]*' regions + # https://crystal-lang.org/reference/syntax_and_semantics/literals/regex.html#interpolation + for id in regex parenthesis-regex bracket-regex brace-regex angle-regex pipe-regex; do + printf " + add-highlighter shared/crystal/$id/fill default-region fill meta + add-highlighter shared/crystal/$id/interpolation region -recurse '\\{' '#\\{' '\\}' ref crystal + " + done # Command - # https://crystal-lang.org/reference/syntax_and_semantics/literals/command.html - add-highlighter shared/crystal/command region '`' '(?' regions - add-highlighter shared/crystal/pipe-command region '%x?\|' '\|' regions +# Commands +# ‾‾‾‾‾‾‾‾ - evaluate-commands %sh[ - # Keywords - eval "set -- $kak_quoted_opt_crystal_keywords" - regex="\\b(?:\\Q$1\\E" - shift - for keyword do - regex="$regex|\\Q$keyword\\E" - done - regex="$regex)\\b" - printf 'add-highlighter shared/crystal/code/keywords regex %s 0:keyword\n' "$regex" - - # Attributes - eval "set -- $kak_quoted_opt_crystal_attributes" - regex="\\b(?:\\Q$1\\E" - shift - for attribute do - regex="$regex|\\Q$attribute\\E" - done - regex="$regex)\\b" - printf 'add-highlighter shared/crystal/code/attributes regex %s 0:attribute\n' "$regex" - - # Symbols - eval "set -- $kak_quoted_opt_crystal_operators" - # Avoid to match modules - regex="(?' - } - # Remove empty line indent - try %{ - execute-keys -draft 'ks^\h+$d' - } +define-command -hidden crystal-new-line-inserted %{ + # Copy previous line indent + try %{ + execute-keys -draft 'K' } - - define-command -hidden crystal-fetch-keywords %{ - set-register dquote %sh{ - curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | - kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' - } + # Remove empty line indent + try %{ + execute-keys -draft 'ks^\h+$d' } +} - define-command -hidden crystal-fetch-operators %{ - set-register dquote %sh{ - curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/parser.cr | - kak -f '/AtomicWithMethodCheck =x1s:"([^"]+)"y%i''a''a' - } +define-command -hidden crystal-fetch-keywords %{ + set-register dquote %sh{ + curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' } +} - define-command -hidden crystal-fetch-objects %{ - set-register dquote %sh{ - curl --location https://crystal-lang.org/api/ | - # Remove Top Level Namespace - kak -f '%1sdata-id="github.com/crystal-lang/crystal/(\w+)")y%aa' - } +define-command -hidden crystal-fetch-operators %{ + set-register dquote %sh{ + curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/parser.cr | + kak -f '/AtomicWithMethodCheck =x1s:"([^"]+)"y%i''a''a' } +} + +define-command -hidden crystal-fetch-objects %{ + set-register dquote %sh{ + curl --location https://crystal-lang.org/api/ | + # Remove Top Level Namespace + kak -f '%1sdata-id="github.com/crystal-lang/crystal/(\w+)")y%aa' + } +} + § From 591cb83da4603b8ac8c1dd868f701981756be9e7 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:39:08 -0600 Subject: [PATCH 06/27] Rename 'crystal-new-line-inserted' to 'crystal-indent-on-new-line' This gives the function clear responsibility, whereas the naming before was unclear --- rc/filetype/crystal.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 5a49c39b..0d5d1ca1 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -17,7 +17,7 @@ hook global WinSetOption filetype=crystal %{ add-highlighter window/crystal ref crystal evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} - hook window InsertChar '\n' -group crystal-indent crystal-new-line-inserted + hook window InsertChar '\n' -group crystal-indent crystal-indent-on-new-line hook -always -once window WinSetOption filetype=.* %{ remove-highlighter window/crystal @@ -175,7 +175,7 @@ evaluate-commands %sh[ # Commands # ‾‾‾‾‾‾‾‾ -define-command -hidden crystal-new-line-inserted %{ +define-command -hidden crystal-indent-on-new-line %{ # Copy previous line indent try %{ execute-keys -draft 'K' From 0c591baae3476ae0e60394c12f478f6c65f6fdc9 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:49:53 -0600 Subject: [PATCH 07/27] Add 'crystal-indent-on-char' and 'crystal-insert-on-new-line' hooks and functions --- rc/filetype/crystal.kak | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 0d5d1ca1..922321f1 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -17,7 +17,9 @@ hook global WinSetOption filetype=crystal %{ add-highlighter window/crystal ref crystal evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} + hook window InsertChar .* -group crystal-indent crystal-indent-on-char hook window InsertChar '\n' -group crystal-indent crystal-indent-on-new-line + hook window InsertChar '\n' -group crystal-insert crystal-insert-on-new-line hook -always -once window WinSetOption filetype=.* %{ remove-highlighter window/crystal @@ -186,6 +188,12 @@ define-command -hidden crystal-indent-on-new-line %{ } } +define-command -hidden crystal-insert-on-new-line %{ +} + +define-command -hidden crystal-indent-on-char %{ +} + define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | From b23a85e747ce94ec8708a44a3b97f2fc6db3055b Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:50:27 -0600 Subject: [PATCH 08/27] Beautify percent string literals highlighters spacing/indentation --- rc/filetype/crystal.kak | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 922321f1..6d8e7fbe 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -53,19 +53,20 @@ add-highlighter shared/crystal/string region '"' '(?' regions -add-highlighter shared/crystal/pipe-string region '%Q?\|' '\|' regions +add-highlighter shared/crystal/bracket-string region -recurse '\[' '%Q?\[' '\]' regions +add-highlighter shared/crystal/brace-string region -recurse '\{' '%Q?\{' '\}' regions +add-highlighter shared/crystal/angle-string region -recurse '<' '%Q?<' '>' regions +add-highlighter shared/crystal/pipe-string region '%Q?\|' '\|' regions + # Raw # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-literals # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#percent-string-array-literal # https://crystal-lang.org/reference/syntax_and_semantics/literals/symbol.html#percent-symbol-array-literal add-highlighter shared/crystal/raw-parenthesis-string region -recurse '\(' '%[qwi]\(' '\)' fill string -add-highlighter shared/crystal/raw-bracket-string region -recurse '\[' '%[qwi]\[' '\]' fill string -add-highlighter shared/crystal/raw-brace-string region -recurse '\{' '%[qwi]\{' '\}' fill string -add-highlighter shared/crystal/raw-angle-string region -recurse '<' '%[qwi]<' '>' fill string -add-highlighter shared/crystal/raw-pipe-string region '%[qwi]\|' '\|' fill string +add-highlighter shared/crystal/raw-bracket-string region -recurse '\[' '%[qwi]\[' '\]' fill string +add-highlighter shared/crystal/raw-brace-string region -recurse '\{' '%[qwi]\{' '\}' fill string +add-highlighter shared/crystal/raw-angle-string region -recurse '<' '%[qwi]<' '>' fill string +add-highlighter shared/crystal/raw-pipe-string region '%[qwi]\|' '\|' fill string # Here document # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html#heredoc From 73f5f32385f8147610e8413d19d94107bece0ccb Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:53:51 -0600 Subject: [PATCH 09/27] Wrap all 'indent-on-new-line' commands in 'evaluate-commands -no-hook -draft -itersel' --- rc/filetype/crystal.kak | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 6d8e7fbe..6bbf35da 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -179,13 +179,15 @@ evaluate-commands %sh[ # ‾‾‾‾‾‾‾‾ define-command -hidden crystal-indent-on-new-line %{ - # Copy previous line indent - try %{ - execute-keys -draft 'K' - } - # Remove empty line indent - try %{ - execute-keys -draft 'ks^\h+$d' + evaluate-commands -no-hooks -draft -itersel %{ + # Copy previous line indent + try %{ + execute-keys -draft 'K' + } + # Remove empty line indent + try %{ + execute-keys -draft 'ks^\h+$d' + } } } From 0063e4c4f5566a3c8d50cbc03702e540d91182cd Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:55:15 -0600 Subject: [PATCH 10/27] Collapse 'try %{ execute-keys ... }' blocks to one line --- rc/filetype/crystal.kak | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 6bbf35da..3482b80b 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -181,13 +181,9 @@ evaluate-commands %sh[ define-command -hidden crystal-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # Copy previous line indent - try %{ - execute-keys -draft 'K' - } + try %{ execute-keys -draft 'K' } # Remove empty line indent - try %{ - execute-keys -draft 'ks^\h+$d' - } + try %{ execute-keys -draft 'ks^\h+$d' } } } From 783fac3d61aad1a13273ce684f7294bd98847066 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:56:02 -0600 Subject: [PATCH 11/27] Remove single quotes from 'execute-keys -draft ...' keys --- rc/filetype/crystal.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 3482b80b..663ba26b 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -181,9 +181,9 @@ evaluate-commands %sh[ define-command -hidden crystal-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # Copy previous line indent - try %{ execute-keys -draft 'K' } + try %{ execute-keys -draft K } # Remove empty line indent - try %{ execute-keys -draft 'ks^\h+$d' } + try %{ execute-keys -draft k s ^\h+$ d } } } From 62ac42bb23968b0903cc0b6b5a8353f165edd3e6 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:58:21 -0600 Subject: [PATCH 12/27] Add 'crystal-trim-indent' command This removes trailing whitespaces from the end of lines --- rc/filetype/crystal.kak | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 663ba26b..3a895045 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -178,6 +178,14 @@ evaluate-commands %sh[ # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden crystal-trim-indent %{ + evaluate-commands -no-hooks -draft -itersel %{ + execute-keys + # remove trailing white spaces + try %{ execute-keys -draft s \h+$ d } + } +} + define-command -hidden crystal-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # Copy previous line indent @@ -196,7 +204,7 @@ define-command -hidden crystal-indent-on-char %{ define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | - kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' } } From ee842da85afc01a804890ee922ba0d8d0d31f34f Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 09:59:53 -0600 Subject: [PATCH 13/27] Replace manual whitespace trimming to use function created in prev. commit --- rc/filetype/crystal.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 3a895045..3f30e85a 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -190,8 +190,8 @@ define-command -hidden crystal-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # Copy previous line indent try %{ execute-keys -draft K } - # Remove empty line indent - try %{ execute-keys -draft k s ^\h+$ d } + # Remove previos line's trailing spaces + try %{ execute-keys -draft k :ruby-trim-indent } } } From 2c382de1e8033dd9f81af6fb67310e3d47f2b36a Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 10:08:47 -0600 Subject: [PATCH 14/27] Add indenting after starting structure/opening statement --- rc/filetype/crystal.kak | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 3f30e85a..5cece7c3 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -192,6 +192,8 @@ define-command -hidden crystal-indent-on-new-line %{ try %{ execute-keys -draft K } # Remove previos line's trailing spaces try %{ execute-keys -draft k :ruby-trim-indent } + # Indent after start structure/opening statement + try %{ execute-keys -draft k ^\h*(?:begin|case|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] j } } } @@ -204,7 +206,7 @@ define-command -hidden crystal-indent-on-char %{ define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | - kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' } } From 76eadef00b49519179a784e449570b84093b0971 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 10:27:51 -0600 Subject: [PATCH 15/27] Add rule to align else/elsif to opening if --- rc/filetype/crystal.kak | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 5cece7c3..8ce70714 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -201,12 +201,16 @@ define-command -hidden crystal-insert-on-new-line %{ } define-command -hidden crystal-indent-on-char %{ + evaluate-commands -no-hooks -draft -itersel %{ + # align 'else/elsif' to 'if' + try %{ execute-keys -draft ^\h*(?:else|elsif)$ ^\h*(?:if) 1 } + } } define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | - kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' } } From 21c083f47c84e56ba38227807d2f1aaef02b24fb Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 10:31:38 -0600 Subject: [PATCH 16/27] Add rule to align 'when' to 'case' --- rc/filetype/crystal.kak | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 8ce70714..96183054 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -204,6 +204,8 @@ define-command -hidden crystal-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ # align 'else/elsif' to 'if' try %{ execute-keys -draft ^\h*(?:else|elsif)$ ^\h*(?:if) 1 } + # align 'when' to 'case' + try %{ execute-keys -draft ^\h*(?:when)$ ^\h*(?:case) 1 } } } From 0fe71ebadaceadd7bda20bb69760a040cadae331 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 10:33:35 -0600 Subject: [PATCH 17/27] Add deindentation rule for 'rescue' statement --- rc/filetype/crystal.kak | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 96183054..9808cddd 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -206,13 +206,15 @@ define-command -hidden crystal-indent-on-char %{ try %{ execute-keys -draft ^\h*(?:else|elsif)$ ^\h*(?:if) 1 } # align 'when' to 'case' try %{ execute-keys -draft ^\h*(?:when)$ ^\h*(?:case) 1 } + # align 'rescue' to 'begin/def' + try %{ execute-keys -draft ^\h*(?:rescue)$ ^\h*(?:begin|def) 1 } } } define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | - kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' } } From 145f2db741d805a17efcbb71e68e153bb20641ad Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 10:35:34 -0600 Subject: [PATCH 18/27] Add rule to align 'end' with opening statement --- rc/filetype/crystal.kak | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 9808cddd..30a16e93 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -208,6 +208,8 @@ define-command -hidden crystal-indent-on-char %{ try %{ execute-keys -draft ^\h*(?:when)$ ^\h*(?:case) 1 } # align 'rescue' to 'begin/def' try %{ execute-keys -draft ^\h*(?:rescue)$ ^\h*(?:begin|def) 1 } + # align 'end' to opening structure + try %{ execute-keys -draft ^\h*(?:end)$ ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } } } From a6329b4bfc0efa101cb15ac6a6be558562ab54a6 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 11:18:41 -0600 Subject: [PATCH 19/27] Fix deindentation of `end` to make it go to the right level --- rc/filetype/crystal.kak | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 30a16e93..c6397a41 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -203,13 +203,13 @@ define-command -hidden crystal-insert-on-new-line %{ define-command -hidden crystal-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ # align 'else/elsif' to 'if' - try %{ execute-keys -draft ^\h*(?:else|elsif)$ ^\h*(?:if) 1 } + try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } # align 'when' to 'case' - try %{ execute-keys -draft ^\h*(?:when)$ ^\h*(?:case) 1 } + try %{ execute-keys -draft ^\h*(?:when)$ i ^\h*(?:case) 1 } # align 'rescue' to 'begin/def' - try %{ execute-keys -draft ^\h*(?:rescue)$ ^\h*(?:begin|def) 1 } + try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } # align 'end' to opening structure - try %{ execute-keys -draft ^\h*(?:end)$ ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } + try %{ execute-keys -draft ^\h*(?:end)$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } } } From 8f0843978e883c92d11a0679e17dde3e7d28fd65 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 11:19:36 -0600 Subject: [PATCH 20/27] Beautify indentation of 'crystal-indent-on-char' --- rc/filetype/crystal.kak | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index c6397a41..725a2b3d 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -203,13 +203,13 @@ define-command -hidden crystal-insert-on-new-line %{ define-command -hidden crystal-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ # align 'else/elsif' to 'if' - try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } + try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } # align 'when' to 'case' - try %{ execute-keys -draft ^\h*(?:when)$ i ^\h*(?:case) 1 } + try %{ execute-keys -draft ^\h*(?:when)$ i ^\h*(?:case) 1 } # align 'rescue' to 'begin/def' - try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } + try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } # align 'end' to opening structure - try %{ execute-keys -draft ^\h*(?:end)$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } + try %{ execute-keys -draft ^\h*(?:end)$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } } } From 0d4dfbc349f435047123ee23707d1c39a4cafca5 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 11:29:59 -0600 Subject: [PATCH 21/27] Implement copying comment char (#) and whitespace after it --- rc/filetype/crystal.kak | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 725a2b3d..dbb1168c 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -198,6 +198,10 @@ define-command -hidden crystal-indent-on-new-line %{ } define-command -hidden crystal-insert-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # Copy comment prefix and following whitespaces + try %{ execute-keys -draft k s '^\h*\K#\h*' y j gl p } + } } define-command -hidden crystal-indent-on-char %{ From c36583524cbe7908cd95438806948c6a702eb7c4 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 11:32:16 -0600 Subject: [PATCH 22/27] Reorder definition of 3 indent/insert commands --- rc/filetype/crystal.kak | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index dbb1168c..65378666 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -186,6 +186,19 @@ define-command -hidden crystal-trim-indent %{ } } +define-command -hidden crystal-indent-on-char %{ + evaluate-commands -no-hooks -draft -itersel %{ + # align 'else/elsif' to 'if' + try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } + # align 'when' to 'case' + try %{ execute-keys -draft ^\h*(?:when)$ i ^\h*(?:case) 1 } + # align 'rescue' to 'begin/def' + try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } + # align 'end' to opening structure + try %{ execute-keys -draft ^\h*(?:end)$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } + } +} + define-command -hidden crystal-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # Copy previous line indent @@ -204,19 +217,6 @@ define-command -hidden crystal-insert-on-new-line %{ } } -define-command -hidden crystal-indent-on-char %{ - evaluate-commands -no-hooks -draft -itersel %{ - # align 'else/elsif' to 'if' - try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } - # align 'when' to 'case' - try %{ execute-keys -draft ^\h*(?:when)$ i ^\h*(?:case) 1 } - # align 'rescue' to 'begin/def' - try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } - # align 'end' to opening structure - try %{ execute-keys -draft ^\h*(?:end)$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } - } -} - define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | From dbb548af2dce84dc557e81f1d7cd1c2951071ce4 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 11:46:35 -0600 Subject: [PATCH 23/27] Fill in implementation of `crystal-insert-on-new-line` --- rc/filetype/crystal.kak | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 65378666..1a55ffde 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -210,12 +210,29 @@ define-command -hidden crystal-indent-on-new-line %{ } } -define-command -hidden crystal-insert-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ +define-command -hidden crystal-insert-on-new-line %[ + evaluate-commands -no-hooks -draft -itersel %[ # Copy comment prefix and following whitespaces try %{ execute-keys -draft k s '^\h*\K#\h*' y j gl p } - } -} + + # Add `end` token if needs be + # The 'x' register is to save the leading whitespaces of the opening token + evaluate-commands -save-regs x %[ + # Save the leading whitespaces in register 'x' + try %{ execute-keys -draft k s ^\h* \" x y } + try %[ + evaluate-commands -draft %[ + # Make sure previous line opens a block + execute-keys -draft k ^x(?:begin|case|class|def|for|if|module|unless|until|while|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] + # Make sure `end` doesn't already exist on indent level + execute-keys -draft }i J ^x(?:end|else|elsif|rescue|when)[^0-9A-Za-z_!?] + ] + # Insert new line with end prepended by contents of register 'x' + execute-keys -draft o x end + ] + ] + ] +] define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ From e858df3ca288ce816068b2d163b7bbcbfdab90f8 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sat, 1 Aug 2020 12:12:48 -0600 Subject: [PATCH 24/27] Add 'else' to auto deindent/align logic in context of 'case' statement --- rc/filetype/crystal.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 1a55ffde..74c283d8 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -190,8 +190,8 @@ define-command -hidden crystal-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ # align 'else/elsif' to 'if' try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } - # align 'when' to 'case' - try %{ execute-keys -draft ^\h*(?:when)$ i ^\h*(?:case) 1 } + # align 'else/when' to 'case' + try %{ execute-keys -draft ^\h*(?:else|when)$ i ^\h*(?:case) 1 } # align 'rescue' to 'begin/def' try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } # align 'end' to opening structure From 6cf39a5f4f8e2e0fbc36389992287d61c32afe55 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sun, 2 Aug 2020 11:22:28 -0600 Subject: [PATCH 25/27] Fix auto indentation for if/case and else --- rc/filetype/crystal.kak | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 74c283d8..9f1e7210 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -188,14 +188,16 @@ define-command -hidden crystal-trim-indent %{ define-command -hidden crystal-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ - # align 'else/elsif' to 'if' - try %{ execute-keys -draft ^\h*(?:else|elsif)$ i ^\h*(?:if) 1 } - # align 'else/when' to 'case' - try %{ execute-keys -draft ^\h*(?:else|when)$ i ^\h*(?:case) 1 } + # align 'else' to 'if/case' + try %{ execute-keys -draft ^\h*else$ i ^\h*(?:if|case) 1 } + # align 'elsif' to 'if' + try %{ execute-keys -draft ^\h*elsif$ i ^\h*(?:if) 1 } + # align 'when' to 'case' + try %{ execute-keys -draft ^\h*when$ i ^\h*(?:case) 1 } # align 'rescue' to 'begin/def' - try %{ execute-keys -draft ^\h*(?:rescue)$ i ^\h*(?:begin|def) 1 } + try %{ execute-keys -draft ^\h*rescue$ i ^\h*(?:begin|def) 1 } # align 'end' to opening structure - try %{ execute-keys -draft ^\h*(?:end)$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } + try %{ execute-keys -draft ^\h*end$ i ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) 1 } } } From f59bdc614ff52726e6c08e23b61d994e875e1514 Mon Sep 17 00:00:00 2001 From: John Isom Date: Sun, 2 Aug 2020 11:33:56 -0600 Subject: [PATCH 26/27] Fix typo in comment --- rc/filetype/crystal.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 9f1e7210..3c4f5dfe 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -205,7 +205,7 @@ define-command -hidden crystal-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # Copy previous line indent try %{ execute-keys -draft K } - # Remove previos line's trailing spaces + # Remove previous line's trailing spaces try %{ execute-keys -draft k :ruby-trim-indent } # Indent after start structure/opening statement try %{ execute-keys -draft k ^\h*(?:begin|case|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] j } From 72f658f8969c6b19b338633d8881d89936c1f5dd Mon Sep 17 00:00:00 2001 From: John Isom Date: Sun, 2 Aug 2020 11:39:40 -0600 Subject: [PATCH 27/27] Replace my implementation of crystal-insert-on-new-line with already-existing ruby one This fixed a weird bug where if you were typing in the top level scope of a program (no indentation before statements), the `end`s wouldn't be inserted for you. --- rc/filetype/crystal.kak | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 3c4f5dfe..6e76b2da 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -214,23 +214,19 @@ define-command -hidden crystal-indent-on-new-line %{ define-command -hidden crystal-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ - # Copy comment prefix and following whitespaces - try %{ execute-keys -draft k s '^\h*\K#\h*' y j gl p } - - # Add `end` token if needs be - # The 'x' register is to save the leading whitespaces of the opening token + # copy _#_ comment prefix and following white spaces + try %{ execute-keys -draft k s '^\h*\K#\h*' y j P } + # wisely add end structure evaluate-commands -save-regs x %[ - # Save the leading whitespaces in register 'x' - try %{ execute-keys -draft k s ^\h* \" x y } + try %{ execute-keys -draft k s ^ \h + \" x y } catch %{ reg x '' } try %[ evaluate-commands -draft %[ - # Make sure previous line opens a block - execute-keys -draft k ^x(?:begin|case|class|def|for|if|module|unless|until|while|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] - # Make sure `end` doesn't already exist on indent level - execute-keys -draft }i J ^x(?:end|else|elsif|rescue|when)[^0-9A-Za-z_!?] + # Check if previous line opens a block + execute-keys -draft k ^x(?:begin|case|class|def|for|if|module|unless|until|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] + # Check that we do not already have an end for this indent level which is first set via `crystal-indent-on-new-line` hook + execute-keys -draft }i J ^x(?:end|else|elsif|rescue|when)[^0-9A-Za-z_!?] ] - # Insert new line with end prepended by contents of register 'x' - execute-keys -draft o x end + execute-keys -draft oxend # insert a new line with containing end ] ] ]