Skip to content

Commit

Permalink
Add support for native Vim/ALE
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereOverfl0w committed Apr 21, 2017
1 parent 82cd2cb commit 7dea5eb
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/output
/clojure-check
/bin
39 changes: 8 additions & 31 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NOTE: I had to run `git config --global http.https://gopkg.in.followRedirects tr
$ glide install
$ go build <1>
----
<1> Creates ./output
<1> Creates ./clojure-check

=== CLI usage

Expand Down Expand Up @@ -52,38 +52,15 @@ $ ./output localhost:33999 app.website < src/app/website.clj
identity)
----

=== ALE
== Editor integration

I'm currently using this configuration with ALE, I don't expect the CLI API to remain particularly stable, so I've not committed this yet.
Inspired by http://ddg.gg/[fzf] I have included a plugin folder in this repo which allows easy integration with Vim. I welcome similar PRs for other editors.

==== Vim - ALE

There is ALE integration available in this repo. It depends on Fireplace to find connection details.

[source,viml]
----
" Packages
Plug 'tpope/vim-fireplace'
Plug 'w0rp/ale'
" ALE config
let g:clojure_check_bin = '/absolute/path/to/clojure-check/output'
function! s:ClojureHost()
return fireplace#client().connection.transport.host
endfunction
function! s:ClojurePort()
return fireplace#client().connection.transport.port
endfunction
function! ClojureCheck(buffer)
try
return g:clojure_check_bin.' '.s:ClojureHost().':'.s:ClojurePort().' '.fireplace#ns(a:buffer)
catch /Fireplace/
return ''
endtry
endfunction
call ale#linter#Define('clojure', {
\ 'name': 'clojure_check',
\ 'executable': g:clojure_check_bin,
\ 'command_callback': 'ClojureCheck',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})
Plug 'SevereOverfl0w/clojure-check', {'do': './install'}
----
51 changes: 51 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

version=0.1
cd "$(dirname "${BASH_SOURCE[0]}")"
check_base="$(pwd)"
bin_name="clojure-check-v$version"
bin_dir="$check_base/bin"
target_bin="$bin_dir/$bin_name"

try_wget() {
command -v wget > /dev/null && wget -O $bin_name $1
}

try_curl() {
command -v curl > /dev/null && curl -fL $1 -o $bin_name
}

download() {
if ! [ -x $target_bin ]; then
rm -rf $bin_dir/*
local url="https://github.com/SevereOverfl0w/clojure-check/releases/download/v$version/$1"
try_curl $url || try_wget $url
chmod +x $target_bin
fi
}

# Create bin dir
mkdir -p $bin_dir && cd $bin_dir

# Try to download binary executable
archi=$(uname -sm)
binary_available=1
case "$archi" in
Darwin\ *64) download clojure-check_darwin_${binary_arch:-amd64} ;;
Darwin\ *86) download clojure-check_darwin_${binary_arch:-386} ;;
Linux\ *64) download clojure-check_linux_${binary_arch:-amd64} ;;
Linux\ *86) download clojure-check_linux_${binary_arch:-386} ;;
Linux\ armv5*) download clojure-check_linux_${binary_arch:-arm5} ;;
Linux\ armv6*) download clojure-check_linux_${binary_arch:-arm6} ;;
Linux\ armv7*) download clojure-check_linux_${binary_arch:-arm7} ;;
Linux\ armv8*) download clojure-check_linux_${binary_arch:-arm8} ;;
FreeBSD\ *64) download clojure-check_freebsd_${binary_arch:-amd64} ;;
FreeBSD\ *86) download clojure-check_freebsd_${binary_arch:-386} ;;
OpenBSD\ *64) download clojure-check_openbsd_${binary_arch:-amd64} ;;
OpenBSD\ *86) download clojure-check_openbsd_${binary_arch:-386} ;;
*) binary_available=0 ;;
esac

if [ $binary_available -eq 0 ]; then
echo "No prebuilt binary for $archi ..."
fi
39 changes: 39 additions & 0 deletions plugin/clojure-check.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
" This Source Code Form is subject to the terms of the Mozilla Public
" License, v. 2.0. If a copy of the MPL was not distributed with this
" file, You can obtain one at http://mozilla.org/MPL/2.0/.

if exists('g:loaded_clojure_check')
finish
endif
let g:loaded_clojure_check = 1

let s:check_version = '0.1'
let s:base_dir = expand('<sfile>:h:h')
" let s:clojure_check_bin = s:base_dir.'/bin/clojure-check-v'.s:check_version
let s:clojure_check_bin = s:base_dir.'clojure-check'

function! s:ClojureHost()
return fireplace#client().connection.transport.host
endfunction

function! s:ClojurePort()
return fireplace#client().connection.transport.port
endfunction

function! ClojureCheck(buffer)
try
return s:clojure_check_bin.' '.s:ClojureHost().':'.s:ClojurePort().' '.fireplace#ns(a:buffer)
catch /Fireplace/
return ''
endtry
endfunction

try
call ale#linter#Define('clojure', {
\ 'name': 'clojure_check',
\ 'executable': s:clojure_check_bin,
\ 'command_callback': 'ClojureCheck',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})
catch /E117/
endtry

0 comments on commit 7dea5eb

Please sign in to comment.