Monday, May 28, 2012

Re: Make Specific Space Characters Visible

On Sun, 27 May 2012, Ben Fritz wrote:

> On Saturday, May 26, 2012 6:14:33 AM UTC-5, Bastien Dejean wrote:
>> Hi,
>>
>> I'd like to visualize specific space characters through the *conceal*
>> mechanism.
>>
>> Here's my first (failed) attempt:
>>
>> syntax match ThreePerEmSpace " " conceal cchar=⅓
>> syntax match FourPerEmSpace " " conceal cchar=¼

Your example worked for me if I first cleared syntax:

:syn clear
:source test-spaces.vim

When editing a 'vim' file for example, in the systemwide syntax/vim.vim
there's something with higher precedence than these matches. If you can
trigger these matches before the systemwide syntax file, it should work.

E.g. for a specific {filetype}, put your matches in
~/.vim/syntax/{filetype}.vim


If you want them to work for all filetypes, you'll have to do something
more drastic. My first thought is the following -- try putting them in
an autocmd that runs before filetype-detection:

" These lines must come before any line with the :filetype command in
" your ~/.vimrc (possibly also before :syntax enable?):
aug ShowSpaces
au!
for [space, char] in {' ':'⅓', ' ':'¼'}
let cmd = 'au BufRead,BufNew * syn match HiddenSpaces "'.space.'" conceal cchar='.char
exe cmd
exe cmd.' contained'
endf
aug END

That creates two syntax matches for each, one of which is contained (so
that it can occur in places that the syntax file may otherwise prevent).


> You've included the special characters literally, which will only work
> if you tell Vim what encoding to use to read the file. Otherwise it
> defaults to something probably incorrect (on my system it defaults to
> latin1).
>
> Try putting "scriptencoding utf-8" at the top of your script, or
> specifying the character by codepoint:

:scriptencoding will convert to the value of 'encoding'. If that's
already utf-8, :scriptencoding shouldn't be necessary.


> syntax match ThreePerEmSpace '[\u2004]' conceal cchar=⅓
> syntax match FourPerEmSpace '[\u2005]' conceal cchar=¼
>
> Note from just above :help /\%[] that this will only work if 'l' is not in 'cpoptions'.

I'm not sure the literal characters are the problem here, but it's good
advice nonetheless.

--
Best,
Ben H

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