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

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

RE: [External] : mark multi regions, kill and yank


From: Drew Adams
Subject: RE: [External] : mark multi regions, kill and yank
Date: Mon, 30 Oct 2023 17:32:47 +0000

> I am looking for a package that allows me
>   1. to mark several regions,
>   2. To kill them
>   3. And then later to yank everything.

`C-w' kills the region text.

`C-M-w' appends the region text to the last kill.

So just use `C-w' for one region, then
`C-M-w C-w' for each subsequent region you
want to kill.  Each `C-M-w C-w' appends that
region to the latest string in `kill-ring'.

Then `C-y' yanks them all, as the latest string
in `kill-ring'.
___

If you don't want to kill the regions, and you
just want to copy them together (concatenated)
to the kill-ring, you can use library zones.el
for that.  And it doesn't matter when you "mark"
the regions of text that you want to later yank
together.

By default, each time you narrow the buffer,
the buffer restriction (the "narrowing") is
added to a list of zones, which is the value of
a variable (`zz-izones', by default).

You can prevent this automatic adding of
narrowings as zones, by setting option
`zz-narrowing-adds-zones-flag' to nil.

You can instead explicitly add the active
region of text as a zone using `C-x n a'
(command `zz-add-zone').  So just use that
any time you want to record a zone.

This is like `M-w', but instead of adding the
region's text to the kill-ring it adds it to
the current izones variable as a zone.

It's easy to define a command that copies the
text of the zones together to the `kill-ring':

(defun zz-copy-izones-as-kill (&optional variable)
"Copy text in izones to kill-ring.
The zones to use are those of VARIABLE that are in the current buffer.
VARIABLE defaults to the value of `zz-izones-var'.  With a prefix arg
you are prompted for a different variable to use."
(interactive
 (list (or (and current-prefix-arg
                (zz-read-any-variable
                 "Variable: " zz-izones-var t))
           zz-izones-var)))
(let* ((var      (or variable  zz-izones-var))
       (izones   (symbol-value var))
       (strings  ()))
  (dolist (iz  izones)
    (push (buffer-substring (cadr iz) (caddr iz)) strings))
  (kill-new (apply #'concat strings))))

You can alternatively use a noncontiguous region.
`zones.el' has functions for converting a set of
zones to and from a noncontiguous region.  (For
one thing, this gives you an easy way to construct
a noncontiguous region of any sort interactively.)



reply via email to

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