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

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

RE: [External] : replace-within-highlighted-region - Is it possible to w


From: Drew Adams
Subject: RE: [External] : replace-within-highlighted-region - Is it possible to write? or too hard?
Date: Sun, 21 Jul 2024 16:47:07 +0000

> I am thinking of a function where you can highlight region, only lets
> say of one color (ie category) and then be able to replace strings or
> regexp within those region only.
> 
> Functionally, it would be equivalent to narrowing to multiple regions all
> at once, based on a regexp and highlighting those regions.
> 
> In my previous posts on ediff-buffers, I was thinking that #f or focus
> provided such a functionality within each active region and REFINED to it
> as the new active region within what was highlighted before it.
> 
> In addition, I was thinking that #h provided a functionality whereby you
> would be able to ignore those regions (ie matched strings) that would be
> masked.
> 
> The problem with narrow-to-region is that undoing is harder of a macro,
> whereas replace can be undone with a single undo.
> 
> As it is, the current #f is almost equivalent to show-lines-matching-
> regexp and #h is almost equivalent to hide-lines-matching-regexp.

See `zones.el'.

In a nutshell, you're looking to query-replace
text within a zone set.

Easily define one or more sets of zones.  You
can think of a zone set as a (more flexible)
noncontiguous region or as "multiple regions".

. Highlight a zone set, if you like.
. Search only within a zone set.
  Or only outside it (search the complement).
. Hide a zone set or its complement.
. Query-replace(-regexp) text within a zone set.
  Or its complement.
. Map a function over a zone set.
. Combine zone sets or zones in a zone set.

Pretty much anything you can do with the
Emacs region you can do with a set of zones.
But existing Emacs commands that act on the
region don't know about zone sets (or about
non-contiguous regions).  You can define
new commands that take them into account.

E.g., This command highlight the text in a
zone set.  It iterates over the zone set in
var `zz-izones' with a function that takes
a zone as an argument and highlights it.
(That function, `hlt-highlight-region', is
from library `highlight.el'.)

What `zones.el' offers in this regard is a
way to easily define a set of buffer zones. 

(defun hlt-highlight-regions
  (&optional regions face msgp mousep buffers)
  "Apply `hlt-highlight-region' to regions in `zz-izones'."
  (interactive
    (list (zz-basic-zones zz-izones) nil t current-prefix-arg))
  (dolist (start+end  regions)
    (hlt-highlight-region (nth 0 start+end) (nth 1 start+end)
                          face msgp mousep buffers)))


Description:

https://www.emacswiki.org/emacs/Zones

Code:

https://www.emacswiki.org/emacs/download/zones.el

or (a little older version):

https://elpa.gnu.org/packages/zones.html


reply via email to

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