-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
The built-in JuliaFormatter formatter knows how to format Julia files. If you | ||
aren't familiar with basic codefmt usage yet, see main.vroom first. | ||
|
||
We'll set up codefmt and configure the vroom environment, then jump into some | ||
examples. | ||
|
||
:source $VROOMDIR/setupvroom.vim | ||
|
||
:let g:repeat_calls = [] | ||
:function FakeRepeat(...)<CR> | ||
| call add(g:repeat_calls, a:000)<CR> | ||
:endfunction | ||
:call maktaba#test#Override('repeat#set', 'FakeRepeat') | ||
|
||
:call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0) | ||
|
||
|
||
The JuliaFormatter formatter uses the bin/julia/format.jl script which is | ||
bundled with codefmt. That script will return an error if Julia or the | ||
JuliaFormatter package are not installed. | ||
|
||
% module Foo bar(x) = x ? "yes" : "no" end | ||
:FormatCode JuliaFormatter | ||
! .*/bin/julia/format.jl .* | ||
$ module Foo { | ||
$ function bar(x) | ||
$ if x | ||
$ "yes" | ||
$ else | ||
$ "no" | ||
$ end | ||
$ end | ||
$ end | ||
|
||
The name or path of the format.jl script can be configured via the | ||
julia_format_executable flag if the bundled format.jl doesn't work. | ||
|
||
:Glaive codefmt julia_format_executable='/path/to/myscript' | ||
:FormatCode JuliaFormatter | ||
! /path/to/myscript .* | ||
$ module Foo | ||
$ function bar(x) | ||
$ if x | ||
$ "yes" | ||
$ else | ||
$ "no" | ||
$ end | ||
$ end | ||
$ end | ||
:let g:format_jl = maktaba#path#Join([expand("$VROOMDIR:h:h"), 'bin', 'julia', 'format.jl']) | ||
:Glaive codefmt julia_format_executable=`g:format_jl` | ||
|
||
It can format specific line ranges of code using :FormatLines. | ||
|
||
@clear | ||
% module Foo<CR> | ||
|function bar(x)<CR> | ||
|print(x ? "yes" : "no")<CR> | ||
|print(<CR> | ||
|x &&<CR> | ||
|!x ?<CR> | ||
|"impossible" :<CR> | ||
|"ok")<CR> | ||
|end<CR> | ||
|end | ||
|
||
:4,8FormatLines JuliaFormatter | ||
! .*/bin/julia/format.jl .*--lines 4:8.* | ||
$ module Foo { | ||
$ function bar(x) | ||
$ print(x ? "yes" : "no") | ||
$ print(if x && !x | ||
$ "impossible" | ||
$ else | ||
$ "ok" | ||
$ end) | ||
$ end | ||
$ end |