[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: window.el modify current emacs23 behavior of anything.

From: Thierry Volpiatto
Subject: Re: window.el modify current emacs23 behavior of anything.
Date: Wed, 21 Sep 2011 08:34:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> When `bury-buffer' restores the buffer previously shown in the selected
>> window, it also restores that buffer's `window-start' and `window-point'
>> position in the window.  If the window is selected, this implicitly
>> moves the buffer's point to the window's point.  This means that if the
>> restored buffer's point was changed before calling `bury-buffer', that
>> position is lost.
> Oh, I see the problem:
> Try M-: (progn (set-window-start (selected-window) (point)) (goto-char 
> (point-min)))
> and you'll see the that set-window-point wins even though it's run
> before the goto-char.
> That's why a sit-for works around the problem: it causes the
> set-window-start to be "executed", letting the subsequent goto-char do
> its job.
> So maybe the right fix is to remove the call to set-window-start.

Using the NOFORCE arg of `set-window-start' seem to fix problem in
anything, but don't know if it can create problems in other places:

#+BEGIN_SRC lisp

(defun set-window-buffer-start-and-point (window buffer &optional start point)
  "Set WINDOW's buffer to BUFFER.
Optional argument START non-nil means set WINDOW's start position
to START.  Optional argument POINT non-nil means set WINDOW's
point to POINT.  If WINDOW is selected this also sets BUFFER's
`point' to POINT.  If WINDOW is selected and the buffer it showed
before was current this also makes BUFFER the current buffer."
  (let ((selected (eq window (selected-window)))
        (current (eq (window-buffer window) (current-buffer))))
    (set-window-buffer window buffer)
    (when (and selected current)
      (set-buffer buffer))
    (when start
      (set-window-start window start t)) ;; Use noforce arg.
    (when point
      (if selected
          (with-current-buffer buffer
            (goto-char point))
        (set-window-point window point)))))


`set-window-buffer-start-and-point' is called by
`switch-to-prev-buffer' which is called by `bury-buffer'.

A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]