For instance, when editing an Emacs lisp file test.el, I would like to mark a text (for instance the name of a function) in the current buffer (I am using a single frame with a single window) then press a keyboard shortcut to split the current window into two parts, one above the other. The top window should display my orginal buffer as it was, the bottom window should display the buffer at the point where the function is defined (like (defun test-fun ...).
I have tried this code:
(defun test-split ()
(interactive)
(split-window-below 28)
(let (( w (next-window)))
(let ((buf (window-buffer w)))
(with-current-buffer buf
(beginning-of-buffer)
(re-search-forward "defun test-fun ")))))
but it does not work.. (It searches the top window, not the bottom window)