-
Notifications
You must be signed in to change notification settings - Fork 1
/
refheap.vim
151 lines (138 loc) · 4.08 KB
/
refheap.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
if !exists('g:refheap_token')
let g:refheap_token = ''
endif
if !exists('g:refheap_username')
let g:refheap_username = ''
endif
if !exists('g:refheap_api_url')
let g:refheap_api_url = 'https://refheap.com/api/'
endif
" I didn't come up with this, but it seems to work for getting the currently
" selected region.
function! GetVisualSelection()
try
let a_save = @a
silent! normal! gv"ay
return @a
finally
let @a = a_save
endtry
endfunction
" This is easily the most insane I've ever written on purpose.
function! refheap#Refheap(line1, line2, ...)
let lastarg = a:0 == 1 ? ",'" . a:1 . "'" : ''
execute 'ruby refheap(' . a:line1 . ',' . a:line2 . lastarg . ')'
endfunction
ruby << EOF
require 'rubygems'
require 'rubyheap'
require 'copier'
$languages = {"clj" => "Clojure",
"cljs" => "Clojure",
"fy" => "Fancy",
"groovy" => "Groovy",
"factor" => "Factor",
"io" => "Io",
"ioke" => "Ioke",
"lua" => "Lua",
"pl" => "Perl",
"perl" => "Perl",
"py" => "Python",
"rb" => "Ruby",
"mirah" => "Duby",
"tcl" => "Tcl",
"ada" => "Ada",
"c" => "C",
"cpp" => "C++",
"d" => "D",
"dylan" => "Dylan",
"flx" => "Felix",
"fortran" => "Fortran",
"nim" => "Nimrod",
"go" => "Go",
"java" => "Java",
"def" => "Modula-2",
"mod" => "Module-2",
"ooc" => "ooc",
"m" => "Objective-C",
"pro" => "Prolog",
"prolog" => "Prolog",
"scala" => "Scala",
"vala" => "Vala",
"boo" => "Boo",
"cs" => "C#",
"fs" => "F#",
"n" => "Nemerle",
"vb" => "VB.NET",
"lisp" => "Common Lisp",
"erl" => "Erlang",
"hs" => "Haskell",
"lhs" => "Literate Haskell",
"ml" => "OCaml",
"scm" => "Scheme",
"rkt" => "Scheme",
"ss" => "Scheme",
"v" => "Verilog",
"r" => "R",
"abap" => "ABAP",
"applescript" => "AppleScript",
"ahk" => "Autohotkey",
"awk" => "Awk",
"sh" => "Bash",
"bat" => "Batch",
"bf" => "Brainfuck",
"befunge" => "Befunge",
"ns2" => "NewSpeak",
"ps" => "PostScript",
"proto" => "Protobuf",
"r3" => "REBOL",
"st" => "Smalltalk",
"cmake" => "CMake",
"dpatch" => "Darcs Patch",
"diff" => "Diff",
"init" => "INI",
"properties" => "Java Properties",
"rst" => "rST",
"tex" => "LaTeX",
"vim" => "VimL",
"yaml" => "YAML",
"coffeescript" => "CoffeeScript",
"css" => "CSS",
"html" => "HTML",
"xml" => "XML",
"haml" => "HAML",
"js" => "Javascript",
"php" => "PHP",
"sass" => "SASS",
"txt" => "Plain Text",
"scaml" => "Scaml"}
$languages.default("Plain Text")
user = VIM::evaluate("g:refheap_username")
token = VIM::evaluate("g:refheap_token")
if user && token
$heap = Refheap::Paste.new(user, token)
else
$heap = Refheap::Paste.new()
end
def buffer_contents()
buffer = VIM::Buffer.current
1.upto(buffer.count).map { |i| buffer[i] }.join("\n")
end
def refheap(line1 = nil, line2 = nil, priv = nil)
if priv == "-p"
priv = "true"
else
priv = "false"
end
if line1 == line2
text = buffer_contents()
else
text = VIM::evaluate("GetVisualSelection()")
end
ref = $heap.create(text,
:language => $languages[VIM::evaluate('expand("%:e")')],
:private => priv)['url']
Copier(ref)
puts "Copied #{ref} to the clipboard."
end
EOF