Subject: Re: bug#17281: 24.4.50; emacs hangs in next-line

From: Eli Zaretskii <[email-masked]>
Date: Thu, 17 Apr 2014 13:16:52 +0300

Btw, just FYI, this code:

  (defun test ()
    (interactive)
    (goto-char (point-min))
    (save-match-data (re-search-forward "^$" nil t))
    (next-line 1))

doesn't do what you think.  next-line does TRT for the selected
window, but in this case the mode function 'test' runs when the buffer
that visits the file is not yet displayed in any window, certainly not
in the selected one.  You want to call forward-line instead.

Stefan (Monnier), this raises a general issue with next-line: is it
supposed to work accurately in a buffer that is not the currently
selected window's buffer?  If so, the call to line-pixel-height should
be made after switching to the current buffer in the selected window.
Right now, line-pixel-height returns its result computed for the
selected window, which is OK when next-line is invoked interactively,
but not if it is part of some non-interactive code, such as the mode
function in this case.