help-gnu-emacs
[Top][All Lists]
Advanced

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

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


From: Uday Reddy
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Fri, 01 Apr 2011 13:39:08 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9

On 4/1/2011 4:20 AM, rusi wrote:
There is this 'new' save-excursion issue/discussion/bug here:
http://thread.gmane.org/gmane.emacs.orgmode/40417

I wonder how much it is related to this discussion?

It is not exactly related.  It is a probably something similar to this:

(save-excursion
  (let ((x (buffer-substring (point-min) (point-max))))
    (erase-buffer)
    (insert x)))

What does it do? Well, save-excursion saves the point, but then erase-buffer destroys the point. So, the "point" moves to the beginning of buffer. And, save-excursion makes sure it stays there.

Without save-excursion, the point would move to the end of the buffer because of (insert x).

In the org-mode example in the thread, org-agenda-redo is probably doing a good job of putting the point at a good place. But the save-excursion at the top-level is negating all its good work.

It just goes to show the fallacy of thinking that save-excursion doesn't hurt.

Cheers,
Uday


reply via email to

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