@@ -132,28 +132,31 @@ def link(external=False):
132
132
else :
133
133
# Search for [http] link
134
134
b = vim .current .buffer
135
- i = vim .current .range .start
136
- while b [i ].find ("[http" ) < 0 and i >= 0 :
135
+ y , x = vim .current .window .cursor
136
+ y -= 1
137
+ while b [y ].find ("[http" ) < 0 and y >= 0 :
137
138
# The line we were on had no part of a link in it
138
- if b [i - 1 ].find ("]" ) > 0 \
139
- and b [i - 1 ].find ("]" ) > b [i - 1 ].find ("[http" ):
139
+ if b [y - 1 ].find ("]" ) > 0 \
140
+ and b [y - 1 ].find ("]" ) > b [y - 1 ].find ("[http" ):
140
141
return
141
- i -= 1
142
- start = i
143
- if b [i ].find ("[http" ) >= 0 :
144
- if b [i ].find ("]" , b [i ].find ("[http" )) >= 0 :
145
- a = b [i ].find ("[http" ) + 1
146
- e = b [i ].find ("]" , b [i ].find ("[http" ))
147
- url = b [i ][a :e ]
142
+ y -= 1
143
+ start = y
144
+ loc = max (b [y ].find ("[http" , x , b [y ].find ("]" , x )),
145
+ b [y ].rfind ("[http" , 0 , x ))
146
+ if loc >= 0 :
147
+ if b [y ].find ("]" , loc ) >= 0 :
148
+ a = loc + 1
149
+ e = b [y ].find ("]" , loc )
150
+ url = b [y ][a :e ]
148
151
else :
149
- url = b [i ][ b [ i ]. find ( "[http" ) + 1 :]
150
- i += 1
151
- while b [i ].find ("]" ) < 0 :
152
- if i != start :
153
- url += b [i ]
154
- i += 1
155
- if i != start :
156
- url += b [i ][:b [i ].find ("]" )]
152
+ url = b [y ][ loc :]
153
+ y += 1
154
+ while b [y ].find ("]" ) < 0 :
155
+ if y != start :
156
+ url += b [y ]
157
+ y += 1
158
+ if y != start :
159
+ url += b [y ][:b [y ].find ("]" )]
157
160
url = url .replace (" " , "" ).replace ("\n " , "" )
158
161
159
162
if url and url .find ("news.ycombinator.com/item?id=" ) > 0 :
0 commit comments