Subject: Re: bug#47860: 28.0.50; Mini buffer resize when lines are truncated regression

From: Aaron Jensen <[email-masked]>
Date: Mon, 19 Apr 2021 10:13:51 -0500

On Mon, Apr 19, 2021 at 9:48 AM Eli Zaretskii <[email-masked]> wrote:
> So you have a package (or two?) that work(s) only with an unreleased
> codebase of Emacs 28 before those two commits were installed?  How
> do those packages work in Emacs 27 and previous versions?

No, they work in Emacs 27 and 28 before 56c42bd28d was installed. As I
said, selectrum must be doing something else on top of what I narrowed
my repro down that triggers the appropriate resize.

>
> > This is what it looks like when using selectrum in Emacs 27:
> >
> > https://user-images.githubusercontent.com/8199224/114367956-3f4a8e00-9b7d-11eb-8307-5372fb48de63.png
> >
> > and Emacs 28:
> >
> > https://user-images.githubusercontent.com/8588/114411541-e1fd0f80-9b71-11eb-8ba3-5bf1437a7806.png
>
> That looks like an entirely different phenomenon than the one
> presented by the minimal reproducer.  Are you sure that the reproducer
> actually shows the same problem?

Both show a failure to resize properly in correlation with a truncated
line. I now believe it's unlikely to be the exact same issue given the
behavior on Emacs 27 w/ my repro. Until I've successfully narrowed
down something that reproduces on Emacs 27, I can't say for certain
that they're related.

> Bottom line, I'm now even more confused regarding the problem and the
> effect of the 2 commits you reverted.

Yeah, well, I'm confused as well. I'm trying to narrow down a repro in
multiple codebases I don't fully understand that points to a commit
that I do not understand at all. I'm feeling my way through the dark
here so I appreciate your patience.

> Reverting them should get you
> back to what we had in Emacs 27 and before, but you say it doesn't?

That's right, it does not, however resetting to 56c42bd28d^ does. Said
plainly: there's a difference in my repro between 56c42bd28d^ and
master + a revert of 56c42bd28d (and the section associated commit
that affected that same area of the code).

> And the effect on selectrum is very different than the effect on the
> reproducer you posted.

In my naivete they looked the same: a failure to resize the minibuffer
vertically to the appropriate size. There's more nuance to this though
and I'll work on a clarifying repro.

If you're willing to install selectrum, it would be helpful if you
could at least verify the behavior I'm seeing so that I do not think
I've gone mad. This reproduces the problem for me on master, but not
on emacs-27. Specifically, on emacs-27, I see both aaaa... and bbbb...
visible in the minibuffer, but on master, I only see aaa....

(require 'selectrum)

(let ((prompt "test: ")
      (candidates '("aaa"
                    "bbb"))
      (candidates
'("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")))
  (let* ((buf (current-buffer))
         default
         (res
          (let
              ((hook
                (make-symbol "selectrum--minibuffer-setup")))
            (fset hook
                  (lambda nil
                    (remove-hook 'minibuffer-setup-hook hook)
                    (setq-local selectrum--last-buffer buf)
                    ;; Track globally and in last buffer.
                    (setq-default selectrum--last-command this-command)
                    (setq-default selectrum--last-prefix-arg current-prefix-arg)
                    (when (buffer-live-p selectrum--last-buffer)
                      (with-current-buffer selectrum--last-buffer
                        (setq-local selectrum--last-command this-command)
                        (setq-local selectrum--last-prefix-arg
current-prefix-arg)))
                    (setq-local auto-hscroll-mode nil)
                    (setq-local selectrum--is-initializing t)
                    (setq-local selectrum--candidates-overlay
                                (make-overlay (point) (point) nil
                                              'front-advance 'rear-advance))
                    (setq-local selectrum--count-overlay
                                (make-overlay (point-min) (point-min)))
                    ;; If metadata specifies a custom sort function use it as
                    ;; `selectrum-preprocess-candidates-function' for
this session.
                    (when-let ((sortf (selectrum--get-meta
'display-sort-function)))
                      (setq-local
selectrum-preprocess-candidates-function sortf))
                    (if (not (functionp candidates))
                        (selectrum--preprocess candidates)
                      (setq-local selectrum--preprocessed-candidates nil)
                      (setq-local
selectrum--dynamic-candidates-function candidates))
                    (let ((default (or (car-safe default) default)))
                      (setq-local selectrum--default-candidate
                                  (if (and default (symbolp default))
                                      (symbol-name default)
                                    default)))
                    (setq-default selectrum--default-candidate
                                  selectrum--default-candidate)
                    ;; Make sure to trigger an "user input changed"
event, so that
                    ;; candidate refinement happens in
`post-command-hook' and an index
                    ;; is assigned.
                    (setq-local selectrum--previous-input-string nil)
                    (setq-local selectrum--line-height (line-pixel-height))
                    (add-hook 'post-command-hook #'selectrum--update
nil 'local)))
            (unwind-protect
                (progn
                  (add-hook 'minibuffer-setup-hook hook t)
                  (read-from-minibuffer prompt))
              (remove-hook 'minibuffer-setup-hook hook)))))))