GNU bug report logs - #20100
24.4.91; Can't scroll a window while in minibuffer

Previous Next

Package: emacs;

Reported by: Oleh Krehel <ohwoeowho <at> gmail.com>

Date: Fri, 13 Mar 2015 12:57:02 UTC

Severity: normal

Found in version 24.4.91

Done: martin rudalics <rudalics <at> gmx.at>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20100 in the body.
You can then email your comments to 20100 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#20100; Package emacs. (Fri, 13 Mar 2015 12:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Oleh Krehel <ohwoeowho <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 13 Mar 2015 12:57:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Oleh Krehel <ohwoeowho <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4.91; Can't scroll a window while in minibuffer
Date: Fri, 13 Mar 2015 13:51:36 +0100
I'm trying to write a completion package using `read-from-minibuffer'
combined with `post-command-hook'.

Everything is working OK, except when I want to sync the current
completion candidate (one of buffer's lines) with the corresponding line
in the buffer.

This code, specifically `recenter', doesn't work:

(with-current-buffer buf
  (goto-char (point-min))
  (forward-line (1- num))
  (recenter))

However, this code will scroll the window (`buf' and `wnd' correspond to
each other):

(with-current-buffer buf
  (goto-char (point-min))
  (forward-line (1- num))
  (setf (window-point wnd)
        (point)))

Still, it's not a perfect solution, since even after setting
`window-point', (window-start wnd) and (window-end wnd t) will not
return the correct thing.

I'm pretty sure it's a bug and the code above should work as is, but I'd
also appreciate pointers for achieving the scrolling and window bounds
re-calculation for the current Emacs.

regards,
Oleh




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20100; Package emacs. (Fri, 13 Mar 2015 16:59:02 GMT) Full text and rfc822 format available.

Message #8 received at 20100 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Oleh Krehel <ohwoeowho <at> gmail.com>, 20100 <at> debbugs.gnu.org
Subject: Re: bug#20100: 24.4.91; Can't scroll a window while in minibuffer
Date: Fri, 13 Mar 2015 17:58:04 +0100
> I'm trying to write a completion package using `read-from-minibuffer'
> combined with `post-command-hook'.
>
> Everything is working OK, except when I want to sync the current
> completion candidate (one of buffer's lines) with the corresponding line
> in the buffer.
>
> This code, specifically `recenter', doesn't work:
>
> (with-current-buffer buf
>    (goto-char (point-min))
>    (forward-line (1- num))
>    (recenter))

I suppose that at the time you invoke `recenter', the selected window
doesn't show `buf'.  When with emacs -Q I do

(let ((buffer (get-buffer-create "*buffer*"))
      (line 0))
  (set-window-buffer nil buffer)
  (with-current-buffer buffer
    (while (< line 100)
      (insert (format "%02d\n" line))
      (setq line (1+ line))))

  (with-current-buffer buffer
    (goto-char (point-min))
    (forward-line 25)
    (recenter)))

then I see the line starting with "25" centered in the selected window.
Can you try modifying my example such that it "doesn't work for you"?

> However, this code will scroll the window (`buf' and `wnd' correspond to
> each other):
>
> (with-current-buffer buf
>    (goto-char (point-min))
>    (forward-line (1- num))
>    (setf (window-point wnd)
>          (point)))

The fact that you apparently have to

(setf (window-point wnd) (point))

seems to suport my claim above, namely that `wnd' is not selected at
that time.

> Still, it's not a perfect solution, since even after setting
> `window-point', (window-start wnd) and (window-end wnd t) will not
> return the correct thing.

What is the wrong thing and what would the correct thing be?  The only
function that should work "correctly" here is `set-window-start'.

> I'm pretty sure it's a bug and the code above should work as is, but I'd
> also appreciate pointers for achieving the scrolling and window bounds
> re-calculation for the current Emacs.

Beyond what you can read in the documentations, explaining `recenter' is
hardly possible without explaining redisplay as well.  You have to look
at its implementation.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20100; Package emacs. (Fri, 13 Mar 2015 17:11:01 GMT) Full text and rfc822 format available.

