From 7dea5ebae0a9ea3da3e1b8c2152339eb4c76706d Mon Sep 17 00:00:00 2001 From: Dominic Monroe Date: Fri, 21 Apr 2017 09:56:46 +0100 Subject: [PATCH] Add support for native Vim/ALE --- .gitignore | 1 + README.adoc | 39 +++++++----------------------- install | 51 ++++++++++++++++++++++++++++++++++++++++ plugin/clojure-check.vim | 39 ++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 31 deletions(-) create mode 100755 install create mode 100644 plugin/clojure-check.vim diff --git a/.gitignore b/.gitignore index 271ab02..9be1ffb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor /output /clojure-check +/bin diff --git a/README.adoc b/README.adoc index 5aac6c9..6e06532 100644 --- a/README.adoc +++ b/README.adoc @@ -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 @@ -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'} ---- diff --git a/install b/install new file mode 100755 index 0000000..d963f1e --- /dev/null +++ b/install @@ -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 diff --git a/plugin/clojure-check.vim b/plugin/clojure-check.vim new file mode 100644 index 0000000..f1ae552 --- /dev/null +++ b/plugin/clojure-check.vim @@ -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(':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