Thursday, June 28, 2012

Re: VimL functions to determine spelling categories?

On Thu, 28 Jun 2012, Ben Fritz wrote:

> On Thursday, June 28, 2012 4:44:19 AM UTC-5, Benjamin R. Haskell wrote:
>> Are there VimL functions for determining that Vim has marked a word
>> as misspelled? E.g. so the highlighting could be exported in
>> something similar to TOhtml.
>
> I recently installed this, which populates the quickfix list with
> spelling errors, but I haven't looked at how it works yet:
>
> http://www.vim.org/scripts/script.php?script_id=3844

Thanks. I didn't find the spellbadword() function before, because it's
the 53rd item when tab-completing :help spell<Tab>.

Unfortunately, spellbadword() can change the cursor position. But,
c'est la vie. I like Ingo's approach:

" pseudocode

" {{{ prevent looping, save the setting and view
let saved_wrapscan = &wrapscan
set nowrapscan

let saved_view = winsaveview()
" }}}

sil! norm! gg0]s " go to first error

while 1
let start_pos = getpos('.')

sil! norm! ]s " go to next error

let error_pos = getpos('.')
let [word, type] = spellbadword()

if error_pos == start_pos " then, there was no error
break
end
endwhile

" {{{ restore setting and view
call winrestview(saved_view)
let &wrapscan = saved_wrapscan
" }}}

In a few places he uses ]s[s (instead of just ]s), but I don't quite
understand what it's working around (code comment mentions something
about multiple errors on one line).



> I have in the TOhtml TODO list, adding guisp highlighting. I'm not
> exactly sure how I want to accomplish it though. It might be converted
> to a dotted underline or something of the appropriate color.

CSS3 is adding properties that will make it properly-possible¹. This
is one way it will eventually work:

.undercurl {
text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: red;
/* possibly also: */ text-underline-position: alphabetic;
}

Shorter:

.undercurl {
text-decoration: red wavy underline;
}

Firefox has vendor-prefixed CSS properties² for some of this already.
The following worked for me (in FF) to simulate this Vim:

.SpellBad {
/* hi SpellBad gui=undercurl guisp=#ff0000 */
-moz-text-decoration-line: underline;
-moz-text-decoration-style: wavy;
-moz-text-decoration-color: #ff0000;
/* text-decoration: #ff0000 wavy underline; // not yet working, even with -moz- */
}

--
Best,
Ben H

¹: text-decoration-style - http://www.w3.org/TR/css3-text/#text-decoration-style

²: http://peter.sh/experiments/vendor-prefixed-css-property-overview/

--
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: