isearch (see IncrementalSearch) is a useful navigation mechanism. This works a little better if isearch puts you at the start of the search, not the end:
(add-hook 'isearch-mode-end-hook 'my-goto-match-beginning) (defun my-goto-match-beginning () (when isearch-forward (goto-char isearch-other-end)))
‘C-g’, and you use such a hook, the mark is not set at the search start, so you cannot get back there via
‘C-x C-x’. Too bad. (Ending the search with
‘RET’or something else does set the mark correctly.) – DrewAdams
[new] With an incremental search, it actually seems fairly natural to end up with point at the end of the search term; after all, you can see it progressing along the search term with each character that you enter. That’s not the case, however, for non-incremental search (search-forward, bound to C-s RET). So is it possible to do a similar thing like this for non-incremental search? I’ve only managed to do it using a wrapper so far:
(defun my-search-forward (term) "Search forward, moving to the beginning of term." (interactive (list (read-from-minibuffer "Find: "))) (if (search-forward term) (backward-char (length term))))
But a hook approach would be better. – SeanPalmer?
[new] Surely (backward-char (length term)) is going to fail for most regex searches. You could, however, use (search-backward term) to move from the end of the match to the beginning. Doing this with ‘after’ advice and only in the interactive case might be safe, but you certainly wouldn’t want to be messing with this function this way in non-interactive circumstances – too many things depend upon its standard behaviour.