Saturday, June 13, 2015

Re: Formatting of lists and paragraphs containing numbers with fo+=n

On 13.06.15 15:34, Marcin Szewczyk wrote:
> With "n" it will become:
> asdasda sadas daskldj alksdj lkjasdk ljasdlk jlakds jlkdas jlkasdj lkajs
> 1000. aslda dkjasdkl jaklsdjklasjdlkasj kljads jasdlk jalkjdsa ljaskl
> asdjk kjasldjlkjklj kljaslkdjakljsd lkjadslkjaskldjklaj ljlkj
> 1. kljkljkljlkjklklj sad kjdjkjlkj asd klj klj lkj klj klj klj klj klj
> kljkl jl jkl asjdlkjaklsjdklajdkljasslkjdljasdkljadlkjakldjs lkj
> 2003. asdasd jlk dasd akdj ljaslkdj alkjsj lkjdskljala jlasjdkl
> jkjslkjd lkasjdlk jlkasjdklaj slkjsadlkj aklsjdlkaj dkjaslkdj
> klajsd jaslkdji
> 2. asdasd alsdk l;askd l;askdl;ka sdksald asdlka jlkdj lkj klj k skljd
> 2004. asjdlkjsalkdj lkasjdkla jkljdsaalk jkljsdlk askdljaskdj
> kasldj asdassdasssdkjaskldj jlkasjdlkjkljk jlkjkljklj lkj
> lkjkl jlkj klj lkj lk jlkj ldsj j ljask dlkjslkdj alksjd
> lkjasdkljadlk

Ugggh, yes, that's a dog's breakfast. This is what happens to that text
when I hit ^W ( mapped to gq} ) while formatoptions=rontcql :

> sdasda sadas daskldj alksdj lkjasdk ljasdlk jlakds jlkdas jlkasdj
> lkajs 1000. aslda dkjasdkl jaklsdjklasjdlkasj kljads jasdlk jalkjdsa
> ljaskl asdjk kjasldjlkjklj kljaslkdjakljsd lkjadslkjaskldjklaj ljlkj
> 1. kljkljkljlkjklklj sad kjdjkjlkj asd klj klj lkj klj klj klj klj
> klj kljkl jl jkl asjdlkjaklsjdklajdkljasslkjdljasdkljadlkjakldjs
> lkj 2003. asdasd jlk dasd akdj ljaslkdj alkjsj lkjdskljala
> jlasjdkl jkjslkjd lkasjdlk jlkasjdklaj slkjsadlkj aklsjdlkaj
> dkjaslkdj klajsd jaslkdji
> 2. asdasd alsdk l;askd l;askdl;ka sdksald asdlka jlkdj lkj klj k
> skljd 2004. asjdlkjsalkdj lkasjdkla jkljdsaalk jkljsdlk
> askdljaskdj kasldj asdassdasssdkjaskldj jlkasjdlkjkljk jlkjkljklj
> lkj lkjkl jlkj klj lkj lk jlkj ldsj j ljask dlkjslkdj alksjd
> lkjasdkljadlk

Even though quoted, Vim still restores the malformatted numbered list,
unfazed by your sneaky look-alikes. So, what do you need to do to also
hold your mouth right? My guess is that:

'formatlistpat' 'flp' string (default: "^\s*\d\+[\]:.)}\t ]\s*")

isn't cutting it. In comparison, mine is:

let &flp = '^\s*\(\d\|\a\)\.\s*'

(That may be mentioned in the 2011 thread, IIRC. It's past midnight
here, so I'm taking shortcuts, before I fall asleep.)

I also initialise with:

set formatoptions=croqltn

But none of that is critical. (Can be ignored in your case, I think.)

Then use Bill's function:

function! NList_toggle()
if &fo =~ "2"
set fo-=2 fo+=n
else
set fo-=n fo+=2
endif
endfun

noremap <F2> :call NList_toggle()<CR>

(F2 suits here, because I have F1 turning line numbering off. I.e keep
them together.)

I can't think that anything else is needed. In your case, the "2" may
not be needed. See :h fo-table . But I often use an indented first line
in a paragraph, so that's pretty darn handy.

If you do get rid of the "2", then the conditionality would be:

if &fo =~ "n"
set fo-=n
else
set fo+=n
endif

Erik

P.S. Thank's Bill, for solving this in 2011.

--
Never worry about theory as long as the machinery does what it's
supposed to do.
- Robert A. Heinlein

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