1

I went from this issue Highlighting text in open (displayed) buffers/windows — searching for text from one buffer in another.

I would like to write the function for these commands to jump to word in another window: C-s C-w C-x o C-s C-s C-x o.

This is my code that doesn't work:

 (defun jump-word-other-window ()
   (interactive)
   (save-excursion
     (isearch-yank-word-or-char)
       (other-window 1)
       (isearch-forward)
       (isearch-repeat-forward)
        (other-window 1)))

How can I write this working keyboard combination in the function?

Pfedj
  • 338
  • 2
  • 11

2 Answers2

1

Take a look at save-excursion documentation:

Save point, and current buffer; execute BODY; restore those things.

No matter how many times other-window function is called point will remain where your function was invoked.

muffinmad
  • 2,300
  • 8
  • 11
1

Here's the solution.

(defun jump-word-other-window ()
  (interactive)
  (isearch-forward nil 1)
  (isearch-yank-word-or-char)
  (other-window 1)
  (isearch-repeat-forward)
  (isearch-exit)
  (other-window 1))
Pfedj
  • 338
  • 2
  • 11