--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---