elisp - Emacs: select multiple regions and switch to inverse -


i know there few different packages selecting multiple regions in gnu emacs. i'm looking way select multiple regions, operate on them, , select inverse of marked regions in order operate on them.

as example, suppose have following data in buffer:

line line b line c line d line e line f 

what want following:

  1. mark lines a, c, , e multiple regions
  2. apply elisp text within these marked regions
  3. tell emacs switch marked , unmarked regions. now, lines b, d, , f should ones marked multiple regions
  4. apply other elisp text within these other regions

steps 1, 2, , 4 trivial, , depend on choice of multiple-region-marking code decide use.

but step 3? there multiple-region-marking package allows me switch inverse of marked?

your question general. answer fit of it, maybe not all.

  1. library zones.el (see zones) lets define , manipulate multiple zones (in effect, multiple regions) of text, across multiple buffers. can these kinds of things them:

    • sort them.
    • unite (coalesce) adjacent or overlapping zones (which includes sorting them).
    • complement them if have been united.
    • intersect them.
    • narrow buffer zones in list - see multiplenarrowings.
    • select zones in list active region. cycle among regions.
    • search them (they automatically united first). need library isearch-prop.el (see isearch+).
    • highlight , unhighlight them. (for need highlight library (highlight.el) or library facemenu+.el (see facemenu+).
    • add active region list of zones.
    • add region list of zones, , unite (coalesce) zones.
    • delete zone list of zones.
    • clone zones variable one, clone has same zones.
    • clone zones variable , unite zones of clone.
    • make list-of-zones variable persistent, in bookmark. use bookmark restore in subsequent emacs session. need library bookmark+.
  2. library isearch+ (including [isearch-prop.el](https://www.emacswiki.org/emacs/isearch-prop.el)) lets search both zones defined zones.el , zones defined text or overlay properties (any properties), , facilitates applying properties zones of text.

    • you can search complement of set of zones, think question about. areas not being searched can optionally dimmed during search.
    • you can search various "things" zones. things can can define syntactically. include usual emacs "things", , if use library thingatpt+.el can define additional things.
  3. if use icicles can use icicles search on set of search contexts in buffers or files. can define search contexts in various ways, including using regexp. there can search complement of set of search contexts. , can use incremental narrowing of matching search contexts, , when doing can subtract sets of matches using complementing.


updated after remarks -

you apparently want complement list of non-basic zones (what call "izones"), each number identifier followed 2 zone limits. (basic zones have limits , not identifier, , function zz-zones-complement returns list of basic zones.)

this how define complement function:

(defun zz-complement-izones (izones &optional beg end)   "complement izones, list `zz-izones'. such list returned, is, zones have identifiers."   (zz-izones-from-zones    (zz-zones-complement (zz-zone-union (zz-izone-limits izones nil t))))) 

that uses predefined function zz-zones-complement after stripping zone identifiers , coalescing zones. predefined function zz-izones-from-zones gives zones identifiers, making result list of izones.

and want function maps function on list of zones, applying each zone in list - function traverse-zones does.

here version (untested) of such map function expects zones of form using, is, izones (zones have number identifier) , maps 3-ary function on them. similar traverse-zones (but see comment):

(defun map-izones (function &optional izones)   "map 3-ary function on izones. function applied first 3 elements of each zone. izones list `zz-izones', is, zones identifiers."   ;; want this?  prohibits mapping on empty list of zones.   ;; (unless izones) (setq izones  zz-izones)   (when (and (functionp function)  (zz-izones-p izones))     (setq izones  (zz-unite-zones izones))     (dolist (izone  izones) (funcall function (car izone) (cadr izone) (caddr izone))))) 

and here (untested) version maps binary function on list of zones. zones in list can either basic zones or izones. seems more useful me, identifiers not useful in such context.

(defun map-zones (function &optional zones)   "map binary function on zones, applying limits of each zone. zones can list of basic zones or list `zz-izones', is, zones have identifiers."   (when (functionp function)     (when (zz-izones-p zones)       (setq zones  (zz-izone-limits zones nil 'only-this-buffer)))     (setq zones  (zz-zone-union zones))     (dolist (zone  zones) (funcall function (car zone) (cadr zone))))) 

hope helps.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -