[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Vim syntax highlighting for *roff (was: Bug#1019257: ...)

From: G. Branden Robinson
Subject: Vim syntax highlighting for *roff (was: Bug#1019257: ...)
Date: Tue, 6 Sep 2022 15:01:52 -0500

I guess this is as good a time as any to share the Vim syntax
highlighting rules I use, which I rewrote from the ground up, and last
worked on about a year ago.

I undertook this because I found the stock Vim one, with Pedro Alejandro
López-Valencia's and Jérôme Plût's names on it, difficult to understand.
This might be more my problem than theirs.

I didn't _finish_ to my satisfaction--I ran into some kind of problems
involving the boundaries of the highlighting vs. the boundaries of the
lexical matching, which made some nested escape sequences not render to
my satisfaction.  (I am demanding in this regard.)  Even after much
reading of the Vim manual and experimentation I couldn't get this to
work the way I wanted.  I am prone to using perverse cases for testing.

On the other hand, for practical work--hacking on groff, which has
hairier exhibits of *roff source code than most code bases--I have gone
a year without noticing or being annoyed by bad lexical coloring, so I
guess other people might benefit from this as well.

Things I had planned for this and even implemented at one point, but
which broke in my quest for nested escape sequence rendering perfection:

1.  Coloring control characters in yellow.
2.  Coloring request names in bright yellow.
3.  Coloring macro names (anything in the position of a request name
    that doesn't match the list of all request names) in yellow.

I had these working just fine for a while in my initial hack-up of the
stock nroff.vim, but since my deeper rewrite they got lost and I've
found I don't miss them.  I might still have the giant declarations of
all CSTR #54 and groff extension request names lying around

Here are the relevant pieces of my .vimrc.

"let nroff_is_groff = 1
"let g:nroff_show_groffisms = 1
let nroff_space_errors = 1

" man pages--source or nroff output?
autocmd BufNewFile,BufRead *.man call s:FTman()

" If any of the first 10 lines of the file begin with a . or ', assume it's roff
" source.
function s:FTman()
    let t = "man"
    let n = 1
    while n < 10
        let line = getline(n)
        if line =~ "^['.]"
            let t = "groff"
        let n = n + 1
    execute "setfiletype" t

" troff/groff files
autocmd BufNewFile,BufRead *.groff setfiletype groff
autocmd BufNewFile,BufRead *.troff setfiletype nroff

autocmd BufReadPost *.man,*.me,*.mm,*.mom,*.ms,*.groff,*.roff,*.tmac
\    set comments=:.\\\",:'\\\",:.\\#,:'\\#

I'm attaching my nroff.vim.  This goes in $HOME/.vim/syntax if you want
to try it out.

And, for grins, my "git log -p" is also attached in case anyone would
find that edifying.

I also have the following.

$ cat /home/branden/.vim/after/syntax/nroff.vim
" Fix nearly unreadable highlight definition.
highlight Special ctermfg=red

hi nroffComment term=italic cterm=italic gui=italic ctermfg=cyan
hi nroffTodo    term=italic cterm=italic gui=italic ctermfg=black 
ctermbg=yellow guifg=blue guibg=yellow
hi nroffNote    term=reverse,italic cterm=reverse,italic gui=reverse,italic 
hi nroffRequest term=bold cterm=bold gui=bold ctermfg=yellow


[1] They can be reconstructed using CSTR #54 and the groff(7) man page.
    N.B., groff 1.23 adds four new requests, 'stringup', 'stringdown',
    'soquiet' and 'msoquiet', and there are two undocumented requests:
    'tag' and 'taga'.  I learned this last fact only in the past
    year.[2]  But I'm happy to share my lists if someone asks for them,
    and if I can find them--I hacked them into the Plût/Valencia syntax
    file, so I might have thrown them away when I undertook my rewrite.

[2] I would, of course, document them, but (1) I don't understand them
    yet and (2) I am not sure I will want to keep them once I do.  They
    have something to do with the nigh-undocumented "devtag" stuff, a
    recurring source of irritation since I began contributing to groff.

Attachment: nroff.vim
Description: nroff.vim

Attachment: nroff.vim.log
Description: nroff.vim.log

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]