From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Magnus Nilsson Newsgroups: gmane.emacs.bugs Subject: bug#56374: 27.2; Occur with non-contiguous regions Date: Mon, 4 Jul 2022 09:12:03 +0200 Message-ID: References: <86y1x9fky2.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000097c03f05e2f574a2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8201"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56374@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 04 09:13:27 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o8GGs-0001xk-1T for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 09:13:26 +0200 Original-Received: from localhost ([::1]:32952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8GGq-0007QE-E7 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 03:13:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8GGU-0007Q2-FG for bug-gnu-emacs@gnu.org; Mon, 04 Jul 2022 03:13:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52079) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8GGU-0001IZ-55 for bug-gnu-emacs@gnu.org; Mon, 04 Jul 2022 03:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o8GGT-0001d3-Uh for bug-gnu-emacs@gnu.org; Mon, 04 Jul 2022 03:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Magnus Nilsson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Jul 2022 07:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56374 X-GNU-PR-Package: emacs Original-Received: via spool by 56374-submit@debbugs.gnu.org id=B56374.16569187456218 (code B ref 56374); Mon, 04 Jul 2022 07:13:01 +0000 Original-Received: (at 56374) by debbugs.gnu.org; 4 Jul 2022 07:12:25 +0000 Original-Received: from localhost ([127.0.0.1]:45976 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8GFt-0001cD-1x for submit@debbugs.gnu.org; Mon, 04 Jul 2022 03:12:25 -0400 Original-Received: from mail-pf1-f171.google.com ([209.85.210.171]:43696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8GFp-0001by-FC for 56374@debbugs.gnu.org; Mon, 04 Jul 2022 03:12:23 -0400 Original-Received: by mail-pf1-f171.google.com with SMTP id g7so3381607pfb.10 for <56374@debbugs.gnu.org>; Mon, 04 Jul 2022 00:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alumni-chalmers-se.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=o2GOgVzHkJOeOxiy4gEWiRHImi4DamoSnEY5OkNJwcM=; b=oxP2xXgYJ5a9MLhCadUkxxvSq78IcdUyFZXvqOcXRuMKkktCXSb/8eTWhTlBQy8Hp4 By/g68QuCOOaRHtz2SoIlvF+KfGoXkBRZzkEj5NE8Agmj0EoZrcqnKoyg4rjYCUXhfzL lu6KP4xH0XvfdhWeX+cUur1RtqIHCXzG5AYLoZp2oR3HUwPStLQtLgjRkVLbgP2935KI 0jRxh9ymRmCPl1AXbaeUufKm79L8nlflAiIpde4QL3E4/M+/Z14fD8ph8dMk0OCR0RtL Jms/gUNmBRBo2UfT93NA/272fkYbt5j46g1sjnvADLZO5I+fKtNif/81ICHe/cbwBa/7 TwYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=o2GOgVzHkJOeOxiy4gEWiRHImi4DamoSnEY5OkNJwcM=; b=QUzMbrHCRsP2zIsjiIoWY7R70kyZefDrIdOAfAA/9rZTfuNLBSRMCssjLUj4zh5/aS J9daIPoY4XAPFq+nWd4WhT5KcCUlWCfJ6eQsw26392gWxZ34+BSP1s56uOObdQMxkKvK rIdOVe45kMPArv/opXa44iWdKqsp1T4py6pCp3PHxeZH/58SXjmxvGRPMN9rYiEoaVaW oTQedpb8t0N5ezLC9w6B1uowwlhn/eN/+sxxSiHlpzsumc48E1mGPRJkb08OUwoT9N+8 UOFAQBPWJ3E54FsJVq950EEDuDqEniyEp48fmuY0ROT7Bo5vPbgqTKXhEEc5V7Ofqc89 mEvg== X-Gm-Message-State: AJIora/2Qx405mjnanW6XR1LM0W2yytjVPJB+VWTn8WXTNjGWZGGkyG4 jOZmxjK4dheEnYMNJfQfOdsBv1PMYaFFhf+2Si/pNKcHWnmDPbz7 X-Google-Smtp-Source: AGRyM1uR4PZGxxNFb/eA8Dn8xR8Gek03digeBTQbDFRayqfdVO23QDvX/jrdEGmdAng4UiOsPNtMJ9vbZUcaXV6JiGM= X-Received: by 2002:a63:6a06:0:b0:3fd:5a1d:85c5 with SMTP id f6-20020a636a06000000b003fd5a1d85c5mr24647548pgc.130.1656918734514; Mon, 04 Jul 2022 00:12:14 -0700 (PDT) In-Reply-To: <86y1x9fky2.fsf@mail.linkov.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:236034 Archived-At: --00000000000097c03f05e2f574a2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Den m=C3=A5n 4 juli 2022 kl 08:35 skrev Juri Linkov : > > In the help text for 'occur' it indicates that it should be able to wor= k > > on non-contiguous regions (i.e., a list of cons cells on the form (STAR= T > > . END)). However, when I tried this in both Emacs 27 and 28, this > > doesn't work when I mark a rectangular region. It only catches > > occurrances found within the bounds of the first cons cell. > > Like bug#14013 now has a patch that implements support for any regexp > including "^.*$" on a non-contiguous region, occur should be improved > to use the same search function. (Also all artificial restrictions > on handling only the first cons cell in occur should be lifted.) > > > My intention was to override (region-bounds) within a let statement to > > return a non-contiguous region of interest (in the form of a list of > > cons cells) and let 'occur' work on that non-contiguous > > region. Unfortunately, this didn't work out as I planned. It would be > > neat if this could be fixed for upcoming versions. > > Do you expect that 'occur' should accept a non-contiguous region > in its argument REGION? This is not how perform-replace works. > The query-replace commands send the boolean value of > '(region-noncontiguous-p)' to perform-replace argument > 'region-noncontiguous-p', then perform-replace extracts it with > '(funcall region-extract-function 'bounds)'. > > Do you agree that 'occur' could do the same? > --00000000000097c03f05e2f574a2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for the swift reply Juri.=C2=A0

