Sunday, November 6, 2011

Re: [Suggestion] New functions iskeywordchar(), isfnamechar(), isprintchar(), and isidentchar()

Addendum.

Heureka, I've found it!

The solution is based on a combination of virtcol(".") and byteidx(...):

function! CWord(string, class_start, class_end)
   let l:len = len(substitute(a:string, ".", "x", "g"))
   let l:pos = virtcol(".") - 1

   let l:start = l:pos
   while l:start >= 0 && matchstr(a:string, ".", byteidx(a:string, l:start)) =~ a:class_start
      let l:start -= 1
   endwhile

   let l:end = l:pos
   while l:end < l:len && matchstr(a:string, ".", byteidx(a:string, l:end)) =~ a:class_end
      let l:end += 1
   endwhile

   let l:start = byteidx(a:string, l:start + 1)
   let l:end   = byteidx(a:string, l:end   - 1)

   return strpart(a:string, l:start, l:end - l:start + 1)
endfunction

Thanks for the comments!

--
You received this message from the "vim_use" 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

No comments: