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

2022-09-06 Thread Nate Bargmann
At the risk of starting an editor skirmish.  ;-)

* On 2022 06 Sep 15:05 -0500, G. Branden Robinson wrote:
> 
> 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.

This is where it seems neovim (nvim) is taking a lead.  I've not
examined all of this yet as I installed their provided .deb for nvim
0.7.2 on a laptop a couple of weeks back and made sure my rather simple
vimrc didn't cause it to hork up a hairball.  It was fine.  I've yet to
do the same on this desktop but I have some time on my hands for a few
weeks so I might get there.

One of the things that nvim brings is LSP (Language Server Protocol)
which is touted to be quite powerful for things like syntax
highlighting.  I've only read about it have not taken the dive into it
yet but the claims are that it allows for much more fine-grained parsing
of source than vimscript's regex based system ever could.

I am still getting familiar with the nvim ecosystem as it appears large
and daunting but even with Vim 9 released earlier this year and its
backward breaking changes to its new vimscript, I think it has reached
its end in some ways even though I am certain there are several more
major versions on its horizon, so I am looking at neovim as the next
logical step.  Note that I'm barely an intermediate in all things Vim so
hardly an expert to turn to!

- Nate

-- 
"The optimist proclaims that we live in the best of all
possible worlds.  The pessimist fears this is true."
Web: https://www.n0nb.us
Projects: https://github.com/N0NB
GPG fingerprint: 82D6 4F6B 0E67 CD41 F689 BBA6 FB2C 5130 D55A 8819



signature.asc
Description: PGP signature


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

2022-09-06 Thread G. Branden Robinson
Hi Alex,

At 2022-09-06T22:21:39+0200, Alejandro Colomar wrote:
> On 9/6/22 22:01, G. Branden Robinson wrote:
> > And, for grins, my "git log -p" is also attached in case anyone would
> > find that edifying.
> 
> Do you have the git repo in a public remote that I can check out?

Sorry, no--it just lives in my home directory with no replication to the
Internet.

I know some people put their personal dotfile repos on the public Web
but I'm neither that much of an exhibitionist, nor that proud of some of
the kludges I come up with, nor willing to provide support services for
such things.

This one, I expect, will either sink into oblivion or be taken up by
someone with more Vim syntax-fu than I have.  If the latter, I am happy
to consult on fiddly *roff syntax issues to get the thing as robust as
possible.  (At some point, roff language inputs overcome the power
of Vim's matching facilities, even if the escape and control characters
are not changed.  But I don't know exactly what the limits of such
facilities are.)

Regards,
Branden


signature.asc
Description: PGP signature


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

2022-09-06 Thread Alejandro Colomar

Hi Branden,

On 9/6/22 22:01, G. Branden Robinson wrote:
> And, for grins, my "git log -p" is also attached in case anyone would
> find that edifying.

Do you have the git repo in a public remote that I can check out?

Cheers,

Alex

--



OpenPGP_signature
Description: OpenPGP digital signature


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

2022-09-06 Thread G. Branden Robinson
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
somewhere.[1]

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"
break
endif
let n = n + 1
endwhile
execute "setfiletype" t
endfunction

" 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 nroffTodoterm=italic cterm=italic gui=italic ctermfg=black 
ctermbg=yellow guifg=blue guibg=yellow
hi nroffNoteterm=reverse,italic cterm=reverse,italic gui=reverse,italic 
ctermfg=cyan
hi nroffRequest term=bold cterm=bold gui=bold ctermfg=yellow

Regards,
Branden

[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.
" Vim syntax file
" by G. Branden Robinson, August 2021.  GPLv3.
" Language: nroff/groff/troff

if exists("b:current_syntax")
finish
endif

let s:cpo_save = 
set cpo

" This syntax should be named 'troff'; it recognizes and does not
" distinguish typesetter-specific features, just like the stock Vim
" implementation.
let b:current_syntax = "nroff"

if exists("b:nroff_is_groff")
syntax keyword nroffKeyword groff
endif

if exists("b:nroff_is_groff")
syntax match nroffEscapeCharacter /\\/ nextgroup=nroffSimpleEscape,
\nroffSingleSpecialCharacter,
\nroffSpecialCharacterLeftParenthesis,
\nroffGroffLeftBracket,
\nroffSpaceEscape,
\nroffFixedWidthSpaceEscape,
\nroffComment,
\nroffOutputEscape,
\nroffGroffOutputEscape,
\nroffInterpolationEscape,
\nroffArgumentInterpolationEscape,
\nroffBracketBuildingEscape,
\nroffCharacterEscape,
\nroffDrawingEscape,
\nroffGroffNullableInterpolationEscape,
\nroffMotionOffsetEscape,
\nroffMarkEscape,