On 5/16/07, Ernie Rael <[EMAIL PROTECTED]> wrote:
For jvi, not vim, I want to implement a way to "p" the clipboard as
though it were yank'd in block mode. I couldn't see anyway in the vim
doc to do this so I'm guessing that this is not supported. This could be
used to paste a rectangular selection from windows. Also, until I figure
out how to get at the vim specific info in the clipboard, it provides a
workaround for jvi.

If its possible that this might be a feature that vim would want some
day, I'd like to implement it in a compatible way. My first thought was
to use "#p to put the clipboard as block mode, the # has a block mode
flavor to it, but that's taken.

I understand exactly nothing of what you're trying to do, but here's a
function to does what "p" with a block does:

function! PasteRegion()
 let [_, lnum, col, _] = getpos('.')
 let saved_lnum = lnum
 for line in split(getreg(), '\n', 1)
   if lnum == line('$')
     if append(lnum, "") == 1
       throw 'Cannot append line to buffer while pasting region'
     endif
   endif
   let current_line = getline(lnum)
   let len = strlen(current_line)
   if len < col
     let new_line = current_line . repeat(' ', col - len) . line
   else
     let new_line = strpart(current_line, 0, col) . line .
strpart(current_line, col)
   endif
   if setline(lnum, new_line) == 1
     throw 'Cannot update line ' . lnum
   endif
   let lnum += 1
 endfor
 call cursor(saved_lnum, col + 1)
endfunction

This doesn't depend on any internal state of Vim.

Bram: Now that we have exceptions, wouldn't it make sense for append()
to throw an exception when it can't allocate memory?  Also, what's
with the C-style error codes for append() and setline()?  It's very
unintuitive, especially when there's really no other error code than
failure (1).  Too late to change, though.

 nikolai

Reply via email to