unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Marcin Borkowski <mbork@mbork.pl>,
	Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: RE: Is there a way to hightlight region permanently?
Date: Sun, 2 Jul 2017 07:52:43 -0700 (PDT)	[thread overview]
Message-ID: <71d925e4-ba3c-47a3-8b54-b527cdd45c82@default> (raw)
In-Reply-To: <87eftzrxwn.fsf@jane>

> I'd like to have something like `highlight-regexp' and
> `unhighlight-regexp', but for the current region.  I.e.,
> something that stays highlighted after I move point
> and/or mark, and whose highlighting I can easily turn
> off when no longer needed.
> 
> Any hints?  Or should I just code that myself?

1. You can easily do what you ask, using library
`highlight.el'.

https://www.emacswiki.org/emacs/HighlightLibrary
https://www.emacswiki.org/emacs/download/highlight.el

You say "permanently" in your Subject line, but it
sounds like you just want to highlight the text in
the region and have that highlighting persist during
the current Emacs session, or until you remove it.

For that, all you need is command `hlt-highlight-region',
bound by default to `C-x X h r'.

[All of the library commands are bound on prefix key
`C-x X', the `h' is for "highlight" (`u' is for
"unhighlight"), and the `r' is for "region".  You can
bind commands to keys individually or use a different
prefix key.]

There are lots of other, related commands, including, for
example, `hlt-highlight-regexp-region' (`C-x X h x').

The single command `hlt-highlight' (`C-x X h h' - I bind
it to `C-x C-y' also) gives you the behaviors of multiple
commands all rolled into one, determined by a prefix arg:

* No prefix arg - highlight all text in region/buffer
* Plain prefix arg (`C-u') or zero prefix arg (`C-0'):
  UNhighlight all
* Positive prefix arg (`C-1'): highlight regexp matches
* Negative prefix arg (`C--'): UNhighlight regexp matches

All of the highlighting and unhighlighting commands
can use text property `face', `font-lock-face', or
`mouse-face'. All of them can use an overlay property
instead of, or in addition to, a text property.  The
default behavior is to use overlay highlighting.

All of the commands let you choose whether the
highlighting is controlled by font-lock or is
independent of font-lock.

You can highlight zones of text defined by their limits.

You can act across multiple buffers: highlighting,
unhighlighting, swapping one face for another, etc.

You can copy and yank text properties from one bit
of text to another.

You can temporarily hide or show text that you have
highlighted.

If you did really want to save your highlighting
permanently, i.e., have it persist between Emacs
sessions, you can do that too.  This bit of doc
describes permanent/persistent highlighting:

https://www.emacswiki.org/emacs/HighlightLibrary#PermanentHighlighting



2. As Stephen Berman suggested, a simple way to
highlight text and have that highlighting stay put
while you move point, is to use the secondary
selection.

Vanilla Emacs lets you use the secondary selection
only using the mouse.  That's probably one reason
that few Emacs users use it or even know about it.
You really need ways to create it (selecting text)
and yank it using the keyboard.

Library `second-sel.el' can help.

https://emacswiki.org/emacs/SecondarySelection#second-sel.el
https://www.emacswiki.org/emacs/download/second-sel.el

There are lots of things you can do with the
secondary selection, and there are lots of ways to
create or move it.

In particular, you can create it from the active
region, using command `primary-to-secondary'.
But the most versatile command, which I bind to
`C-M-y', is this one: `secondary-yank|select|move|swap'.

By default it yanks the secondary selection at point.
With a prefix arg it interacts with the active region:

 Zero: Select secondary as region.
 > 0:  Move secondary to region.
 < 0:  Swap region and secondary.



      parent reply	other threads:[~2017-07-02 14:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-02  9:27 Is there a way to hightlight region permanently? Marcin Borkowski
2017-07-02 12:24 ` Stephen Berman
2017-07-02 14:52 ` Drew Adams [this message]

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=71d925e4-ba3c-47a3-8b54-b527cdd45c82@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    /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).