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?

  • And the question is...? – Drew May 29 at 14:00
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.

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))
  • Accept your own answer once you're able to. – DoMiNeLa10 May 31 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.