unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* replace-within-highlighted-region - Is it possible to write? or too hard?
@ 2024-07-21  1:50 gnuist
  2024-07-21 12:57 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-07-21 16:47 ` [External] : " Drew Adams
  0 siblings, 2 replies; 4+ messages in thread
From: gnuist @ 2024-07-21  1:50 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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

Tx



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: replace-within-highlighted-region - Is it possible to write? or too hard?
  2024-07-21  1:50 replace-within-highlighted-region - Is it possible to write? or too hard? gnuist
@ 2024-07-21 12:57 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-07-21 16:55   ` [External] : " Drew Adams
  2024-07-21 16:47 ` [External] : " Drew Adams
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-07-21 12:57 UTC (permalink / raw)
  To: help-gnu-emacs

gnuist <gnuist@protonmail.com> writes:

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

AFAIR, isearch+ can do this out of the box.

Isearch itself needs some help: You would first have to mark the
region(s) to treat yourself - using hi-lock for example, or something
even more basic (text properties or overlays).  And then use an
according `isearch-filter-predicate' to limit isearch operations to
these regions.


Michael.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [External] : replace-within-highlighted-region - Is it possible to write? or too hard?
  2024-07-21  1:50 replace-within-highlighted-region - Is it possible to write? or too hard? gnuist
  2024-07-21 12:57 ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-07-21 16:47 ` Drew Adams
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2024-07-21 16:47 UTC (permalink / raw)
  To: gnuist, help-gnu-emacs@gnu.org

> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [External] : Re: replace-within-highlighted-region - Is it possible to write? or too hard?
  2024-07-21 12:57 ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-07-21 16:55   ` Drew Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2024-07-21 16:55 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'

[-- Attachment #1: Type: text/plain, Size: 920 bytes --]

> > Hi - 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.
> 
> AFAIR, isearch+ can do this out of the box.

Yes, in particular in combination with `zones.el'.

And it's mainly the `isearch-prop.el' part of
Isearch+ that works with zones.

Isearch+ description:

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

`isearch+.el':

https://www.emacswiki.org/emacs/download/isearch%2b.el

`isearch-prop.el':

https://www.emacswiki.org/emacs/download/isearch-prop.el
 
> Isearch itself needs some help: You would first have to mark the
> region(s) to treat yourself - using hi-lock for example, or something
> even more basic (text properties or overlays).  And then use an
> according `isearch-filter-predicate' to limit isearch operations to
> these regions.

Yes.


[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 14659 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-21 16:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-21  1:50 replace-within-highlighted-region - Is it possible to write? or too hard? gnuist
2024-07-21 12:57 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-07-21 16:55   ` [External] : " Drew Adams
2024-07-21 16:47 ` [External] : " Drew Adams

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