help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: cursor position upon search


From: Drew Adams
Subject: RE: cursor position upon search
Date: Sun, 28 Feb 2010 14:51:39 -0800

> If the search string is "arg", then is there a command in
> emacs to place the cursor on the first character of arg
> when it is found rather than 1 past the last character
> as search-forward for instance does?

1. I assume you're asking about interactive use of Isearch (even though you
asked about `search-forward').

See `isearch-mode-end-hook' and variable `isearch-other-end'. The latter is the
position you want to go to. The former gives you a way to go there:

(defun foo () (goto-char isearch-other-end))
(add-hook 'isearch-mode-end-hook 'foo)

2. If you really meant `search-forward' and you are using this in Lisp code,
then after calling `search-forward' just (goto-char (match-beginning 0)).

3. If what you really want is to select the search hit, then see library
`isearch+.el' - option `isearchp-set-region-flag' determines this behavior. You
can use `C-SPC' during Isearch to toggle the behavior.
http://www.emacswiki.org/emacs/IsearchPlus





reply via email to

[Prev in Thread] Current Thread [Next in Thread]