Skip to content

Commit c1a770e

Browse files
committed
Restore winsaveview
1 parent 251f834 commit c1a770e

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

plugin/iron.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
map <silent> <Plug>(iron-send-motion) :<c-u>set opfunc=IronSendMotion<CR>g@
2-
vmap <silent> <Plug>(iron-send-motion) :<c-u>call IronSendMotion('visual')<CR>
1+
map <silent> <Plug>(iron-send-motion)
2+
\ :<c-u>let b:iron_cursor_pos = winsaveview() \| set opfunc=IronSendMotion<CR>g@
3+
vmap <silent> <Plug>(iron-send-motion)
4+
\ :<c-u>let b:iron_cursor_pos = winsaveview() \| call IronSendMotion('visual')<CR>
35
46
"Call previous command again
57
map <silent> <Plug>(iron-repeat-cmd) :call IronSend("\u001b\u005b\u0041")<CR>

rplugin/python3/iron/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,22 @@ def mapping_send(self, args):
109109
@neovim.function("IronSendMotion", range=True)
110110
def send_motion_to_repl(self, args, rng=None):
111111
logger.debug("Supplied data: {}".format(", ".join(args)))
112+
cur_buf = self.nvim.current.buffer
113+
114+
if not 'iron_cursor_pos' in cur_buf.vars:
115+
# Probably repeating, so setting the position manually
116+
cur_buf.vars['iron_cursor_pos'] = self.call('winsaveview')
112117

113118
if args[0] == 'visual':
114-
init = self.nvim.current.buffer.mark('<')
115-
end = self.nvim.current.buffer.mark('>')
119+
init = cur_buf.mark('<')
120+
end = cur_buf.mark('>')
116121
else:
117-
init = self.nvim.current.buffer.mark('[')
118-
end = self.nvim.current.buffer.mark(']')
122+
init = cur_buf.mark('[')
123+
end = cur_buf.mark(']')
119124

120125
end[1] += 1
121126

122-
text = self.nvim.current.buffer[init[0]-1:end[0]]
127+
text = cur_buf[init[0]-1:end[0]]
123128

124129
logger.debug("Gathered: {} - {}: {}".format(
125130
init, end, "\n".join(text)))
@@ -133,6 +138,9 @@ def send_motion_to_repl(self, args, rng=None):
133138

134139
logger.debug("Stripped: {}".format("\n".join(text)))
135140

141+
self.call('winrestview', cur_buf.vars['iron_cursor_pos'])
142+
del cur_buf.vars['iron_cursor_pos']
143+
136144
return self.send_to_repl(["\n".join(text)])
137145

138146
@neovim.function("IronSend")

0 commit comments

Comments
 (0)