2017-11-18 7:37 GMT+03:00 Tony Mechelynck <[email protected]>:
> Have you tried saving and restoring with the :let command, by means of an
> auxiliary variable (possibly a script-local variable)? (see :help
> script-variable, :help let-register and :help expr-register)
You can’t do that: `:let @x` is not going to work correctly if you
yanked NUL byte, or if you yanked a block selection. For
saving/restoring registers one must use getreg()/setreg(), but this is
only good as long as registers are internal to Vim and you have an
idea of what registers your command have touched: @", @0..@9 and @-
have a habit of being auto-populated under different circumstances.
If register is not internal to Vim (i.e. @* or @+, @" with some
&clipboard values) it is completely impossible to restore it correctly
because of
1. In X11 there is no register contents to restore at all, accessing a
register yields a call to the owner and Vim can only make himself the
owner and not restore the original app as such.
2. System clipboard does not necessary contain only text, but Vim is
completely unable to “restore” anything, but text.
So what you need to save/restore registers correctly is something like
function RExe(s)
let clipboard_save = &clipboard
let &clipboard = ''
let registers_save = []
for r in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '"']
call add(registers_save, [r, getreg(r, 1, 1), getregtype(r)])
endfor
try
execute a:s
finally
for reg in registers_save
call call('setreg', reg)
endfor
let &clipboard = clipboard_save
endtry
endfunction
>
> Best regards,
> Tony.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.