unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Hongyi Zhao <hongyi.zhao@gmail.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Automatically highlight all same occurrence of same stuff which has been currently marked/selected.
Date: Sun, 21 May 2023 07:17:26 +0000	[thread overview]
Message-ID: <87cz2udugp.fsf@posteo.net> (raw)
In-Reply-To: <CAGP6POLifN9xwnkq5_dCw06zNa92jQr9Ei_fiYFfOwe5tZ=1Kg@mail.gmail.com> (Hongyi Zhao's message of "Sun, 21 May 2023 08:47:18 +0800")

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> Hi here,
>
> In an Emacs buffer, I want to let it automatically highlight all same
> occurrence of some stuff which has been currently marked/selected.
>
> Say, I have the following:
>
> foo ...
> .. bar...
> baz foo
>
> Then when I select one of the `foo` above, the two `foo`s will be
> highlighted automatically. Any tips for achieving this?

I have this command

--8<---------------cut here---------------start------------->8---
;;;; Search the selected region
(defun site/isearch-region (start end)
  "Start isearch with the contents between START and END."
  (interactive (if (use-region-p)
                   (list (region-beginning) (region-end))
                 (user-error "No region")))
  (when (and start end)
    (deactivate-mark)
    (isearch-mode t)
    (isearch-yank-string (buffer-substring start end))))

(global-set-key (kbd "M-s M-s") #'site/isearch-region)
--8<---------------cut here---------------end--------------->8---

that searches for whatever is selected.  That also highlights every
occurrence.

> Regards,
> Zhao



  parent reply	other threads:[~2023-05-21  7:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-21  0:47 Automatically highlight all same occurrence of same stuff which has been currently marked/selected Hongyi Zhao
2023-05-21  1:13 ` Michael Heerdegen
2023-05-21  1:44   ` Hongyi Zhao
2023-05-21  7:17 ` Philip Kaludercic [this message]
2023-05-22 11:16   ` Daniel Martín
2023-05-25 13:27     ` Rudolf Adamkovič
2023-05-25 14:29       ` Hongyi Zhao
2023-05-25 14:35         ` tomas
2023-05-25 15:31       ` Daniel Martín
2023-05-26 11:47         ` Rudolf Adamkovič
2023-05-26 12:26           ` Hongyi Zhao
2023-05-26 12:38             ` Eli Zaretskii

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=87cz2udugp.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=help-gnu-emacs@gnu.org \
    --cc=hongyi.zhao@gmail.com \
    /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.
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).