Skip to content

Commit f5e7783

Browse files
committed
sending to node server
0 parents  commit f5e7783

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

.gitignore

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

autoload/parinfer.vim

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
python <<NOMAS
4+
import sys
5+
import time
6+
import urllib2
7+
import vim
8+
import os
9+
import subprocess
10+
NOMAS
11+
12+
" function! evalbody(code)
13+
" python urllib2.urlopen(urllib2.Request("http://localhost:8088", "ohter"))
14+
" endfunction

plugin/parinfer.vim

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
if !exists("g:paredit_cmd")
3+
let g:paredit_cmd = "potion"
4+
endif
5+
6+
function! SendStr()
7+
let page = join(getline(1,'$'), "\n")
8+
let body = substitute(page, '\n', '\\n', 'g')
9+
let jsonbody = '{"text": "' . body . '", "cursor": 10, "line": 10}'
10+
let cmd = "curl -s -X POST -d '" . jsonbody . "' localhost:8088"
11+
let res = system(cmd)
12+
redraw!
13+
" this makes handling \n chars much more sane
14+
" as opppsed to append()
15+
let @a = res
16+
normal! G
17+
execute "put a"
18+
endfunction
19+
20+
nnoremap <buffer> <leader>bb :call SendStr()<cr>
21+

server.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var parinfer = require("parinfer");
2+
var http = require("http");
3+
4+
var handler = function(req, res) {
5+
6+
var body = "";
7+
req.on('data', function(data) {
8+
body += data;
9+
});
10+
11+
req.on('end', function() {
12+
13+
// console.log('raw body', body)
14+
15+
var obj = JSON.parse(body);
16+
17+
var cursor = {
18+
cursorX: obj.cursor,
19+
cursorLine: obj.line
20+
}
21+
22+
var executed = parinfer.indentMode(obj.text, cursor)
23+
res.end(executed.text)
24+
25+
// if (req.url == "/indent-mode") {
26+
// res.end(parinfer.indentMode(obj.text, {"cursorX": obj.cursor,
27+
// "cursorLine": obj.line}).text + "\n");
28+
// }
29+
// else if (req.url == "/paren-mode") {
30+
// res.end(parinfer.indentMode(obj.text, {"cursorX": obj.cursor,
31+
// "cursorLine": obj.line}).text + "\n");
32+
// }
33+
// else if (req.url == "/indent-mode-changed") {
34+
// res.end(parinfer.indentMode(body).text + "\n");
35+
// }
36+
});
37+
38+
};
39+
40+
var server = http.createServer(handler);
41+
server.listen(8088, function() {
42+
console.log("Server Listening");
43+
});
44+
45+
module.exports = function() {
46+
var server = http.createServer(handler);
47+
server.listen(8088, function() {
48+
console.log("Server Listening");
49+
});
50+
};

test.clj

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(def foo
2+
[a b
3+
c])
4+
5+
6+
7+
(def foo
8+
[a b]
9+
c)
10+
11+
12+
(def foo
13+
[a b]
14+
c)
15+
16+
17+
18+
(def foo
19+
[a b]
20+
c)
21+

0 commit comments

Comments
 (0)