[Top][All Lists]

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

RE: `save-exursion' makes a comeback!

From: Drew Adams
Subject: RE: `save-exursion' makes a comeback!
Date: Tue, 15 Mar 2011 09:02:02 -0700

> > Forget about `save-excursion' "saving" or "restoring" or
> > "hiding" or "protecting" anything.  Forget about it "defeating"
> > or being "defeated".  Forget all of that right now.
> >
> > The real name of `save-excursion' is `come-back-here'.
> > Just remember that and Bob's your uncle.
> M-: (with-temp-buffer (let ((b (current-buffer))) (save-excursion
>     (set-buffer "*scratch*") (kill-buffer b))) (current-buffer)) RET

Yes, David.  I explicitly mentioned that case before (though that was no doubt
lost in the bit torrent).  This makes it even clearer, I think:

(defun foo ()
    (message "BEFORE KILL, buf: %S, pt: %S, mark: %S"
               (current-buffer) (point) (mark))
    (sit-for 2)
    (kill-buffer (current-buffer))
    (message "BEFORE END, buf: %S, pt: %S, mark: %S"
               (current-buffer) (point) (mark))
    (sit-for 2))
  (message "AFTER, buf: %S, pt: %S, mark: %S"
             (current-buffer) (point) (mark))
  (sit-for 2))

M-x foo RET

This is no different from your father saying "Come back here!" as you run out
the door, and your then burning down the house so there is no place to come back

Really, this kind of thing just adds confusion to the discussion for most users.
There is nothing special here to do with `save-excursion'.  `save-excursion'
just does an `unwind-protect' to return where you came from.  If in the meantime
you have nuked the place you came from then there is nothing that
`save-excursion', `unwind-protect', or the Emacs god herself can do to bring
your home back.

reply via email to

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