Monday, August 28, 2017

Re: Controlling the display of a syntax highlighting group

On Tue, Aug 29, 2017 at 3:51 AM, Jeffery Small <jefferysmall@gmail.com> wrote:
> To find non-ascii characters in a file, I have defined the following:
>
> syntax match nonascii "[^\x00-\x7F]"
> highlight nonascii ctermbg=13
>
> I can disable this with the command:
>
> syntax off
>
> I would like to create a command that toggles this highlight group on/off
> and
> hopefully do so without affecting the current state of the remainder of the
> syntax highlight groups. I have not found a way to test the state of this
> group, and once activated, I cannot seem to clear or edit the highlight
> definition non-destructively.
>
> Any pointers?

Try the following (untested):

function ASCII_on()
syn match NonAscii "[^\x00-\x7F]"
hi clear NonAscii
hi NonAscii term=reverse ctermbg=Magenta guibg=Magenta
endfunction
function ASCII_off()
syn clear NonAscii
hi clear NonAscii
endfunction
function ASCII_toggle()
if hlexists('NonAscii')
call ASCII_off()
else
call ASCII_on()
endif
endfunction
map <F12> :call ASCII_toggle()<CR>
imap <F12> <C-O>:call ASCII_toggle()<CR>
" but Select mode would use the Normal-mode mapping
" and replace the selection — we don't want that
sunmap <F12>

>
> [P.S.: I originally sent this to <vim@vim.org> which is the address listed
> on the official Vim mailing list page, but it never showed up. Is that
> still
> valid, or must vim_use@googlegroups.com now be used?]

I think that vim@vim.org is still acceptable, but I'm not sure: it
used to be a robot on a computer somewhere in an out-of-the-way place
in the Math faculty of some German university (Uni-Erlangen IIRC), and
no one knew anymore how to fix anything that went wrong with it. IMHO
the Google Group is more reliable.

Best regards,
Tony.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: