From 488798d977c4e2c3c8607bce932dd89656c1899b Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Wed, 28 Apr 2021 21:27:43 -0400 Subject: [PATCH] improve colors for rust/solarized * bring colors more aligned with upstream solarized implementations (e.g. vim, emacs) * tweak rust syntax * add more details, like operators, highlighting certain traits and types from std, etc * remove certain highlighters, like user types. This has the effect of just highlighting almost the whole code base one color, and wasn't really correct either. CamelCase for types is only convention --- colors/solarized-dark.kak | 4 +-- rc/filetype/rust.kak | 52 +++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/colors/solarized-dark.kak b/colors/solarized-dark.kak index ddb1fee6..ccbeb4f7 100644 --- a/colors/solarized-dark.kak +++ b/colors/solarized-dark.kak @@ -21,13 +21,13 @@ evaluate-commands %sh{ echo " # code face global value ${cyan} - face global type ${red} + face global type ${yellow} face global variable ${blue} face global module ${cyan} face global function ${blue} face global string ${cyan} face global keyword ${green} - face global operator ${yellow} + face global operator ${green} face global attribute ${violet} face global comment ${base01} face global documentation comment diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index 8f9627ec..5b0c0261 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -67,28 +67,38 @@ add-highlighter shared/rust/macro_attributes/ default-region fill meta add-highlighter shared/rust/macro_attributes/string region %{(?]+?>)?\( 1:function -add-highlighter shared/rust/code/variable_declaration regex (?:let\h+(?:mut\h+)?)(_?\w+) 1:variable -add-highlighter shared/rust/code/macro regex \b[A-z0-9_]+! 0:meta -# the number literals syntax is defined here: -# https://doc.rust-lang.org/reference/tokens.html#numbers -add-highlighter shared/rust/code/values regex \b(?:self|true|false|[0-9][_0-9]*(?:\.[0-9][_0-9]*|(?:\.[0-9][_0-9]*)?E[\+\-][_0-9]+)(?:f(?:32|64))?|(?:0x[_0-9a-fA-F]+|0o[_0-7]+|0b[_01]+|[0-9][_0-9]*)(?:(?:i|u|f)(?:8|16|32|64|128|size))?)\b 0:value -add-highlighter shared/rust/code/attributes regex \b(?:trait|struct|enum|union|type|mut|ref|static|const|default)\b 0:attribute -# the language keywords are defined here, but many of them are reserved and unused yet: -# https://doc.rust-lang.org/reference/keywords.html -add-highlighter shared/rust/code/keywords regex \b(?:let|as|fn|return|match|if|else|loop|for|in|while|break|continue|move|box|where|impl|dyn|pub|unsafe|async|await|mod|crate|use|extern)\b 0:keyword -add-highlighter shared/rust/code/char_character regex "'([^\\]|\\(.|x[0-9a-fA-F]{2}|u\{[0-9a-fA-F]{1,6}\}))'" 0:green -# TODO highlight error for unicode or single escape byte character -add-highlighter shared/rust/code/byte_character regex b'([\x00-\x5B\x5D-\x7F]|\\(.|x[0-9a-fA-F]{2}))' 0:yellow -add-highlighter shared/rust/code/builtin_types regex \b(?:u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize|f32|f64|bool|char|str|Self)\b 0:type -add-highlighter shared/rust/code/return regex \breturn\b 0:meta +add-highlighter shared/rust/code/operators_arithmetic regex (\+|-|/|\*|=|\^|&|\||!|>|<|%)=? 0:operator +add-highlighter shared/rust/code/operators_as regex \bas\b 0:operator +add-highlighter shared/rust/code/ref_ref regex (&\h+[&~@*])[^)=\s\t\r\n] 1:type +add-highlighter shared/rust/code/ref regex ([&~@*])[^)=\s\t\r\n] 1:type +add-highlighter shared/rust/code/operators_logic regex &&|\|\| 0:operator +add-highlighter shared/rust/code/lifetime_or_loop_label regex ('([a-zA-Z]\w+|_\w+))\b 1:meta +add-highlighter shared/rust/code/namespace regex \b[a-zA-Z](\w+)?(\h+)?(?=::) 0:module +add-highlighter shared/rust/code/mod_path_sep regex :: 0:meta +add-highlighter shared/rust/code/question_mark regex \? 0:meta +# the language keywords are defined here, but many of them are reserved and unused yet: +# https://doc.rust-lang.org/reference/keywords.html +add-highlighter shared/rust/code/function_call regex _?[a-zA-Z]\w*\s*(?=\() 0:function +add-highlighter shared/rust/code/generic_function_call regex _?[a-zA-Z]\w*\s*(?=::<) 0:function +add-highlighter shared/rust/code/function_declaration regex (?:fn\h+)(_?\w+)(?:<[^>]+?>)?\( 1:function +add-highlighter shared/rust/code/keywords regex \b(?:let|as|fn|return|match|if|else|loop|for|in|while|break|continue|box|where|impl|dyn|unsafe|async|await|mod|crate|use|extern|trait|struct|enum|union|type|default)\b 0:keyword +add-highlighter shared/rust/code/storage regex \b(move|mut|ref|static|const)\b 0:type +# after let can be an arbitrary pattern match +add-highlighter shared/rust/code/macro regex \b\w+! 0:meta +# the number literals syntax is defined here: +# https://doc.rust-lang.org/reference/tokens.html#numb ers +add-highlighter shared/rust/code/values regex \b(?:self|true|false|[0-9][_0-9]*(?:\.[0-9][_0-9]*|(?:\.[0-9][_0-9]*)?E[\+\-][_0-9]+)(?:f(?:32|64))?|(?:0x[_0-9a-fA-F]+|0o[_0-7]+|0b[_01]+|[0-9][_0-9]*)(?:(?:i|u|f)(?:8|16|32|64|128|size))?)\b 0:value +add-highlighter shared/rust/code/char_character regex "'([^\\]|\\(.|x[0-9a-fA-F]{2}|u\{[0-9a-fA-F]{1,6}\}))'" 0:green +# TODO highlight error for unicode or single escape by te character +add-highlighter shared/rust/code/byte_character regex b'([\x00-\x5B\x5D-\x7F]|\\(.|x[0-9a-fA-F]{2}))' 0:yellow +add-highlighter shared/rust/code/builtin_types regex \b(?:u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize|f32|f64|bool|char|str|Self)\b 0:type +add-highlighter shared/rust/code/return regex \breturn\b 0:meta + +add-highlighter shared/rust/code/enum regex \b(Option|Result)\b 0:type +add-highlighter shared/rust/code/enum_variant regex \b(Some|None|Ok|Err)\b 0:value +add-highlighter shared/rust/code/std_traits regex \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|SliceConcatExt|String|ToString|Vec)\b 0:type + # Commands # ‾‾‾‾‾‾‾‾