1

I'd like to mark the current isearch result so that it can be copied or cut (killed) via M-w and C-w. Is there a ready-made function for this?

The solution below provided by @danielpoe over here copies but does not cut. Changing kill-new to kill-region doesn't seem to work.

(defun hack-isearch-kill ()
   "Push current matching string into kill ring."
   (interactive)
   (kill-new (buffer-substring (point) isearch-other-end))
   (isearch-done))

(define-key isearch-mode-map (kbd "M-w") 'hack-isearch-kill)

If we can somehow mark the isearch result, then there would be no need for separate commands to do each job. Atom has one such package that can be used as a reference.

  • n.b. Edited to remove the suggestion of marking multiple results -- AFAICT that was not the intention of the question. – phils Dec 15 '19 at 20:43
  • @phils: It's unclear. That's what I thought too, but see the comment OP added to my answer today. – Drew Dec 19 '19 at 2:51
  • 2
    Hmm. Sati, please edit the question to clarify the functionality you're looking for. Based on your new comment to @Drew's answer I think you'd probably like github.com/victorhge/iedit and/or pragmaticemacs.com/emacs/multiple-cursors but at present it's hard to tell what your requirement is. – phils Dec 19 '19 at 3:01
  • @phils Yes, you've hit the nail. iedit and multiple-cursors is the kind of functionality I was looking for. – Sati Dec 19 '19 at 7:42
  • Your question has already been upvoted and answered (with upvotes) as a question about selecting the current search hit as the region. Please leave it as is, and post the other question, which you apparently meant to post, about all search hits, as a new, separate question. And keep in mind that comments can be deleted at any time - put all info into the question itself. – Drew Dec 19 '19 at 15:38
2

Your question is unclear (to me). You say you want to "mark regex isearch results" (plural). But the code you show just marks the final result - final match when you exit Isearch.

Is that what you want: just set the region around the final match, so you can use C-w or M-w on it?

If so, what was wrong with this answer on the page of your first link?

  • Isearch+ does this already. It optionally sets the region around the search target. You can use C-SPC C-SPC or M-= C-SPC at any time during Isearch to toggle this.

isearchp-deactivate-region-flag is a variable defined in isearch+.el.

Its value is t

Documentation:

Non-nil means isearching deactivates the region.

See also option isearchp-restrict-to-region-flag. You can toggle this option using M-= C-SPC during Isearch.

You can customize this variable.

| improve this answer | |
  • No, I want all instances that match to be marked, so that they can be processed in bulk, not just the final match. – Sati Dec 19 '19 at 1:32
  • Then I don't know what you mean by "marked", or how you intend to process them in bulk. The code you show in your question does not in any way deal with multiple search hits. – Drew Dec 19 '19 at 2:53
  • I've edited my question. Please see if it is clearer now. phils's last comment has got the answer I want. Perhaps he (or you) should post it as an answer and I would accept it. Sorry about the ambiguity of the original question. – Sati Dec 19 '19 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.