Message #11 received at 20100 <at> debbugs.gnu.org (full text, mbox):

From: Oleh Krehel <ohwoeowho <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 20100 <at> debbugs.gnu.org
Subject: Re: bug#20100: 24.4.91; Can't scroll a window while in minibuffer
Date: Fri, 13 Mar 2015 18:10:09 +0100
Hi Martin,

On Fri, Mar 13, 2015 at 5:58 PM, martin rudalics <rudalics <at> gmx.at> wrote:
>> I'm trying to write a completion package using `read-from-minibuffer'
>> combined with `post-command-hook'.
>>
>> Everything is working OK, except when I want to sync the current
>> completion candidate (one of buffer's lines) with the corresponding line
>> in the buffer.
>>
>> This code, specifically `recenter', doesn't work:
>>
>> (with-current-buffer buf
>>    (goto-char (point-min))
>>    (forward-line (1- num))
>>    (recenter))
>
> I suppose that at the time you invoke `recenter', the selected window
> doesn't show `buf'.  When with emacs -Q I do
>
> (let ((buffer (get-buffer-create "*buffer*"))
>       (line 0))
>   (set-window-buffer nil buffer)
>   (with-current-buffer buffer
>     (while (< line 100)
>       (insert (format "%02d\n" line))
>       (setq line (1+ line))))
>
>   (with-current-buffer buffer
>     (goto-char (point-min))
>     (forward-line 25)
>     (recenter)))
>
> then I see the line starting with "25" centered in the selected window.
> Can you try modifying my example such that it "doesn't work for you"?

You need to be in the minibuffer in order for the effect to occur,
which you're not.

See my question on Emacs Stack Exchange for a simple way to reproduce the issue:
http://emacs.stackexchange.com/questions/9967/how-to-scroll-another-buffer-while-in-minibuffer

However, what I'm actually trying to do is here:
https://raw.githubusercontent.com/abo-abo/swiper/master/ivy.el

> The fact that you apparently have to
>
> (setf (window-point wnd) (point))
>
> seems to suport my claim above, namely that `wnd' is not selected at
> that time.

It is selected, only the minibufer is interfering.

>> Still, it's not a perfect solution, since even after setting
>> `window-point', (window-start wnd) and (window-end wnd t) will not
>> return the correct thing.
>
> What is the wrong thing and what would the correct thing be?  The only
> function that should work "correctly" here is `set-window-start'.

`set-window-start' doesn't work. The issue is that the scroll
happended and visibly the window start has changed, but `window-start`
still returns the old value.

> Beyond what you can read in the documentations, explaining `recenter' is
> hardly possible without explaining redisplay as well.  You have to look
> at its implementation.

Thanks, I might get to that eventually, I just wanted to hear the
expert opinion, maybe this is a
known problem. My current work-around for re-computing the changed
`window-start' and `window-end'
is to call `forward-line' with the window height parameter.

Oleh




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20100; Package emacs. (Fri, 13 Mar 2015 18:17:02 GMT) Full text and rfc822 format available.

Message #14 received at 20100 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Oleh Krehel <ohwoeowho <at> gmail.com>
Cc: 20100 <at> debbugs.gnu.org
Subject: Re: bug#20100: 24.4.91; Can't scroll a window while in minibuffer
Date: Fri, 13 Mar 2015 19:16:54 +0100
> You need to be in the minibuffer in order for the effect to occur,
> which you're not.

I know but you didn't give a recipe.

>> The fact that you apparently have to
>>
>> (setf (window-point wnd) (point))
>>
>> seems to suport my claim above, namely that `wnd' is not selected at
>> that time.
>
> It is selected, only the minibufer is interfering.

It apparently is _not_ selected (at least not in your snippet).  With
emacs -Q evaluate the following code:

