[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Point at beginning of search pattern incompatible with M-p
From: |
Juri Linkov |
Subject: |
Re: Point at beginning of search pattern incompatible with M-p |
Date: |
Sat, 06 Oct 2012 20:31:11 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu) |
> I had, for some time, the following code in my .emacs.
>
> The goal: always exit searches at the beginning of the expression found.
>
> (add-hook 'isearch-mode-end-hook 'custom-goto-match-beginning)
>
> (defun custom-goto-match-beginning ()
> "Use with isearch hook to end search at first char of match."
> (when isearch-forward (goto-char isearch-other-end)))
>
> Problem: when I want to reuse earlier search strings (with the command `M-p'),
> I get the following error:
> [...]
> Can this be fixed somehow, to enjoy both features (exiting searches at the
> beginning of the expression, and reusing earlier search strings) together?
I for one have this code in ~/.emacs that could help you to do what you want:
(define-key isearch-mode-map [(control return)] 'isearch-exit)
;; C-RET doesn't add the current search string to the search ring
;; and moves point to the beginning of the found search string.
(add-hook 'isearch-mode-end-hook
(lambda ()
;; Exiting isearch with C-RET
(when (eq last-input-event 'C-return)
;; Move point to the beginning of the found search string
(if (and isearch-forward isearch-other-end)
(goto-char isearch-other-end))
;; Don't add the current search string to the search ring
(if isearch-regexp
(setq regexp-search-ring (cdr regexp-search-ring))
(setq search-ring (cdr search-ring))))))
Not sure about turning this into some configurable options.