From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Sam Halliday Newsgroups: gmane.emacs.bugs Subject: bug#35119: 26.1; narrow-to-region loses word-start/symbol-start information at end Date: Wed, 3 Apr 2019 14:01:58 +0100 Message-ID: References: <87y34r1glv.fsf@gmail.com> <83a7h7e3ex.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="259402"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 35119@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 03 15:03:22 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBfY1-0015GT-NW for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Apr 2019 15:03:21 +0200 Original-Received: from localhost ([127.0.0.1]:42530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBfY0-00054r-QW for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Apr 2019 09:03:20 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBfXp-00054J-In for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2019 09:03:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBfXk-0000sr-Q6 for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2019 09:03:09 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hBfXi-0000rv-4f for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2019 09:03:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hBfXh-0005gc-Sm for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2019 09:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sam Halliday Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Apr 2019 13:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35119 X-GNU-PR-Package: emacs Original-Received: via spool by 35119-submit@debbugs.gnu.org id=B35119.155429653921803 (code B ref 35119); Wed, 03 Apr 2019 13:03:01 +0000 Original-Received: (at 35119) by debbugs.gnu.org; 3 Apr 2019 13:02:19 +0000 Original-Received: from localhost ([127.0.0.1]:42183 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hBfX0-0005fb-Oi for submit@debbugs.gnu.org; Wed, 03 Apr 2019 09:02:19 -0400 Original-Received: from mail-vs1-f48.google.com ([209.85.217.48]:46557) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hBfWy-0005fN-LV for 35119@debbugs.gnu.org; Wed, 03 Apr 2019 09:02:17 -0400 Original-Received: by mail-vs1-f48.google.com with SMTP id e2so9184014vsc.13 for <35119@debbugs.gnu.org>; Wed, 03 Apr 2019 06:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rpAuXqEkwcQPPg4cTdJT4YVGjtR6/MZLt16yO/2O0OY=; b=HHaqk2osa6d5tIbY0TbBkUEyO+1kWZp1jWlBbaeFkVt/vuoCDQz7CV7tGYvAy6oeyj iVo472pEcMmsyDS9ufjSi8DiFm9h1v23HcFclu7EhJxzfxp4SQtaWsBd/qIa6i8AeGSu 4NxqUnDf5Irm8cGreRfo1tWcnT3SZp++BkQCgFglR7Kt3N8W92VCJ4hVf5wpZYpg+lRR pbcs2zLE/kD4u5+T0tcMqBfRHsxhSEvJj9QtdZJA42zA3Ji06DRMFtXmP3+kVkk/Ndmk xAGSBEBwXPQi4iqvQ1y8o73XSHebNIBkCWb0cnypHykNpv1db3gyH7lrXSWYnAl5qIgk IBAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rpAuXqEkwcQPPg4cTdJT4YVGjtR6/MZLt16yO/2O0OY=; b=TvEno8ctJUiOkGC37Ai+Cg5xe/UQwEVTxzZQ4EjAbTHEocuI+0QgGvHNT6AJS4y5+m zGGzPdtem7GBQ1lS3EwYTHYloxAndowmmSFt1rx9S67+i+JC2PNGW6JAqW62WY4etpZL tdPdVlAXZV/0Rw6/+1/jfC6X02t02hGyz1kC9KMbYLcxdOcVFo3vLRy2OkHAb7/dhOnZ BlJtJVL7bCG3hJd3+XA4KVXKiS+m+YoyKV8ZK4jHupY0KQ8OIKw85xEDc/HYPkbPFQi/ pqKwCjp5jeNRGlebSNqrB6YSfcZDlbnICGolFxOUcUCylWA6qUqKfKgCkFzeiVGXs7yY +V5w== X-Gm-Message-State: APjAAAXqbekFUi43mcpDIsbhp7rHdXKIiX6njqQPSfON2JmUtxkgbzcP DC2sZ5Y5A5+ZZEnuOedYrWKg2xy76nzNZBL36ts= X-Google-Smtp-Source: APXvYqwOHBBC67O91rOcID5lRrzdsYXZSJV99B3AEmHpYpfwUVbHXcV+7R07i0AcJh5Iw6CGwzSfEytV73mnva6I3Ws= X-Received: by 2002:a67:6847:: with SMTP id d68mr53867vsc.90.1554296530070; Wed, 03 Apr 2019 06:02:10 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:157120 Archived-At: Hmm, on further investigation I think this may just be regexp behaviour. I came up with this as an alternative to `looking-back' (defun my-looking-back (regexp lower) (let ((upper (point)) (start lower)) (save-excursion (catch 'hit (while (< start upper) (goto-char start) (re-search-forward regexp upper 't) (when (= (point) upper) (throw 'hit 't)) (setq start (+ 1 start))) nil)))) and it also fails to match the : in the example. So perhaps limit is also excluding the zero-length implied by the subsequent character. On Wed, 3 Apr 2019 at 13:30, Sam Halliday wrote: > > Hi Eli, > > Sorry that was a terrible bug report. > > This impacts me in `looking-back'. Here's an interactive snippet to > demonstrate the problem (not minimised to`narrow-to-region'): > > (defun look-for-35119 () > (interactive) > (if (looking-back > (rx (: word-end ":" word-start)) > ;;(rx (: word-end ":")) > (- (point) 1) 't) > (message "hit") > (message "miss"))) > > in emacs-lisp-mode, which defines : as non-word, interactively > evaluate look-for-35119 when the point is just after the colon in this > example text > > wibble:wobble > > I would expect to see "hit", but we get "miss". To demonstrate that > the word-start is the cause of the problem, try the commented regexp > and try again, you'll get "hit" but of course this regexp is not what > is intended. For example, it would also match in between :: in the > following: > > wibble::wobble > > The cause is that the `narrow-to-region' call inside `looking-back' is > dropping the word-start zero length match at the beginning of wobble. > This may or may not be a bug in narrow-to-region, but I'm quite sure > it's a bug in `looking-back'. There is most likely a similar example > demonstrating that the zero lengths are missing at the start as well > as the end. > > I've tried playing around with multiple alternative implementations of > `looking-back' but none are working for me. Probably the best > workaround I can think of is to extend the `narrow-to-region' call by > one more character at the start and the end. Dealing with the start is > easy, we just goto-char limit+1, but dealing with the end is difficult > as we need to put an anychar \\. matcher in the doctored regexp and > then the match-end is off-by-one from what the user expects, so then > we have to doctor that, and then all hell breaks loose. > > Does that make sense? > > > On Wed, 3 Apr 2019 at 12:25, Eli Zaretskii wrote: > > > > > From: Sam Halliday > > > Date: Wed, 03 Apr 2019 12:19:08 +0100 > > > > > > If the function `narrow-to-region' (as it is in `looking-back') is used > > > to restrict the region prior to an invocation of re-search-forward or > > > looking-at, then zero length regexp patterns are lost at the boundaries. > > > > Could you please provide a recipe to reproduce the issue? I'm not > > sure I understand what is the problem you are describing. > > > > Thanks.