5

The find-function-at-point command finds a function and displays its definition in the other window, while moving point to the other window as well.

I'd like to have a version of find-function-at-point that opens the function definition in the other window, but leaves point in the current window.

I thought I could accomplish this with save-excursion in a lambda expression as follows:

(lambda ()
 (interactive)
 (save-excursion)
 (find-function-at-point))))

However, this doesn't seem to work. Point remains in the other window.

My understanding of save-excursion is that it should restore point and mark after the body of save-excursion is evaluated. What am I missing here?

Tianxiang Xiong
  • 3,848
  • 16
  • 27

1 Answers1

7

Your call to save-excursion has no body.

It is saving point, mark, and the current buffer, then doing nothing, and then 'restoring' those things to their saved values.

However that's the wrong macro. You want save-selected-window.

It sounds like you are under the misconception that there is a single point and mark which 'move' around between buffers. This is not the case -- each buffer has its own buffer-local point and mark values -- so "restoring point and mark" has nothing to do with changing the currently-selected window.

Nor indeed does "restoring the current buffer" -- that is simply the buffer (which is not necessarily visible in any window) which is current for the functions being called. "Restoring" this value has no bearing on whether/where that buffer is displayed.

In short, be aware that buffers are independent of the windows they can be displayed in. Mixing the two concepts in your mind will certainly lead to confusion.

phils
  • 48,657
  • 3
  • 76
  • 115