Thanks for the swift reply Juri.
If "artificial resctrictions (...) should be lifted" means that rectangular regions could start working with occur, that sounds great.
Regarding your question, I'm not aware of the possible dependencies between perform-replace and occur. My intended use case is to have a separate function to extract a non-contiguous region of my liking (i.e., in the form of a list of cons cells of buffer positions) and have occur operate on that list by passing it in as the "region" argument. That way, occur wouldn't return any matches in the parts of the buffer I'm not interested in. I interpreted the documentation of occur to support passing in region like that, in particular from this formulation:
"REGION must be a list of (START . END) positions as returned by
`region-bounds'."
In elisp-code, this is how I changed occur to also support non-contiguous regions according to my interpretation of the documentation:
------------ begin elisp-code ----------------------
(defun my-occur (regexp &optional nlines region)
"My fix to occur, which does not handle non-contiguous regions
now. I filed a bug report for this."
(interactive
(nconc (occur-read-primary-args)
(and (use-region-p) (list (region-bounds)))))
(let ((bufs (list))
(once t))
(while (or region once)
(let* ((start (and (caar region) (max (caar region) (point-min))))
(end (and (cdar region) (min (cdar region) (point-max))))
(in-region (or start end))
(buf (if (not in-region) (current-buffer)
(let ((ol (make-overlay
(or start (point-min))
(or end (point-max)))))
(overlay-put ol 'occur--orig-point (point))
ol))))
(push buf bufs))
(setq once nil)
(setq region (cdr region)))
(occur-1 regexp nlines bufs)))
(defalias 'occur 'my-occur)
-------------- end elisp-code -----------------------------------------
Anyway, I'll leave it up to you to interpret the documentation and if it or the code requires a fix.
Thanks again,
Magnus