Subject: Re: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers

From: Dmitry Gutov <[email-masked]>
Date: Wed, 13 Dec 2023 01:47:59 +0200

On 13/12/2023 01:43, Ihor Radchenko wrote:
> Stefan Monnier<[email-masked]>  writes:
> 
>>> E.g. company-dabbrev-code creates a dynamic binding for case-fold-search in
>>> one place and then calls a function (company-dabbrev--search) that iterates
>>> across all buffers with re-search-forward.
>> BTW, that `company-dabbrev-code` function may not do what you expect
>> in those buffers that have set `case-fold-search` buffer-locally.
> Yup.
> 
> Steps to reproduce:
> 
> 1. emacs -Q
> 2. M-: (setq-local case-fold-search nil)
> 3. C-x b <RET> (to*Messages*)
> 4. M-: (let ((case-fold-search t)) (with-current-buffer (get-buffer "*scratch*") (search-forward "CREATE")))
> 5. Observe search failing
> 
> If step (2) is omitted, search succeeds.

That's a good data point, but since I don't understand why anybody would 
make (or does make) case-fold-search buffer-local, I'm not going to 
hurry to fix those cases.

> Although, I am not sure if I like that let-binding is not reliable for
> buffer-locals. It is simply confusing from the point of view of let
> usage; even if documented. I'd rather go for `let' becoming more consistent.

That sounds attractive (ignoring all buffer-locals when let-bound?), but 
I'm guessing there are enough valid use cases for this behavior.