From 3ab714983993765321494b04a6d5208bc96a2da2 Mon Sep 17 00:00:00 2001 From: Bahex <17417311+Bahex@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:19:04 +0300 Subject: [PATCH 1/5] add commas between items in single line lists and records --- languages/nu.scm | 18 ++++++++++++++++-- test/expected_ctrl.nu | 4 ++-- test/expected_data.nu | 10 +++++----- test/expected_exe.nu | 10 +++++----- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/languages/nu.scm b/languages/nu.scm index b6306c6..efe1635 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -280,9 +280,16 @@ ) @prepend_input_softline (list_body - entry: _ @append_space + (_) @append_delimiter . - entry: _ @prepend_spaced_softline + (_) + (#delimiter! ",") + (#single_line_only!) +) +(list_body + entry: (_) @append_space + . + entry: (_) @prepend_spaced_softline ) ;; match_arm @@ -302,6 +309,13 @@ entry: (record_entry) @prepend_spaced_softline ) +(record_body + entry: (record_entry) @append_delimiter + . + entry: (record_entry) + (#delimiter! ",") + (#single_line_only!) +) (record_body entry: (record_entry) @append_space . diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index 4c4c150..264761f 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -1,5 +1,5 @@ # for -for i in [1 2 3] { +for i in [1, 2, 3] { # if if (true or false) { print "break"; break # break @@ -14,7 +14,7 @@ alias ll = ls -l # alias comment ls | where $in.name == 'foo' | where {|e| $e.item.name !~ $'^($e.index + 1)' } # match -let foo = {name: 'bar' count: 7} +let foo = {name: 'bar', count: 7} match $foo { {name: 'bar' count: $it} if $it < 5 => ($it + 3) # match arm comment # match comment diff --git a/test/expected_data.nu b/test/expected_data.nu index d1ffe71..6deb081 100644 --- a/test/expected_data.nu +++ b/test/expected_data.nu @@ -38,7 +38,7 @@ export const config = { { name: ws_listener pos: left - events: [aerospace_workspace_change space_windows_change] + events: [aerospace_workspace_change, space_windows_change] args: { updates: on drawing: off @@ -48,7 +48,7 @@ export const config = { { name: front_app pos: left - events: [front_app_switched aerospace_mode_change] + events: [front_app_switched, aerospace_mode_change] args: { label.color: $colors.black icon.color: $colors.black @@ -112,7 +112,7 @@ export const config = { } { name: battery - events: [system_woke power_source_change] + events: [system_woke, power_source_change] args: { update_freq: 120 script: '{}/battery.nu' @@ -247,7 +247,7 @@ export const config = { ] } -const table = [[a b]; [1 2] [2 [4 4]]] -const table_no_row = [[a b]; ] +const table = [[a, b]; [1, 2] [2, [4, 4]]] +const table_no_row = [[a, b]; ] mut foo: record<"a", b, "c": int, d: list> = {} diff --git a/test/expected_exe.nu b/test/expected_exe.nu index 9e6dae6..03d86e0 100644 --- a/test/expected_exe.nu +++ b/test/expected_exe.nu @@ -21,13 +21,13 @@ def modify_args_per_workspace [ ) let extra = ( if $sid == $focused_sid { - {highlight: on border_color: $colors.green} + {highlight: on, border_color: $colors.green} } else { - {highlight: off border_color: $colors.fg} + {highlight: off, border_color: $colors.fg} } ) - ['--set' $"space.($sid)"] + ['--set', $"space.($sid)"] | append ( if (($icons | is-empty) and ($sid != $focused_sid)) { [ @@ -58,14 +58,14 @@ def workspace_modification_args [ let ids_to_modify = ( if ($last_sid | is-empty) { (aerospace list-workspaces --all | lines) } else { - [$focused_sid $last_sid] + [$focused_sid, $last_sid] } ) $ids_to_modify | uniq | each { modify_args_per_workspace $in $focused_sid } | flatten - | append ["--set" $name $"label=($focused_sid)"] + | append ["--set", $name, $"label=($focused_sid)"] } # remained for other possible signals From c193a7cf413721da0092ec22c486179e4a0bf3ed Mon Sep 17 00:00:00 2001 From: Bahex <17417311+Bahex@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:19:04 +0300 Subject: [PATCH 2/5] insert commas between pattern items --- languages/nu.scm | 26 ++++++++++++++++++++++---- test/expected_ctrl.nu | 8 +++++--- test/input_ctrl.nu | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/languages/nu.scm b/languages/nu.scm index efe1635..4e90480 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -294,9 +294,17 @@ ;; match_arm (val_list - entry: _ @append_space + entry: (_) @append_delimiter + ;; unlike list expressions, list patterns include commas as anonymous nodes. + ;; this is required to avoid adding multiple commas + ","* @do_nothing + entry: (_) + (#delimiter! ",") +) +(val_list . - entry: _ @prepend_spaced_softline + entry: (_) + entry: (_) @prepend_spaced_softline ) (val_table @@ -304,9 +312,19 @@ ) (val_record - entry: (record_entry) @append_space + entry: (_) @append_delimiter + ;; unlike record expressions, record patterns include commas as anonymous nodes. + ;; this is required to avoid adding multiple commas + ","* @do_nothing + entry: (_) + (#delimiter! ",") +) +(val_record . - entry: (record_entry) @prepend_spaced_softline + ;; record patterns can use `{ $foo }` as a shorthand for `{ foo: $foo }` + ;; so we can's use record_entry here + entry: (_) + entry: (_) @prepend_spaced_softline ) (record_body diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index 264761f..ab0c8f5 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -16,13 +16,15 @@ ls | where $in.name == 'foo' # match let foo = {name: 'bar', count: 7} match $foo { - {name: 'bar' count: $it} if $it < 5 => ($it + 3) # match arm comment + {name: 'bar', count: $it} if $it < 5 => ($it + 3) # match arm comment # match comment - {name: 'bar' count: $it} if not ($it >= 5) => ($it + 7) + {name: 'bar', count: $it} if not ($it >= 5) => ($it + 7) + # record shorthand + {$name, $count} => $'($name): ($count)' _ => { exit 0 } } match $foo { - [a b c] => 0 + [a, b, c] => 0 } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment diff --git a/test/input_ctrl.nu b/test/input_ctrl.nu index 9903493..6e0e5b7 100644 --- a/test/input_ctrl.nu +++ b/test/input_ctrl.nu @@ -19,6 +19,8 @@ match $foo { { name: 'bar' count: $it } if $it < 5 => ($it + 3), # match arm comment # match comment { name: 'bar' count: $it } if not ($it >= 5) => ($it + 7), + # record shorthand + { $name $count } => $'($name): ($count)', _ => {exit 0} } match $foo { From f3342d8e2ff91eedd3bbf2acd6bb21b5a54ff436 Mon Sep 17 00:00:00 2001 From: Bahex <17417311+Bahex@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:19:04 +0300 Subject: [PATCH 3/5] insert spaces around alternate pattern delimiter ('|') --- languages/nu.scm | 2 ++ test/expected_ctrl.nu | 1 + test/input_ctrl.nu | 1 + 3 files changed, 4 insertions(+) diff --git a/languages/nu.scm b/languages/nu.scm index 4e90480..c634ff0 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -260,6 +260,8 @@ (default_arm)? @prepend_spaced_softline ) +(match_pattern "|" @prepend_spaced_softline @append_space ) + ;; data structures (command_list [ diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index ab0c8f5..6de25d5 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -25,6 +25,7 @@ match $foo { } match $foo { [a, b, c] => 0 + a | b | c => 42 } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment diff --git a/test/input_ctrl.nu b/test/input_ctrl.nu index 6e0e5b7..5b8e9b0 100644 --- a/test/input_ctrl.nu +++ b/test/input_ctrl.nu @@ -25,6 +25,7 @@ match $foo { } match $foo { [ a b c] => 0 + a|b|c => 42 } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment From b3c8fcdfda71dfe52cfca86bb470125d11cd8435 Mon Sep 17 00:00:00 2001 From: Bahex <17417311+Bahex@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:19:04 +0300 Subject: [PATCH 4/5] insert space before closing brace in single line match expression --- languages/nu.scm | 1 + test/expected_ctrl.nu | 1 + test/input_ctrl.nu | 1 + 3 files changed, 3 insertions(+) diff --git a/languages/nu.scm b/languages/nu.scm index c634ff0..b250dfd 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -258,6 +258,7 @@ scrutinee: _? @append_space (match_arm)? @prepend_spaced_softline (default_arm)? @prepend_spaced_softline + "}"? @prepend_spaced_softline ) (match_pattern "|" @prepend_spaced_softline @append_space ) diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index 6de25d5..fdc3a72 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -27,6 +27,7 @@ match $foo { [a, b, c] => 0 a | b | c => 42 } +match $foo { null => { return "default" } $val => $val } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop diff --git a/test/input_ctrl.nu b/test/input_ctrl.nu index 5b8e9b0..e878b5a 100644 --- a/test/input_ctrl.nu +++ b/test/input_ctrl.nu @@ -27,6 +27,7 @@ match $foo { [ a b c] => 0 a|b|c => 42 } +match $foo {null => {return "default"} $val => $val} # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop From 51d9a1b83101a5a7ea6e5c192fd5ee984358b612 Mon Sep 17 00:00:00 2001 From: Bahex <17417311+Bahex@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:19:04 +0300 Subject: [PATCH 5/5] insert delimiters between match arms on a single line --- languages/nu.scm | 11 +++++++++++ test/expected_ctrl.nu | 2 +- test/input_ctrl.nu | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/languages/nu.scm b/languages/nu.scm index b250dfd..eb1081a 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -261,6 +261,17 @@ "}"? @prepend_spaced_softline ) +; append delimiter after match_arms in single line match expressions +(ctrl_match + "match" + scrutinee: _ + (_) @append_delimiter + . + (_) + (#delimiter! ",") + (#single_line_only!) +) + (match_pattern "|" @prepend_spaced_softline @append_space ) ;; data structures diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index fdc3a72..4363612 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -27,7 +27,7 @@ match $foo { [a, b, c] => 0 a | b | c => 42 } -match $foo { null => { return "default" } $val => $val } +match $foo { null => { return "default" }, 1 => "one", 2 => "two", $val => $val } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop diff --git a/test/input_ctrl.nu b/test/input_ctrl.nu index e878b5a..061ba19 100644 --- a/test/input_ctrl.nu +++ b/test/input_ctrl.nu @@ -27,7 +27,7 @@ match $foo { [ a b c] => 0 a|b|c => 42 } -match $foo {null => {return "default"} $val => $val} +match $foo {null => {return "default"} 1 => "one" 2 => "two" $val => $val} # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop