Skip to content

Commit cbd3d46

Browse files
committedSep 11, 2016
Initial commit
0 parents  commit cbd3d46

File tree

13 files changed

+261
-0
lines changed

13 files changed

+261
-0
lines changed
 

‎.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--color

‎CONTRIBUTING.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing
2+
3+
If you'd like to contribute to the project, you can use the usual github pull-request flow:
4+
5+
1. Fork the project
6+
2. Make your change/addition, preferably in a separate branch.
7+
3. Test the new behaviour and make sure all existing tests pass (optional, see below for more information).
8+
4. Issue a pull request with a description of your feature/bugfix.
9+
10+
## Testing
11+
12+
This project uses [rspec](http://rspec.info/) and [vimrunner](https://github.com/AndrewRadev/vimrunner) to test its behaviour. Testing vimscript this way is still fairly experimental, but does a great job of catching regressions. Tests are written in the ruby programming language, so if you're familiar with it, you should (I hope) find the tests fairly understandable and easy to get into.
13+
14+
If you're not familiar with ruby, please don't worry about it :). I'd definitely appreciate it if you could take a look at the tests and attempt to write something that describes your change. Even if you don't, Travis-bot should run the tests upon issuing a pull request, so we'll know right away if there's a regression. In that case, I'll work on the tests myself and see what I can do.
15+
16+
To run the test suite, provided you have ruby installed, first you need bundler:
17+
18+
```
19+
$ gem install bundler
20+
```
21+
22+
If you already have the `bundle` command (check it out with `which bundle`), you don't need this step. Afterwards, it should be as simple as:
23+
24+
```
25+
$ bundle install
26+
$ bundle exec rspec spec
27+
```
28+
29+
Depending on what kind of Vim you have installed, this may spawn a GUI Vim instance, or even several. You can read up on [vimrunner's README](https://github.com/AndrewRadev/vimrunner/blob/master/README.md) to understand how that works.

‎Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'rspec'
4+
gem 'vimrunner'
5+
gem 'pry'
6+
gem 'rake'

‎LICENSE

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Permission is hereby granted, free of charge, to any person obtaining a copy of
2+
this software and associated documentation files (the "Software"), to deal in
3+
the Software without restriction, including without limitation the rights to
4+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
5+
of the Software, and to permit persons to whom the Software is furnished to do
6+
so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all
9+
copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

‎README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Usage
2+
3+
TODO
4+
5+
## Contributing
6+
7+
Pull requests are welcome, but take a look at [CONTRIBUTING.md](https://github.com/AndrewRadev/gnugo.vim/blob/master/CONTRIBUTING.md) first for some guidelines.

‎Rakefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
task :default do
2+
sh 'rspec spec'
3+
end
4+
5+
desc "Prepare archive for deployment"
6+
task :archive do
7+
puts "TODO"
8+
# sh 'zip -r ~/newplugin.zip doc/newplugin.txt'
9+
end

‎_project.vim

Whitespace-only changes.

‎autoload/gnugo.vim

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
function! gnugo#InitRunner()
2+
return {
3+
\ 'output': [],
4+
\ 'job': v:null,
5+
\ 'channel': v:null,
6+
\
7+
\ 'Start': function('gnugo#Start'),
8+
\ 'Execute': function('gnugo#Execute'),
9+
\
10+
\ 'Expect': function('gnugo#Expect'),
11+
\ 'HandleOutput': function('gnugo#HandleOutput'),
12+
\ 'HandleError': function('gnugo#HandleError'),
13+
\ }
14+
endfunction
15+
16+
function! gnugo#Start() dict
17+
let self.job = job_start('gnugo --mode gtp', {
18+
\ 'out_cb': function(self.HandleOutput),
19+
\ 'err_cb': function(self.HandleError),
20+
\ })
21+
let self.channel = job_info(self.job).channel
22+
endfunction
23+
24+
function! gnugo#Execute(move) dict
25+
call ch_sendraw(self.channel, a:move."\n")
26+
let result = self.Expect('^=', 1)
27+
let move_location = substitute(result[-1], '^= \(.*\)', '\1', '')
28+
29+
call ch_sendraw(self.channel, "showboard\n")
30+
let board = self.Expect('A B C', 2)
31+
32+
let output = []
33+
call extend(output, [
34+
\ '= Last command: '.a:move,
35+
\ '= Location: '.move_location,
36+
\ ])
37+
call extend(output, board)
38+
39+
normal! ggdG
40+
call setline(1, output)
41+
normal! gg
42+
set nomodified
43+
endfunction
44+
45+
function! gnugo#HandleOutput(unused, line) dict
46+
call add(self.output, a:line)
47+
endfunction
48+
49+
function! gnugo#HandleError(unused, line) dict
50+
echoerr "Error: ".a:line
51+
endfunction
52+
53+
function! gnugo#Expect(pattern, count) dict
54+
let pattern = a:pattern
55+
" which encounter of the pattern to match:
56+
let encounter_count = copy(a:count)
57+
58+
let current_offset = 0
59+
let found_offset = -1
60+
let result = []
61+
62+
while encounter_count > 0
63+
" being updated asynchronously:
64+
let content_lines = self.output[current_offset:]
65+
66+
let index = 0
67+
for line in content_lines
68+
if line =~ pattern
69+
" we have a match, take everything up to the line, leave everything
70+
" afterwards
71+
let found_offset = current_offset + index
72+
let encounter_count -= 1
73+
break
74+
endif
75+
76+
let index += 1
77+
endfor
78+
79+
" for the next scan, just look at everything after the offset
80+
let current_offset = found_offset + 1
81+
sleep 10m
82+
endwhile
83+
84+
let result = self.output[0:found_offset]
85+
" clear what we've found
86+
let self.output = self.output[(found_offset + 1):]
87+
88+
return result
89+
endfunction

‎doc/gnugo.txt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
*gnugo.txt* TODO
2+
3+
==============================================================================
4+
CONTENTS *gnugo* *gnugo-contents*
5+
6+
Installation................................: |gnugo-installation|
7+
Usage.......................................: |gnugo-usage|
8+
Settings....................................: |gnugo-settings|
9+
Internals...................................: |gnugo-internals|
10+
Issues......................................: |gnugo-issues|
11+
12+
13+
==============================================================================
14+
INSTALLATION *gnugo-installation*
15+
16+
There are several ways to install the plugin. The recommended one is by using
17+
Tim Pope's pathogen (http://www.vim.org/scripts/script.php?script_id=2332). In
18+
that case, you can clone the plugin's git repository like so:
19+
>
20+
git clone git://github.com/AndrewRadev/gnugo.vim.git ~/.vim/bundle/gnugo
21+
<
22+
If your vim configuration is under git version control, you could also set up
23+
the repository as a submodule, which would allow you to update more easily.
24+
The command is (provided you're in ~/.vim):
25+
>
26+
git submodule add git://github.com/AndrewRadev/gnugo.vim.git bundle/gnugo
27+
<
28+
29+
Another way is to simply copy all the essential directories inside the ~/.vim
30+
directory: TODO list of directories
31+
32+
33+
==============================================================================
34+
USAGE *gnugo-usage*
35+
36+
TODO
37+
38+
39+
==============================================================================
40+
SETTINGS *gnugo-settings*
41+
42+
TODO
43+
44+
45+
==============================================================================
46+
INTERNALS *gnugo-internals*
47+
48+
TODO
49+
50+
==============================================================================
51+
ISSUES *gnugo-issues*
52+
53+
Any issues and suggestions are very welcome on the github bugtracker:
54+
https://github.com/AndrewRadev/gnugo.vim/issues
55+
56+
57+
vim:tw=78:sw=4:ft=help:norl:

‎ftplugin/gnugo.vim

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
" TODO (2016-09-09) Set this up when editing a go game file?
2+
" TODO (2016-09-09) Error handling ("invalid move")
3+
4+
command! -buffer -nargs=* Play call b:runner.Execute(<q-args>)

‎plugin/gnugo.vim

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
if exists('g:loaded_gnugo') || &cp
2+
finish
3+
endif
4+
5+
let g:loaded_gnugo = '0.0.1' " version number
6+
let s:keepcpo = &cpo
7+
set cpo&vim
8+
9+
command! Gnugo call s:Gnugo()
10+
function! s:Gnugo()
11+
new
12+
set filetype=gnugo
13+
14+
let b:runner = gnugo#InitRunner()
15+
call b:runner.Start()
16+
endfunction
17+
18+
let &cpo = s:keepcpo
19+
unlet s:keepcpo

‎spec/spec_helper.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'vimrunner'
2+
require 'vimrunner/rspec'
3+
require_relative './support/vim'
4+
5+
Vimrunner::RSpec.configure do |config|
6+
config.reuse_server = true
7+
8+
plugin_path = File.expand_path('.')
9+
10+
config.start_vim do
11+
vim = Vimrunner.start_gvim
12+
vim.add_plugin(plugin_path, 'plugin/gnugo.vim')
13+
vim
14+
end
15+
end
16+
17+
RSpec.configure do |config|
18+
config.include Support::Vim
19+
end

‎spec/support/vim.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Support
2+
module Vim
3+
end
4+
end

0 commit comments

Comments
 (0)
Please sign in to comment.