Saturday, June 27, 2020

Re: An interesting little poser [PS]

On Mon, Jun 22, 2020 at 09:40:38PM EDT, Tim Chase wrote:
>
> function! Unfootnote()
> " make all the footnotes on one line
> $?^$?+,$g/^\[\@!.*\n\[\@!/,/\n\[\|\%$/j
> " gather the footnotes into b:a
> let b:a={}
> $?^$?,$g/\[\d\+\]/let b:a[getline('.')]=getline(line(".")+1)
> " find all the footnote references
> " and replace them with the corresponding text
> 1,$?^$?s/\[\d\+]/\='^['.b:a[submatch(0)].']'/g
> endfunc

When I run the above function (as copy-pasted from this thread) I get an
'E16: Invalid range' error on the g(global) command on some files.
Interestingly the function still does the job as if nothing had
happened. I went back to the explanation you gave in your earlier post
and after comparing with other files where I do not get the error
I can't find what's wrong with it. It looks like the range defining the
footnotes section is perfectly valid and that the Vim has
a problem with the pattern used in the g:/pattern/j command (I did
a $?^$?+,$print and it prints the footnotes section to the screen and
does not yell at me).

The interesting point is that the g: command's pattern has two parts
separated by a comma... which makes it suspiciously look like...
a range!

So is Vim confused by the regex that makes up the /pattern/…?

The problem occurs for instance with the following example file:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Debitis neque ipsum eos aut. Voluptatum ratione voluptatum facere voluptas.
Maxime qui ad autem ducimus quae [36]. Officia labore iusto voluptas ad quia
nostrum.


[36]
Ullam consequatur.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

But if I add a carriage return between Ullam & consequatur like so:

[36]
Ullam
consequatur.

... the problem goes away!

Not sure if it's some kind of corner case or this little experimented
has unearthed a bug in Vim's regex logic... and unfortunately I have no
idea how to investigate further.

Assuming you manage to reproduce the error is there any way you could
take a (quick) look?

Thanks,

CJ

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200628024608.GB4819%40turki.local.

No comments: