this post was submitted on 22 Nov 2023
1 points (100.0% liked)

Emacs

311 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

When debugging some code, I learned that if you call pop-to-buffer and pop-to-buffer-same-window inside save-excursion or save-current-buffer, the original buffer will not be restored at the end of the save-. You can get around this by using save-window-excursion; however, I still feel like save-excursion ought to work. Does anyone know why it doesn't?

(You can check this by eval-ing the following in any buffer other than *Messages*: (save-excursion (pop-to-buffer-same-window "*Messages*")).

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 11 months ago

This is 100% expected behaviour. save-excursion has nothing to do with windows.

Perhaps you are confused about the phrase "...and the current buffer [is] restored". The "current buffer" is independent of the buffer in the selected window, and moreover need not be displayed at all. The current buffer is simply the buffer which is being acted on at the time.

[–] [email protected] 1 points 11 months ago

This is 100% expected behaviour. save-excursion has nothing to do with windows.

Perhaps you are confused about the phrase "...and the current buffer [is] restored". The "current buffer" is independent of the buffer in the selected window, and moreover need not be displayed at all. The current buffer is simply the buffer which is being acted on at the time.

[–] [email protected] 1 points 11 months ago