emacs-devel
[Top][All Lists]
Advanced

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

RE: `save-excursion' defeated by `set-buffer'


From: Drew Adams
Subject: RE: `save-excursion' defeated by `set-buffer'
Date: Sun, 10 Jan 2010 10:06:41 -0800

> A is inserted four places after point, but point does not move:
> (with-current-buffer "*scratch*" (forward-char 4) (insert "A"))
 
Actually, I think that `point' does move. What doesn't move is `window-point'.
Which is the correct behavior.

Try `M-x foo' (a) with *scratch* displayed and (b) without *scratch* displayed:

(defun foo ()
  (interactive)
  (with-current-buffer "*scratch*"
    (bar) (forward-char 4)
    (bar) (insert "A")
    (bar)))

(defun bar ()
  (message
   "%S, %S, %S"
   (current-buffer)
   (point)
   (and (get-buffer-window "*scratch*" 0)
        (window-point
         (get-buffer-window "*scratch*" 0)))))

Starting with point at 1, you see this:

(a) *scratch* displayed
#<buffer *scratch*>, 1, 1
#<buffer *scratch*>, 5, 1
#<buffer *scratch*>, 6, 1

(b) *scratch* not displayed
#<buffer *scratch*>, 1, nil
#<buffer *scratch*>, 5, nil
#<buffer *scratch*>, 6, nil





reply via email to

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