Yes. See library Zones, in particular, function
From the Commentary in
zones.el, section Define Your Own Commands:
Pretty much anything you can do with the Emacs region you can do
with a set of zones (i.e., with a non-contiguous "region"). But
existing Emacs commands that act on the region do not know about
non-contiguous regions. What you will need to do is define new
commands that take these into account.
You can define your own commands that iterate over a list of
izones in a given buffer, or over such lists in a set of buffers.
zz-map-izones can help with this.
As examples of such commands, if you use library
then you can use
C-x n h (command
highlight the izones recorded for the current buffer. You can use
C-x n H (command
hlt-highlight-regions-in-buffers) to do the
same across a set of buffers that you specify (or across all
visible buffers). If option
hlt-auto-faces-flag is non-nil then
each zone gets a different face. Otherwise, all of the zones are
highlighted with the same face. Complementary (unbound) commands
Defining your own command can be simple or somewhat complex,
depending on how the region is used in the code for the
corresponding region-action Emacs command. The definition of
hlt-highlight-regions just calls existing function
hlt-highlight-region once for each recorded zone:
(defun hlt-highlight-regions (&optional regions face msgp mousep buffers)
"Apply `hlt-highlight-region' to regions in `zz-izones'."
(interactive (list (zz-izone-limits zz-izones)
(dolist (start+end regions)
(hlt-highlight-region (nth 0 start+end) (nth 1 start+end)
face msgp mousep buffers)))
That's it - just iterate over
zz-izones with a function that
takes a zone as an argument. What
zones.el offers in this
regard is a way to easily define a set of buffer zones.
The doc also tells you how to easily create zones from bits of text such as what you describe. See, for example, function (command)
zz-add-zone is an interactive Lisp function in
It is bound to
C-x n a.
(zz-add-zone START END &optional VARIABLE NOT-BUF-LOCAL-P SET-VAR-P MSG)
Add an izone for the region to the izones of
But do not add a zone if it would cover the entire buffer.
Return the new value of
This is a destructive operation: The list structure of the variable
value can be modified.
VARIABLE defaults to the value ofzz-izones-var`.
With a prefix arg you are prompted for a different variable to use, in
place of the current value of
zz-izones-var. The particular prefix
arg determines whether the variable, if unbound, is made buffer-local,
zz-izones-var is set to the variable symbol:
prefix arg buffer-local set ‘zz-izones-var’
---------- ------------ -------------------
Plain ‘C-u’ yes yes
> 0 (e.g. ‘C-1’) yes no
= 0 (e.g. ‘C-0’) no yes
< 0 (e.g. ‘C--’) no no
END are as for ‘narrow-to-region’.
VARIABLE is the optional izones variable to use.
NOT-BUF-LOCAL-P means do not make
SET-VAR-P means set
MSG means echo the zone limits, preceded by string
zz-add-region-as-izone which also adds the region as an
izone, but which has a simpler signature and so can be used as a hook
function. (In particular, it is used on
zz-auto-add-region-as-izone-mode, to automatically add the region as
an izone each time it is deactivated.)