Subject: bug#56682: feature/improved-locked-narrowing 9dee6df39c: Reworked locked narrowing.

From: Gregory Heytings <[email-masked]>
Date: Fri, 30 Dec 2022 16:38:34 +0000

[Moved to the bug tracker.]

Thanks for your comments, Stefan!

>
> - I don't see any mention of those new features in etc/NEWS.
>

Yes, that's something I still need to do.

>
> - I can't think of a case where a piece of code could/should make use of 
> `narrowing-unlock`.
>

I don't understand what you mean by that.  'narrowing-lock' locks a 
narrowing, and is used e.g. in the 'with-narrowing' macro. 
'narrowing-unlock' can be used to unlock a narrowing.

>
> - In `nlinum--line-number-at-pos`, I want to circumvent the narrowing 
> lock due to long lines (since its performance is only affected by buffer 
> size but not by line length), but I can't see how to do that. The only 
> primitive I see which would let me get out of the locked narrowing is 
> `narrowing-unlock` but:
>
> - I don't know which tag(s) to use.
>

That depends on the place where 'nlinum--line-number-at-pos' is called, or 
IOW where/by which function the narrowing was locked, or IOW again which 
tag was used to unlock the narrowing.

>
> - I don't want to remove the lock, I only want to circumvent it 
> temporarily, and I can't see how to re-install a lock after removing it 
> (`narrowing-lock` doesn't fit the bill because I don't know the bounds 
> of the lock and because that would not preserve the stacking order of 
> locks).
>

That's part of the improvements you suggested, and I implemented.  Simply 
do a:

(save-restriction
   (narrowing-unlock 'the-appropriate-tag)
   (widen)
   ... your code ...)

Upon return from the save-restriction, the narrowing locks are restored.