Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 8443a64

Browse files
agentydragondbarnett
authored andcommitted
Add cljstyle formatter
1 parent 048baf8 commit 8443a64

File tree

5 files changed

+115
-1
lines changed

5 files changed

+115
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ helpfiles in the `doc/` directory. The helpfiles are also available via
1212

1313
* [Bazel](https://www.github.com/bazelbuild/bazel) BUILD files (buildifier)
1414
* C, C++ (clang-format)
15-
* [Clojure](https://clojure.org/) ([zprint](https://github.com/kkinnear/zprint))
15+
* [Clojure](https://clojure.org/) ([zprint](https://github.com/kkinnear/zprint),
16+
[cljstyle](https://github.com/greglook/cljstyle))
1617
* CSS, Sass, SCSS, Less (js-beautify)
1718
* Dart (dartfmt)
1819
* Fish ([fish_indent](https://fishshell.com/docs/current/commands.html#fish_indent))

autoload/codefmt/cljstyle.vim

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
" Copyright 2019 Google Inc. All rights reserved.
2+
"
3+
" Licensed under the Apache License, Version 2.0 (the "License");
4+
" you may not use this file except in compliance with the License.
5+
" You may obtain a copy of the License at
6+
"
7+
" http://www.apache.org/licenses/LICENSE-2.0
8+
"
9+
" Unless required by applicable law or agreed to in writing, software
10+
" distributed under the License is distributed on an "AS IS" BASIS,
11+
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
" See the License for the specific language governing permissions and
13+
" limitations under the License.
14+
15+
16+
let s:plugin = maktaba#plugin#Get('codefmt')
17+
18+
19+
""
20+
" @private
21+
" Formatter: cljstyle
22+
function! codefmt#cljstyle#GetFormatter() abort
23+
let l:formatter = {
24+
\ 'name': 'cljstyle',
25+
\ 'setup_instructions':
26+
\ 'Install cljstyle (https://github.com/greglook/cljstyle) ' .
27+
\ 'and configure the cljstyle_executable flag'}
28+
29+
function l:formatter.IsAvailable() abort
30+
return executable(s:plugin.Flag('cljstyle_executable'))
31+
endfunction
32+
33+
function l:formatter.AppliesToBuffer() abort
34+
return &filetype is# 'clojure'
35+
endfunction
36+
37+
""
38+
" Reformat the current buffer with cljstyle.
39+
"
40+
" We implement Format(), and not FormatRange{,s}(), because cljstyle doesn't
41+
" provide a hook for formatting a range
42+
function l:formatter.Format() abort
43+
let l:cmd = [s:plugin.Flag('cljstyle_executable'), 'pipe']
44+
45+
call codefmt#formatterhelpers#Format(l:cmd)
46+
endfunction
47+
48+
return l:formatter
49+
endfunction

instant/flags.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,7 @@ call s:plugin.Flag('nixpkgs_fmt_executable', 'nixpkgs-fmt')
176176
""
177177
" The path to the luaformatterfiveone executable.
178178
call s:plugin.Flag('luaformatterfiveone_executable', 'luaformatterfiveone')
179+
180+
""
181+
" The path to the cljstyle executable.
182+
call s:plugin.Flag('cljstyle_executable', 'cljstyle')

plugin/register.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ call s:registry.AddExtension(codefmt#prettier#GetFormatter())
2727
call s:registry.AddExtension(codefmt#rustfmt#GetFormatter())
2828
call s:registry.AddExtension(codefmt#jsbeautify#GetFormatter())
2929
call s:registry.AddExtension(codefmt#clangformat#GetFormatter())
30+
call s:registry.AddExtension(codefmt#cljstyle#GetFormatter())
3031
call s:registry.AddExtension(codefmt#gofmt#GetFormatter())
3132
call s:registry.AddExtension(codefmt#dartfmt#GetFormatter())
3233
call s:registry.AddExtension(codefmt#black#GetFormatter())

vroom/cljstyle.vroom

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
The cljstyle formatter knows how to format Clojure.
2+
If you aren't familiar with basic codefmt usage yet, see main.vroom first.
3+
4+
We'll set up codefmt and configure the vroom environment, then jump into some
5+
examples.
6+
7+
:source $VROOMDIR/setupvroom.vim
8+
9+
:let g:repeat_calls = []
10+
:function FakeRepeat(...)<CR>
11+
| call add(g:repeat_calls, a:000)<CR>
12+
:endfunction
13+
:call maktaba#test#Override('repeat#set', 'FakeRepeat')
14+
15+
:call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0)
16+
17+
The cljstyle formatter expects the cljstyle executable to be installed on your
18+
system.
19+
20+
:FormatCode cljstyle
21+
! cljstyle .*
22+
$ no-op
23+
24+
The name or path of the cljstyle executable can be configured via the
25+
cljstyle_executable flag if the default of "cljstyle" doesn't work.
26+
27+
:Glaive codefmt cljstyle_executable='/usr/local/bin/cljstyle'
28+
:FormatCode cljstyle
29+
! /usr/local/bin/cljstyle .*
30+
$ no-op
31+
:Glaive codefmt cljstyle_executable='cljstyle'
32+
33+
You can format an entire buffer with :FormatCode.
34+
35+
@clear
36+
% (defn x [] (cond nil 1 :else 2))<CR>
37+
|(defn y [] (cond nil 3 :else 4))
38+
39+
:FormatCode cljstyle
40+
! cljstyle .*
41+
$ (defn x
42+
$ []
43+
$ (cond nil 1
44+
$ :else 2))
45+
$ (defn y
46+
$ []
47+
$ (cond nil 3
48+
$ :else 4))
49+
(defn x
50+
[]
51+
(cond nil 1
52+
:else 2))
53+
(defn y
54+
[]
55+
(cond nil 3
56+
:else 4))
57+
@end
58+
59+
Formatting a specific line range is not supported.

0 commit comments

Comments
 (0)