= If "artificial resctrictions (...) should be lifted" means that r= ectangular regions could start working with occur, that sounds great.=C2=A0=

Regarding your question, I'm not aware of the p= ossible dependencies between perform-replace and occur. My intended use cas= e is to have a separate function to extract a non-contiguous region of my l= iking (i.e., in the form of a list of cons cells of buffer positions) and h= ave occur operate on that list by passing it in as the "region" a= rgument. That way, occur wouldn't return any matches in the parts of th= e buffer I'm not interested in. I interpreted the documentation of occu= r to support passing in region like that, in particular from this formulati= on:=C2=A0
"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 regi= ons according to my interpretation of the documentation:
--------= ---- begin elisp-code ----------------------
=C2=A0 =C2=A0 (defun= my-occur (regexp &optional nlines region)
=C2=A0 =C2=A0 =C2=A0 &quo= t;My fix to occur, which does not handle non-contiguous regions
=C2=A0 = =C2=A0 now. I filed a bug report for this."
=C2=A0 =C2=A0 =C2=A0 (i= nteractive
=C2=A0 =C2=A0 =C2=A0 =C2=A0(nconc (occur-read-primary-args)=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (and (use-region-p) (lis= t (region-bounds)))))
=C2=A0 =C2=A0 =C2=A0 (let ((bufs (list))
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (once t))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 (while (or region once)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let* ((s= tart (and (caar region) (max (caar region) (point-min))))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(end (and (cdar region) (mi= n (cdar region) (point-max))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0(in-region (or start end))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(buf (if (not in-region) (current-buf= fer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (let ((ol (make-overlay
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(or start (point-min))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(or end (point-max)))))
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (over= lay-put ol 'occur--orig-point (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ol))))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push buf bufs))
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 (setq once nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (setq region (cdr region)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (occur-1 regexp= nlines bufs)))

=C2=A0 =C2=A0 (defalias 'occur 'my-occur)
-------------- end elisp-code ---------------------------------= --------

Anyway, I'll leave it up to you to in= terpret the documentation and if it or the code requires a fix.=C2=A0
=

Thanks again,
Magnus

Den m=C3=A5n 4 juli= 2022 kl 08:35 skrev Juri Linkov <jur= i@linkov.net>:
> In the help text for &= #39;occur' it indicates that it should be able to work
> on non-contiguous regions (i.e., a list of cons cells on the form (STA= RT
> . END)). However, when I tried this in both Emacs 27 and 28, this
> doesn't work when I mark a rectangular region. It only catches
> occurrances found within the bounds of the first cons cell.

Like bug#14013 now has a patch that implements support for any regexp
including "^.*$" on a non-contiguous region, occur should be impr= oved
to use the same search function.=C2=A0 (Also all artificial restrictions on handling only the first cons cell in occur should be lifted.)

> My intention was to override (region-bounds) within a let statement to=
> return a non-contiguous region of interest (in the form of a list of > cons cells) and let 'occur' work on that non-contiguous
> region. Unfortunately, this didn't work out as I planned. It would= be
> neat if this could be fixed for upcoming versions.

Do you expect that 'occur' should accept a non-contiguous region in its argument REGION?=C2=A0 This is not how perform-replace works.
The query-replace commands send the boolean value of
'(region-noncontiguous-p)' to perform-replace argument
'region-noncontiguous-p', then perform-replace extracts it with
'(funcall region-extract-function 'bounds)'.

Do you agree that 'occur' could do the same?
--00000000000097c03f05e2f574a2--