all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* option to let isearch select the search target (in transient mark mode)
@ 2007-07-10 19:58 Drew Adams
  2007-07-10 20:37 ` Davis Herring
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Drew Adams @ 2007-07-10 19:58 UTC (permalink / raw)
  To: Emacs-Devel

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))

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-08-01  9:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-10 19:58 option to let isearch select the search target (in transient mark mode) Drew Adams
2007-07-10 20:37 ` 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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.