1

What's the best way to move point to the start of an isearch result instead of the end?

E.g. given the following, where | is point:

|foo bar baz    

And searching for bar, I'd like point to be at:

foo |bar baz

instead of

foo bar| baz

The latter is almost never useful.

1 Answer 1

2

Assuming that you don't want the same behavior on isearch-backward:

(defun isearch-exit--after ()
  (when isearch-forward
    (setf (point) isearch-other-end)))
(advice-add 'isearch-exit :after 'isearch-exit--after)
3
  • 1
    Cool, thanks. So isearch-backward puts point at the beginning of the result? Super weird! Commented Apr 25, 2017 at 19:38
  • Not weird. The defaults are such that another search in the same direction for the same pattern will not find the same match you found last time.
    – phils
    Commented Apr 25, 2017 at 21:55
  • Ah, that makes sense...however, it seems that this information could simply be held in some variable (isearch doesn't shy away from state anyway). Commented Apr 25, 2017 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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