[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: region around search hit
From: |
Andreas Roehler |
Subject: |
Re: region around search hit |
Date: |
Wed, 26 Jul 2006 14:16:40 +0200 |
User-agent: |
KNode/0.9.2 |
Drew Adams wrote:
> This could be programmed, but I'm wondering if there is already
> a quick way to do this: set the region around the last search
> occurrence, when isearch is exited. Likewise, for query-replace
> (even if exited with C-g).
;; works so far with isearch-forward
;; you have to customize `isearch-set-region' to t
before it takes effect
;; with isearch-backward isearch-pos-to-region still doesn't work that way
(defcustom isearch-set-region nil
"If the region around the last search occurrence, when isearch is exited,
should be set"
:type 'boolean
:group 'isearch)
(defun isearch-pos-to-region ()
"Set the region with beginning- and end-positions of the last isearch-string
found"
(interactive)
(when isearch-set-region
(goto-char (- isearch-success (length isearch-string)))
(transient-mark-mode t)
(push-mark)
(goto-char isearch-success)))
;; isearch-mode-end-hook
(defun isearch-exit ()
"Exit search normally.
However, if this is the first command after starting incremental
search and `search-nonincremental-instead' is non-nil, do a
nonincremental search instead via `isearch-edit-string'."
(interactive)
(if (and search-nonincremental-instead
(= 0 (length isearch-string)))
(let ((isearch-nonincremental t))
(isearch-edit-string)))
(isearch-done)
(isearch-clean-overlays)
;; 2006-07-26 a.roehler@web.de changed section start
(isearch-pos-to-region)
) ;; 2006-07-26 a.roehler@web.de changed section end