From 1a82caec13b163ca0271b3d1a607961d3b1e9d5a Mon Sep 17 00:00:00 2001 From: Benjamin VAUDOUR Date: Wed, 13 Oct 2021 20:49:48 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20=C3=A0=20elvish=200.17=20(3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/moi/alias.elv | 4 +-- lib/moi/completion.elv | 4 +-- lib/moi/completion/arc.elv | 2 +- lib/moi/completion/archiver.elv | 6 ++-- lib/moi/completion/desarchiver.elv | 2 +- lib/moi/completion/kcp.elv | 2 +- lib/moi/completion/mpv.elv | 2 +- lib/moi/completion/pacman.elv | 4 +-- lib/moi/completion/ssh.elv | 12 ++++---- lib/moi/completion/sudo.elv | 2 +- lib/moi/completion/use.elv | 2 +- lib/moi/util/common.elv | 4 +-- lib/moi/util/file.elv | 12 ++++---- lib/moi/util/ip.elv | 24 ++++++++-------- lib/moi/util/list.elv | 44 +++++++++++++++--------------- lib/moi/util/map.elv | 20 +++++++------- lib/moi/util/option.elv | 14 +++++----- lib/moi/util/strutil.elv | 26 +++++++++--------- 18 files changed, 93 insertions(+), 93 deletions(-) diff --git a/lib/moi/alias.elv b/lib/moi/alias.elv index 4b99d38..7b523c8 100644 --- a/lib/moi/alias.elv +++ b/lib/moi/alias.elv @@ -1,6 +1,6 @@ var dir = ~/.config/elvish/aliases -for file [(_ = ?(put $dir/*.elv))] { - content = (cat $file | slurp) +for file [(set _ = ?(put $dir/*.elv))] { + var content = (cat $file | slurp) eval $content } diff --git a/lib/moi/completion.elv b/lib/moi/completion.elv index eec40d8..fffb64f 100644 --- a/lib/moi/completion.elv +++ b/lib/moi/completion.elv @@ -1,8 +1,8 @@ #use github.com/zzamboni/elvish-completions/builtins use github.com/zzamboni/elvish-completions/cd use github.com/zzamboni/elvish-completions/git -git:git-command = hub -git:git-completions[checkout] = [ { git:MODIFIED; git:BRANCHES &all } ... ] +set git:git-command = hub +set git:git-completions[checkout] = [ { git:MODIFIED; git:BRANCHES &all } ... ] git:init #use github.com/zzamboni/elvish-completions/ssh diff --git a/lib/moi/completion/arc.elv b/lib/moi/completion/arc.elv index c8e0a2c..cfdb4b0 100644 --- a/lib/moi/completion/arc.elv +++ b/lib/moi/completion/arc.elv @@ -44,5 +44,5 @@ fn complete [@argv]{ } } -edit:completion:arg-completer[arc] = $complete~ +set edit:completion:arg-completer[arc] = $complete~ diff --git a/lib/moi/completion/archiver.elv b/lib/moi/completion/archiver.elv index 0962aeb..b536d21 100644 --- a/lib/moi/completion/archiver.elv +++ b/lib/moi/completion/archiver.elv @@ -1,4 +1,4 @@ -options = [ +var options = [ z l x @@ -7,7 +7,7 @@ options = [ h ] -description = [ +var description = [ &z='zst compression (default)' &l='lz4 compression' &x='xz compression' @@ -26,5 +26,5 @@ fn complete [@argv]{ edit:complete-getopt $argv [(-options)] [ $edit:complete-filename~ ...] } -edit:completion:arg-completer[archiver] = $complete~ +set edit:completion:arg-completer[archiver] = $complete~ diff --git a/lib/moi/completion/desarchiver.elv b/lib/moi/completion/desarchiver.elv index dd0b1ee..08fec76 100644 --- a/lib/moi/completion/desarchiver.elv +++ b/lib/moi/completion/desarchiver.elv @@ -9,4 +9,4 @@ fn complete [@argv]{ file:match-extensions &type=$type $m $@extensions } -edit:completion:arg-completer[desarchiver] = $complete~ +set edit:completion:arg-completer[desarchiver] = $complete~ diff --git a/lib/moi/completion/kcp.elv b/lib/moi/completion/kcp.elv index 4e420f9..68819e3 100644 --- a/lib/moi/completion/kcp.elv +++ b/lib/moi/completion/kcp.elv @@ -38,4 +38,4 @@ fn complete [@argv]{ } } -edit:completion:arg-completer[kcp] = $complete~ +set edit:completion:arg-completer[kcp] = $complete~ diff --git a/lib/moi/completion/mpv.elv b/lib/moi/completion/mpv.elv index e50aed9..4ebd30b 100644 --- a/lib/moi/completion/mpv.elv +++ b/lib/moi/completion/mpv.elv @@ -56,4 +56,4 @@ fn complete [@argv]{ } } -edit:completion:arg-completer[mpv] = $complete~ +set edit:completion:arg-completer[mpv] = $complete~ diff --git a/lib/moi/completion/pacman.elv b/lib/moi/completion/pacman.elv index 6885ad3..74b1016 100644 --- a/lib/moi/completion/pacman.elv +++ b/lib/moi/completion/pacman.elv @@ -15,7 +15,7 @@ fn -repo-packages { peach [p]{ str:split '/' $p } $packages | peach [e]{ - spackages[$e] = $nil + set spackages[$e] = $nil } keys $spackages all $packages @@ -102,4 +102,4 @@ fn complete [@argv]{ } } -edit:completion:arg-completer[pacman] = $complete~ +set edit:completion:arg-completer[pacman] = $complete~ diff --git a/lib/moi/completion/ssh.elv b/lib/moi/completion/ssh.elv index 3932971..5d08712 100644 --- a/lib/moi/completion/ssh.elv +++ b/lib/moi/completion/ssh.elv @@ -65,17 +65,17 @@ fn -complete-args [hosts cmd @argv]{ } var n h = $arg[..$i] $arg[(+ $i 1)..] if (eq $cmd scp) { - i = (str:index $h :) + set i = (str:index $h :) if (>= $i 0) { var d = $h[(+ $i 1)..] - h = $h[..$i] + set h = $h[..$i] if (list:includes $h $hosts) { var p = (-port $cmd @argv) var e = [ (str:split / $d) ] if (not-eq $e[-1] '') { - d = (str:join / $e[..-1]) + set d = (str:join / $e[..-1]) if (eq $d '') { - d = / + set d = / } } -complete-remote-dir $p $n@$h $d @@ -102,5 +102,5 @@ fn complete [@argv]{ } } -edit:completion:arg-completer[scp] = $complete~ -edit:completion:arg-completer[ssh] = $complete~ +set edit:completion:arg-completer[scp] = $complete~ +set edit:completion:arg-completer[ssh] = $complete~ diff --git a/lib/moi/completion/sudo.elv b/lib/moi/completion/sudo.elv index 1f68fa9..235550f 100644 --- a/lib/moi/completion/sudo.elv +++ b/lib/moi/completion/sudo.elv @@ -6,5 +6,5 @@ fn complete [@argv]{ } } -edit:completion:arg-completer[sudo] = $edit:complete-sudo~ +set edit:completion:arg-completer[sudo] = $edit:complete-sudo~ #edit:completion:arg-completer[sudo] = $-complete~ diff --git a/lib/moi/completion/use.elv b/lib/moi/completion/use.elv index 492ae88..480da25 100644 --- a/lib/moi/completion/use.elv +++ b/lib/moi/completion/use.elv @@ -12,7 +12,7 @@ var builtin_modules = [ unix ] -edit:completion:arg-completer[use] = [@argv]{ +set edit:completion:arg-completer[use] = [@argv]{ use str use path all $builtin_modules diff --git a/lib/moi/util/common.elv b/lib/moi/util/common.elv index cdf1d6e..07b5e63 100644 --- a/lib/moi/util/common.elv +++ b/lib/moi/util/common.elv @@ -21,7 +21,7 @@ edit:add-var abs~ [n]{ edit:add-var sum~ [@numbers]{ var s = 0 - each [e]{ s = (+ $s e) } (to-list $numbers) + each [e]{ set s = (+ $s e) } (to-list $numbers) } fn -minmax [t @numbers]{ @@ -32,7 +32,7 @@ fn -minmax [t @numbers]{ var m = $l[0] each [n]{ if ($t $n $m) { - m = $n + set m = $n } } $l[1..] put $m diff --git a/lib/moi/util/file.elv b/lib/moi/util/file.elv index 4c7cb2f..f0552fe 100644 --- a/lib/moi/util/file.elv +++ b/lib/moi/util/file.elv @@ -2,7 +2,7 @@ use str use ./list use ./map -search-type = [ +var search-type = [ &exact= [m]{ ls $m 2>/dev/null } &match= [m]{ put *$m* } &prefix= [m]{ put $m* } @@ -16,7 +16,7 @@ fn -less [f1 f2]{ var fl1 fl2 = (str:to-lower $f1) (str:to-lower $f2) var c = (str:compare $fl1 $fl2) if (== $c 0) { - c = (str:compare $f1 $f2) + set c = (str:compare $f1 $f2) } put (< $c 0) } @@ -32,12 +32,12 @@ fn -get-results [sort result]{ fn -search [&sort=$false &type=exact @motive]{ var f result = $search-type[$type] [&] if (list:empty $motive) { - result = (put * | map:to-set) + set result = (put * | map:to-set) } else { peach [m]{ try { $f $m | peach [e]{ - result[$e] = $nil + set result[$e] = $nil } } except e { } } $motive @@ -48,10 +48,10 @@ fn -search [&sort=$false &type=exact @motive]{ fn match-files [&sort=$false &type=prefix @motive]{ -search &sort=$sort &type=$type $@motive } fn match-extensions [&sort=$false &type=deep-prefix motive @extensions]{ - result = [&] + var result = [&] -search &type=$type $motive | peach [f]{ if (list:contains [e]{ str:has-suffix $f .$e } $extensions) { - result[$f] = $nil + set result[$f] = $nil } } -get-results $sort $result diff --git a/lib/moi/util/ip.elv b/lib/moi/util/ip.elv index c57755c..dfe701f 100644 --- a/lib/moi/util/ip.elv +++ b/lib/moi/util/ip.elv @@ -33,14 +33,14 @@ fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) } fn -long-part6 [p]{ use str - p = (str:to-lower $p) - c = (- 4 (count $p)) + set p = (str:to-lower $p) + var c = (- 4 (count $p)) put (repeat $c '0' | str:join '')$p } fn -middle-part6 [p]{ while (and (> (count $p) 1) (eq $p[0] 0)) { - p = $p[1..] + set p = $p[1..] } put $p } @@ -51,16 +51,16 @@ fn -find-max0 [parts]{ var ci cs f = -1 0 $false list:loop [i p]{ if (eq $p 0) { - condition:call $f { cs = (+ $cs 1) } { ci cs f = $i 1 $true } + condition:call $f { set cs = (+ $cs 1) } { set ci cs f = $i 1 $true } } elif $f { - f = $false + set f = $false if (> $cs $s) { - idx s = $ci $cs + set idx s = $ci $cs } } } $parts if (and $f (> $cs $s)) { - idx s = $ci $cs + set idx s = $ci $cs } put $idx $s } @@ -77,7 +77,7 @@ fn long6 [ip]{ if (> $c 0) { var i = (str:index $ip '::') var z = (repeat $c ':' | str:join '') - ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]]) + set ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]]) } str:split ':' $ip | each $-long-part6~ | str:join ':' } @@ -92,12 +92,12 @@ fn short6 [ip]{ if (>= $i 0) { var left right = $parts[..$i] $parts[(+ $i $s)..] if (== (count $left) 0) { - left = [''] + set left = [''] } if (== (count $right) 0) { - right = [''] + set right = [''] } - parts = [$@left '' $@right] + set parts = [$@left '' $@right] } str:join ':' $parts } @@ -110,7 +110,7 @@ fn -cmp [e1 e2]{ var c = 0 list:loop [i p1]{ var p2 = $e2[$i] - c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0)) + set c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0)) if (!= $c 0) { break } diff --git a/lib/moi/util/list.elv b/lib/moi/util/list.elv index a4b7277..2e4cfda 100644 --- a/lib/moi/util/list.elv +++ b/lib/moi/util/list.elv @@ -40,10 +40,10 @@ fn range [&step=1 b @r]{ var e = 0 if (== $c 0) { if (> $step 0) { - b e = $e $b + set b e = $e $b } } else { - e = $r[0] + set e = $r[0] } -r $step $b $e } @@ -58,16 +58,16 @@ fn indexes [&from=$false &step=1 @argv]{ range &step=$step (- $c 1) } else { if (< $from 0) { - from = (+ $c $from) + set from = (+ $c $from) } if (> $step 0) { if (< $from 0) { - from = 0 + set from = 0 } range &step=$step $from (- $c 1) } else { if (>= $from $c) { - from = (- $c 1) + set from = (- $c 1) } range &step=$step $from 0 } @@ -126,22 +126,22 @@ fn first [&from=$false &reverse=$false cb @argv]{ } else { var c = (count $l) if (< $from 0) { - from = (+ $c $from) + set from = (+ $c $from) } if $reverse { var e = (+ $from 1) if (> $e $c) { - e = $c + set e = $c } elif (< $e 0) { - e = 0 + set e = 0 } reach $f $l[..$e] } else { var b = $from if (> $b $c) { - b = $c + set b = $c } elif (< $b 0) { - b = 0 + set b = 0 } each $f $l[$b..] } @@ -160,11 +160,11 @@ fn first-index [&from=$false &reverse=$false cb @argv]{ var idx = -1 var step = 1 if $reverse { - step = -1 + set step = -1 } loop &from=$from &step=$step [i v]{ if ($cb $v) { - idx = $i + set idx = $i break } } $@argv @@ -182,7 +182,7 @@ fn search-not [cb @argv]{ search [i v]{ not ($cb $i $v) } $@argv } fn search-first [&from=$false &reverse=$false cb @argv]{ var step = 1 if $reverse { - step = -1 + set step = -1 } loop &from=$from &step=$step [i v]{ if ($cb $i $v) { @@ -204,11 +204,11 @@ fn search-first-index [&from=$false &reverse=$false cb @argv]{ var idx = -1 var step = 1 if $reverse { - step = -1 + set step = -1 } loop &from=$from &step=$step [i v]{ if ($cb $i $v) { - idx = $i + set idx = $i break } } $@argv @@ -219,7 +219,7 @@ fn contains [cb @argv]{ var e = $false each [v]{ if ($cb $v) { - e = $true + set e = $true break } } (-p $@argv) @@ -231,7 +231,7 @@ fn exists [cb @argv]{ var e = $false loop [i v]{ if ($cb $i $v) { - e = $true + set e = $true break } } $@argv @@ -243,7 +243,7 @@ fn includes [v @argv]{ contains [e]{ is $v $e } $@argv } fn includes-not [v @argv]{ contains-not [e]{ is $v $e } $@argv } fn reduce [v cb @argv]{ - each [e]{ v = ($cb $v $e) } (to-list $@argv) + each [e]{ set v = ($cb $v $e) } (to-list $@argv) put $v } @@ -251,7 +251,7 @@ fn remove-duplicate [@argv]{ var done = [&] each [v]{ put [&v=$v &e=(has-key $done $v)] - done[$v] = $nil + set done[$v] = $nil } (-p $@argv) | each [v]{ assoc $v k (not $v[e]) } | each [v]{ @@ -263,7 +263,7 @@ fn remove-duplicate [@argv]{ fn premove-duplicate [@argv]{ var done = [&] peach [v]{ - done[$v] = $nil + set done[$v] = $nil } (-p $@argv) keys $done } @@ -271,7 +271,7 @@ fn premove-duplicate [@argv]{ fn swap [i j @argv]{ var l = (-p $@argv) var c = (count $l) - i j = (-i $i $c) (-i $j $c) + set i j = (-i $i $c) (-i $j $c) if (or (== $i $c) (== $j $c)) { fail 'Index out of range' } @@ -279,7 +279,7 @@ fn swap [i j @argv]{ all $l } else { if (> $i $j) { - i j = $j $i + set i j = $j $i } take $i $l put $l[j] diff --git a/lib/moi/util/map.elv b/lib/moi/util/map.elv index e2b5692..aaafc45 100644 --- a/lib/moi/util/map.elv +++ b/lib/moi/util/map.elv @@ -14,8 +14,8 @@ fn value-of [container k &default=$nil]{ fn unzip [container]{ var lkeys lvalues = [] [] keys $container | each [k]{ - lkeys = [(all $lkeys) $k] - lvalues = [(all $lvalues) $container[$k]] + set lkeys = [(all $lkeys) $k] + set lvalues = [(all $lvalues) $container[$k]] } put $lkeys $lvalues } @@ -24,7 +24,7 @@ fn zip [lkeys lvalues]{ var ck cv = (count $lkeys) (count $lvalues) var c = $ck if (> $ck $cv) { - c = $cv + set c = $cv } var result = [&] range $c | peach [i]{ @@ -32,7 +32,7 @@ fn zip [lkeys lvalues]{ } | peach [e]{ assoc $e v $lvalues[$e[i]] } | each [e]{ - result[$e[k]] = $e[v] + set result[$e[k]] = $e[v] } put $result } @@ -46,13 +46,13 @@ fn to-map [@argv]{ fn to-set [@argv]{ use ./list var m = [&] - each [k]{ m[$k] = $nil } (list:to-list $@argv) + each [k]{ set m[$k] = $nil } (list:to-list $@argv) put $m } fn mdissoc [container @argv]{ each [k]{ - container = (dissoc $container $k) + set container = (dissoc $container $k) } $argv put $container } @@ -61,7 +61,7 @@ fn massoc [&replace=$true container @argv]{ each [e]{ var k v = $@e if (or $replace (not (has-key $container $k))) { - container[$k] = $v + set container[$k] = $v } } $argv put $container @@ -71,16 +71,16 @@ fn add [container key @values]{ use ./list var values = (list:to-list $values) if (has-key $container $key) { - container[$key] = [(all $container[$key]) $@values] + set container[$key] = [(all $container[$key]) $@values] } else { - container[$key] = $values + set container[$key] = $values } put $container } fn join [container container2]{ keys $container2 | each [k]{ - container[$k] = $container2[$k] + set container[$k] = $container2[$k] } put $container } diff --git a/lib/moi/util/option.elv b/lib/moi/util/option.elv index 08c6dea..4947468 100644 --- a/lib/moi/util/option.elv +++ b/lib/moi/util/option.elv @@ -42,7 +42,7 @@ fn join [@opt]{ each [i]{ -joins $opt[{$i0}:$i] put $opt[$i] - i0 = (+ $i 1) + set i0 = (+ $i 1) } $idx -joins $opt[{$i0}:] } @@ -51,7 +51,7 @@ fn expand [@argv]{ each $split~ (list:-p $@argv) } fn map [@argv]{ use ./map - argv = [(expand $@argv)] + set argv = [(expand $@argv)] var result i c = [&] 0 (count $argv) while (< $i $c) { var o = $argv[$i] @@ -60,15 +60,15 @@ fn map [@argv]{ if (< $i (- $c 1)) { var e = $argv[(+ $i 1)] if (not (is-option $e)) { - v = [$@v $e] - i = (+ $i 1) + set v = [$@v $e] + set i = (+ $i 1) } } - result = (map:add $result $k $@v) + set result = (map:add $result $k $@v) } else { - result = (map:add $result '' [$o]) + set result = (map:add $result '' [$o]) } - i = (+ $i 1) + set i = (+ $i 1) } put $result } diff --git a/lib/moi/util/strutil.elv b/lib/moi/util/strutil.elv index 0774be4..9a9fdc8 100644 --- a/lib/moi/util/strutil.elv +++ b/lib/moi/util/strutil.elv @@ -49,36 +49,36 @@ fn -c2map [col]{ var k = (kind-of $c) var cf = [&min=0] if (is $k string) { - cf[min] = $c + set cf[min] = $c } elif (is $k map) { if (has-key $c min) { - cf[min] = $c[min] + set cf[min] = $c[min] } if (has-key $c align) { - cf[align] = $c[align] + set cf[align] = $c[align] } } - col[$i] = $cf + set col[$i] = $cf } $col put $col } fn -parsecols [col &split=$false lst]{ - col = (-c2map $col) + set col = (-c2map $col) var cc lines = (count $col) $lst if $split { - lines = [ (eawk [_ @args]{ put $args } $lst) ] + set lines = [ (eawk [_ @args]{ put $args } $lst) ] } each [l]{ var cl = (count $l) if (> $cl $cc) { - col = [ $@col (range (- $cl $cc) | each [_]{ put [&align=left &min=0] }) ] - cc = $cl + set col = [ $@col (range (- $cl $cc) | each [_]{ put [&align=left &min=0] }) ] + set cc = $cl } list:loop [i c]{ var ccl = (+ (count $c) 1) if (> $ccl $col[$i][min]) { - col[$i][min] = $ccl + set col[$i][min] = $ccl } } $l } $lines @@ -90,9 +90,9 @@ fn -format [f e]{ if (has-key $f align) { var a = $f[align] if (is $a right) { - cb = $right~ + set cb = $right~ } elif (is $a center) { - cb = $center~ + set cb = $center~ } } $cb $f[min] $e @@ -107,8 +107,8 @@ fn -formatline [col line]{ fn format [&col=[] &split=$false @lst]{ var lines = (list:-p $@lst) if $split { - lines = [ (eawk [l @args]{ put $args } $lines) ] + set lines = [ (eawk [l @args]{ put $args } $lines) ] } - col = (-parsecols $col $lines) + set col = (-parsecols $col $lines) each [l]{ -formatline $col $l } $lines }