help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Is there a way to hightlight region permanently?


From: Drew Adams
Subject: RE: Is there a way to hightlight region permanently?
Date: Sun, 2 Jul 2017 07:52:43 -0700 (PDT)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]