5

The title says it all.

I'm looking for a C- or M- built-in way to select non-consecutive lines and blocks of text, like usual consecutive lines with Shift or C-SPC.

I.e. I need a switch that turn selecting off and back on, but previous selections stay.

iantonuk
  • 151
  • 1
  • 4

3 Answers3

2

Not built in but another package for this is called objed (I'm the author). You can mark any text object with m the point is moved to the next object of current type automatically. Unmark any object by navigating to it and press m again. Here is an example screencast:

enter image description here

clemera
  • 3,401
  • 13
  • 40
1

Emacs does not offer this currently. (And the so-called "non-consecutive region" is at best only a very partial substitute, IMHO.)

You can, however, use library zones.el (see Zones and Multiple Narrowings) to act on multiple, non-contiguous buffer zones, either together or separately.

You can put the region on any zone, and then use commands that act on the region. And you can write commands that act on multiple zones.

But Emacs itself does not currently have a notion of multiple-zone region, that is, a region whose parts are truly non-contiguous.


In particular, if you try to Isearch the rectangular region (so-called "non-consecutive region") the search is actually performed against the whole buffer, and search hits that are not entirely within the rectangle are filtered out. This can have the effect of missing some legitimate search hits that are within the rectangle. See Emacs bugs #27896 and #27926.

Drew
  • 75,699
  • 9
  • 109
  • 225
0

There is currently no such functionality in Emacs. The infrastructure to make it possible is pretty much there, but the UI for it is missing.

More specifically, there is one form of "non-consecutive region" which is supported: rectangular regions. The underlying hooks (such as region-extract-function) can be used for non-rectangular non-consecutive regions, but I don't know yet of any package which implements this.

Stefan
  • 26,154
  • 3
  • 46
  • 84