(let ((buffer (get-buffer-create "*buffer*"))
      (window (selected-window))
      (line 0))
  (set-window-buffer nil buffer)
  (with-current-buffer buffer
    (while (< line 100)
      (insert (format "%02d\n" line))
      (setq line (1+ line))))

  (with-selected-window (minibuffer-window)
    (with-selected-window window
      (goto-char (point-min))
      (forward-line 25)
      (recenter))
    (insert "This is your minibuffer window!")
    (sit-for 5)))

Can you see the difference?

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20100; Package emacs. (Fri, 13 Mar 2015 18:42:02 GMT) Full text and rfc822 format available.

Message #17 received at 20100 <at> debbugs.gnu.org (full text, mbox):

From: Oleh Krehel <ohwoeowho <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 20100 <at> debbugs.gnu.org
Subject: Re: bug#20100: 24.4.91; Can't scroll a window while in minibuffer
Date: Fri, 13 Mar 2015 19:41:38 +0100
> It apparently is _not_ selected (at least not in your snippet).  With
> emacs -Q evaluate the following code:
>
> (let ((buffer (get-buffer-create "*buffer*"))
>       (window (selected-window))
>       (line 0))
>   (set-window-buffer nil buffer)
>   (with-current-buffer buffer
>     (while (< line 100)
>       (insert (format "%02d\n" line))
>       (setq line (1+ line))))
>
>   (with-selected-window (minibuffer-window)
>     (with-selected-window window
>       (goto-char (point-min))
>       (forward-line 25)
>       (recenter))
>     (insert "This is your minibuffer window!")
>     (sit-for 5)))
>
> Can you see the difference?

Thanks, using `with-selected-window' instead of `with-current-buffer'
solved it. I thought that they should be equivalent. Apparently they are not.

So the problem is solved, thanks again.

Oleh




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20100; Package emacs. (Fri, 13 Mar 2015 20:59:02 GMT) Full text and rfc822 format available.

Message #20 received at 20100 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Oleh Krehel <ohwoeowho <at> gmail.com>
Cc: rudalics <at> gmx.at, 20100 <at> debbugs.gnu.org
Subject: Re: bug#20100: 24.4.91; Can't scroll a window while in minibuffer
Date: Fri, 13 Mar 2015 22:58:18 +0200
> Date: Fri, 13 Mar 2015 19:41:38 +0100
> From: Oleh Krehel <ohwoeowho <at> gmail.com>
> Cc: 20100 <at> debbugs.gnu.org
> 
> Thanks, using `with-selected-window' instead of `with-current-buffer'
> solved it. I thought that they should be equivalent. Apparently they are not.

with-current-buffer makes the buffer current for the purposes of
editing, but not for the purposes of redisplay.  By contrast,
'recenter' needs a window to do its job, so it must have the buffer
selected in the current window.




Reply sent to martin rudalics <rudalics <at> gmx.at>:
You have taken responsibility. (Sat, 14 Mar 2015 08:18:02 GMT) Full text and rfc822 format available.

Notification sent to Oleh Krehel <ohwoeowho <at> gmail.com>:
bug acknowledged by developer. (Sat, 14 Mar 2015 08:18:02 GMT) Full text and rfc822 format available.

Message #25 received at 20100-done <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Oleh Krehel <ohwoeowho <at> gmail.com>
Cc: 20100-done <at> debbugs.gnu.org
Subject: Re: bug#20100: 24.4.91; Can't scroll a window while in minibuffer
Date: Sat, 14 Mar 2015 09:17:04 +0100
> Thanks, using `with-selected-window' instead of `with-current-buffer'
> solved it. I thought that they should be equivalent. Apparently they are not.

It's a trap.  Commands that implicitly work on the selected window
should not be used programmatically.  Such commands are `recenter',
`enlarge-window', `shrink-window', `split-window-below' and
`split-window-right'.  When used in applications the only way to make
them behave is to wrap them in `with-selected-window' :-(

There are also more specialized commands like `recenter-top-bottom' or
`move-to-window-line-top-bottom' whose doc-strings don't explain what
they do.  Never use them in programs!

martin, closing this bug




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 11 Apr 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 74 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.