unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "Emacs-Devel" <emacs-devel@gnu.org>
Subject: option to let isearch select the search target (in transient mark mode)
Date: Tue, 10 Jul 2007 12:58:48 -0700	[thread overview]
Message-ID: <BDEIJAFNGDOAGCJIPKPBAEKHCFAA.drew.adams@oracle.com> (raw)

How about adding this to Isearch: Depending on the value of an option,
`isearch-set-region-flag', Isearch leaves the region active around the
search target when you stop searching with `RET'.  This is only for
Transient Mark mode; if that mode is not on, then this does nothing.

This feature makes it easy to delete the found text, copy it, or type
to replace it in Delete Selection mode.  You can toggle the option at
any time during searching, with `C-SPC'.

I use `isearch-mode-end-hook' to implement this, but it could no doubt
be integrated with the Isearch code more directly.  Alternatively,
`transient-mark-mode' could perhaps add this to or remove it from
`isearch-mode-end-hook'.  In that case, the test for
`transient-mark-mode' would be removed.

(defcustom isearch-set-region-flag nil
  "Non-nil means set region around search target.
This is used only for Transient Mark mode.
You can toggle this with `isearch-toggle-set-region', bound to
`C-SPC' during isearch."
  :type 'boolean :group 'isearch)

(add-hook 'isearch-mode-end-hook 'isearch-set-region)

(defun isearch-set-region ()
  "Set the region around the search target, if `isearch-set-region-flag'.
This is used only for Transient Mark mode."
  (when (and isearch-set-region-flag transient-mark-mode)
    (push-mark isearch-other-end t 'activate)))

(defun isearch-toggle-set-region ()
  "Toggle `isearch-set-region-flag'."
  (interactive)
  (setq isearch-set-region-flag (not isearch-set-region-flag))
  (if isearch-set-region-flag
      (message "Setting region around search target is now ON")
    (message "Setting region around search target is now OFF")))

(define-key isearch-mode-map [(control ? )]
  'isearch-toggle-set-region)

And here is a standalone command, for users who want to do this only
upon demand and leave `isearch-set-region-flag' = nil:

(defun set-region-around-search-target ()
  "Set the region around the last search or query-replace target."
  (interactive)
  (case last-command
    ((isearch-forward isearch-backward isearch-forward-regexp
                      isearch-backward-regexp)
     (push-mark isearch-other-end t 'activate))
    (t (push-mark (match-beginning 0) t 'activate)))
  (setq deactivate-mark nil))

             reply	other threads:[~2007-07-10 19:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-10 19:58 Drew Adams [this message]
2007-07-10 20:37 ` option to let isearch select the search target (in transient mark mode) Davis Herring
2007-07-10 21:03   ` Mathias Dahl
2007-07-10 21:31     ` Davis Herring
2007-07-10 21:56   ` Drew Adams
2007-08-01  9:46   ` Johan Bockgård
2007-07-11  2:34 ` Miles Bader
2007-07-11  3:05 ` Richard Stallman
2007-08-01  9:51   ` Johan Bockgård
2007-07-12  7:28 ` Slawomir Nowaczyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BDEIJAFNGDOAGCJIPKPBAEKHCFAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).