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*")).

  • 7890yuiop@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 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.

  • 7890yuiop@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 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.