From unknown Sat Jun 21 03:04:28 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#25243 <25243@debbugs.gnu.org> To: bug#25243 <25243@debbugs.gnu.org> Subject: Status: 26.0.50; ffap-guesser very slow w/ region active in large diff files Reply-To: bug#25243 <25243@debbugs.gnu.org> Date: Sat, 21 Jun 2025 10:04:28 +0000 retitle 25243 26.0.50; ffap-guesser very slow w/ region active in large dif= f files reassign 25243 emacs submitter 25243 Tino Calancha severity 25243 minor tag 25243 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 21 10:36:21 2016 Received: (at submit) by debbugs.gnu.org; 21 Dec 2016 15:36:21 +0000 Received: from localhost ([127.0.0.1]:50400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJiwH-0005Ww-41 for submit@debbugs.gnu.org; Wed, 21 Dec 2016 10:36:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49413) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJiwG-0005Wj-A3 for submit@debbugs.gnu.org; Wed, 21 Dec 2016 10:36:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cJiwA-0007AK-1H for submit@debbugs.gnu.org; Wed, 21 Dec 2016 10:36:15 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:39338) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cJiw9-0007AD-UI for submit@debbugs.gnu.org; Wed, 21 Dec 2016 10:36:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJiw8-0003xZ-LA for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2016 10:36:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cJiw3-000792-PW for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2016 10:36:12 -0500 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33862) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cJiw3-00078K-JR for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2016 10:36:07 -0500 Received: by mail-pf0-x241.google.com with SMTP id y68so11085023pfb.1 for ; Wed, 21 Dec 2016 07:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=JXNbdNkD3g5pcXAye1ueO4SlaHRzag71S56Qik0+9EQ=; b=qpfI9NiJEmZ8bagZbYKCsAxBcA1sXlX9oSSg/X/fm61nYS+zwqym+rj/NTwnpvD1Me 3eTDGZH9arRojaS7x3/jf2VuNZWIpL75gadZG4jsaKTnktTXA4tAy8GvQdzKcHj5WG20 22b33XQREDWX4bChRyF4sOzwHwgfLPMb7CP2Yty220DXFwHYpUubco4/cS+sCC4SpLDh s62Gu4FiX1sY599ljIt5MdFbolA5w6qXsJa6YVXrfxDZy5+BY97MyEWvkv+WC7Ds5MNy 4ocJf6mvFHVGQZH5Poyn+SWr8yGZGQDKAoWfCxeG4uoAZMpjJD4tA7FNs2ThUtcjv0DK 2BJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=JXNbdNkD3g5pcXAye1ueO4SlaHRzag71S56Qik0+9EQ=; b=AGNgkA4Lmd/RNkENT4X0w5C2ks5CzZ3vcdSVmzb1x9UZejzuxbj1YK+KGPu/wfrctB Zsf1EkepXZ6g1Y5ISWgOFln3XjWtmDEYVThYeG9mI38iHg/QdszhfUuXDMk6lcjV/c4K A1Dj11tDV7Zx/XEPm5jvdqFTLNyBRIBSnNHP2yG2loyhai6TELuulthlbd4WAeT/Uafk /RiED4lTEJidu9dvRjV1CYj2CzkdGhnE/QxkQ4ujCkm8BJq6myXO/ALkGZ10YY/LTfJU ZYENvRtnoLV2h+sO6SP8UP/jpQ274B+xWCgre1xad8nRELxMwjC10hgRFzfZyQhf55ZV D2Pg== X-Gm-Message-State: AIkVDXIvhlKEw+ax8Rc7J4hkTWPVSVor3tKF/q63clxyvFUBI80CCoA3Qlt+/WH5QMbatw== X-Received: by 10.98.74.142 with SMTP id c14mr4542467pfj.139.1482334564552; Wed, 21 Dec 2016 07:36:04 -0800 (PST) Received: from calancha-pc (177.192.218.133.dy.bbexcite.jp. [133.218.192.177]) by smtp.gmail.com with ESMTPSA id 1sm48292885pgp.1.2016.12.21.07.36.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Dec 2016 07:36:04 -0800 (PST) From: Tino Calancha To: bug-gnu-emacs@gnu.org Subject: 26.0.50; ffap-guesser very slow w/ region active in large diff files Date: Thu, 22 Dec 2016 00:35:59 +0900 Message-ID: <87k2at2t28.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) The slowness is apparent for diff files with > 2 klines. emacs -Q -l ffap ;; From emacs git rep. extract a diff w/ 10 klines. M-! git diff HEAD~200 | head -10000 > /tmp/test-Bug25243 M-: (find-file "/tmp/test-Bug25243") C-x h M-: (ffap-guesser) ;; It took > 2 min in my box. In this example `ffap-guesser' is spending long time testing the whole buffer content as a file name candidate. It might has sense to introduce a maximum limit in the length for file names in `ffap-file-at-point'. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 9e919ba3c86a912bc42cb8e439ad7b8b3660dc37 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Thu, 22 Dec 2016 00:27:50 +0900 Subject: [PATCH] ffap-file-at-point: Limit length of file names Do not spend time checking large strings which are likely not actual file names (Bug#25243). * lisp/ffap.el (ffap-file-name-max-length): New option. (ffap-file-at-point): Use it. ; etc/NEWS: Add entry for the new option. --- etc/NEWS | 4 ++++ lisp/ffap.el | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 7338c0c6a7..fd89568c6e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -312,6 +312,10 @@ the file's actual content before prompting the user. * Changes in Specialized Modes and Packages in Emacs 26.1 +** ffap + +*** A new user option 'ffap-file-name-max-length'. + ** Electric-Buffer-menu +++ diff --git a/lisp/ffap.el b/lisp/ffap.el index 3d7cebadcf..1df30e4516 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -292,6 +292,13 @@ dired-at-point-require-prefix :group 'ffap :version "20.3") +(defcustom ffap-file-name-max-length 1024 + "Maximum length allowed for file names in `ffap-file-at-point'." + :type '(choice (const :tag "Unlimited" nil) + (integer :tag "File Name Max Length" 1024)) + :group 'ffap + :version "26.1") + ;;; Compatibility: ;; @@ -1244,6 +1251,9 @@ ffap-file-at-point (abs (file-name-absolute-p name)) (default-directory default-directory) (oname name)) + ;; When oname is very large is likely not a file name. + (when (or (null ffap-file-name-max-length) + (< (length oname) ffap-file-name-max-length)) (unwind-protect (cond ;; Immediate rejects (/ and // and /* are too common in C/C++): @@ -1334,7 +1344,7 @@ ffap-file-at-point (and (not (string= dir "/")) (ffap-file-exists-string dir)))) ) - (set-match-data data)))) + (set-match-data data))))) ;;; Prompting (`ffap-read-file-or-url'): ;; -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.4) of 2016-12-21 Repository revision: 8661313efd5fd5b0a27fe82f276a1ff862646424 From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 21 11:22:31 2016 Received: (at 25243) by debbugs.gnu.org; 21 Dec 2016 16:22:31 +0000 Received: from localhost ([127.0.0.1]:50418 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJjex-0006ct-6P for submit@debbugs.gnu.org; Wed, 21 Dec 2016 11:22:31 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:25587) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJjev-0006cg-6A for 25243@debbugs.gnu.org; Wed, 21 Dec 2016 11:22:29 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uBLGMLmO023621 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 21 Dec 2016 16:22:22 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id uBLGMLtN008233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 21 Dec 2016 16:22:21 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id uBLGMKFL014169; Wed, 21 Dec 2016 16:22:20 GMT MIME-Version: 1.0 Message-ID: <36cb0896-f437-41f6-92d1-1f8897ff141d@default> Date: Wed, 21 Dec 2016 08:22:19 -0800 (PST) From: Drew Adams To: Tino Calancha , 25243@debbugs.gnu.org Subject: RE: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> In-Reply-To: <87k2at2t28.fsf@gmail.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6753.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-Spam-Score: -5.4 (-----) X-Debbugs-Envelope-To: 25243 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.4 (-----) Amusing backstory: In some of my code I use `ffap-guesser' to pick up file-name defaults for own my version of `read-file-name'. I added that pretty much naively, without digging into the `ffap-guesser' code to check what it does. It seemed to work pretty well. Tino sent me a diff file of about 14 KB, which showed the problem. Other files, even 10 times as large (!), didn't necessarily show the problem. The test case was to use `write-region' in that diff-file buffer, after `C-x h'. (In context, `write-region' invoked my version of `read-file-name'.) Looking closer, I saw that `ffap-guesser' tries to use the text in the active region to guess a file name, and that it passes this text around to multiple functions that examine it, search through it, and massage it (e.g., remove text properties). Needless to say, this is problematic for a large active region. Had the doc string of `ffap-guesser' (and other functions that call it and that it calls) mentioned that it uses the active region, I likely would never have used it as I did. Stefan did add a comment, in Emacs 23, for one call to `ffap-guesser', which is helpful: ;; Don't use the region here, since it can be something ;; completely unwieldy. If the user wants that, she could ;; use M-w before and then C-y. --Stef But it's not just for that occurrence that the problem can exist. And putting that info in a doc string would be more helpful than just in a comment. It's not just a message to Emacs implementers; it's something that users of the ffap functions should know about. Preventing the problem in the first place, as Tino's patch tries to do, is even better than just documenting the gotcha. The ffap.el code does prevent the problem itself for some uses of `ffap-guesser' (e.g. `ffap-prompter'), but it is in `ffap-guesser' itself (or `ffap-file-at-point' or `ffap-string-at-point') that this should be done. Wrt the proposed patch: 1. It is `ffap-string-at-point' that picks up the active region text as a string and removes its properties. Since that is what is slow, I think it is in that function that preventing this from happening should occur. The patch tries to control this only in `ffap-file-at-point', and it does so _after_ calling `ffap-string-at-point', which is too late (AFAICS). I think that `ffap-string-at-point' should control this. It should not try to pick up a file name from a 14 KB diff buffer. 2. I'm not sure that a user option is really what's called for here. I'd suggest a defvar, but only because Emacs Dev does not really like programs to bind option values (I have little problem with that, myself), and that is the main place where I expect the value to be changed: programmatically. Thanks, Tino, for finding this bug and reporting it. From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 21 23:31:39 2016 Received: (at 25243) by debbugs.gnu.org; 22 Dec 2016 04:31:39 +0000 Received: from localhost ([127.0.0.1]:50778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJv2Z-00042m-3T for submit@debbugs.gnu.org; Wed, 21 Dec 2016 23:31:39 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34513) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJv2X-00042X-9A for 25243@debbugs.gnu.org; Wed, 21 Dec 2016 23:31:37 -0500 Received: by mail-pg0-f68.google.com with SMTP id b1so18613123pgc.1 for <25243@debbugs.gnu.org>; Wed, 21 Dec 2016 20:31:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=s6EUWmZnPmMCz5XmDxDFeYWAucuSQZjIwBbBHNxAf1s=; b=jXJ++/gmF7YY+kvVF1td5C/bUhUR1JQKzIyOrQtWP08SHr46Bsc9F5D8Njur5rmrYf RWlgOGYW3Zp7RXSpk/g71ziMAR/0FcVCAGfruj0ebAEpqHv8Gj30RFrTK1teo1tXpa3Z r4MPQSA9olqEppxdkCkhyINN8vZv7NtflGI1zfvcC+urE7U5t/KxV2gXKklc7fPBntHg vEO92Gv1KvcC5bmTargty+eeL6WZ726HX7DEqZaLCEcxeqQdt55aCG9rTpCTSZi3laQW tHXLWsLcN2m9vjNyFH2MaxiAR5i0WJGWpbxFk3i1WSZquIiD2d4oMDWO1HJoQZsIlG4I tD4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=s6EUWmZnPmMCz5XmDxDFeYWAucuSQZjIwBbBHNxAf1s=; b=TGEsWBFwj0a/MgvQRWT20Of7wUj5m+Wz7+vi93qnGOzPA+7qJMxMQy4zSkZ8HC4sV9 /OPS17Y065y3HjaQ3qy7rOAhEbOG0FJESVE1q7PY4/tWOhYVgcVYK6vvBplzzvaW05WM QhqR/bNWZ7YozlOawPiQe9/fatCNUeajlkGHDjU0+vsCoqtgQxwgsYV/eD0UL4xXWv8t cZ0eZw/hKgs3t+rQ4YwOsDwNvkpwhzNxaXWxwNyWORDqI4xu25BpeqaQvHKLcbT0pbwp 4Hr+b/RYXfShIUTmPESYT4/PuwgYSrmKdA5AUDBXZnTvbyyi/Tb1SGjDe3iTQJP8Ch4e EWLw== X-Gm-Message-State: AIkVDXL3mNtx02aufVOlS3IujtBch0N/3TKOLKSSaaHb6VPBJ/IY2Jzyd8cOmrHwjgiadg== X-Received: by 10.98.76.129 with SMTP id e1mr3773617pfj.149.1482381091349; Wed, 21 Dec 2016 20:31:31 -0800 (PST) Received: from calancha-pc (177.192.218.133.dy.bbexcite.jp. [133.218.192.177]) by smtp.gmail.com with ESMTPSA id w11sm50258687pfk.75.2016.12.21.20.31.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Dec 2016 20:31:30 -0800 (PST) From: Tino Calancha To: Drew Adams Subject: Re: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> <36cb0896-f437-41f6-92d1-1f8897ff141d@default> Date: Thu, 22 Dec 2016 13:31:25 +0900 In-Reply-To: <36cb0896-f437-41f6-92d1-1f8897ff141d@default> (Drew Adams's message of "Wed, 21 Dec 2016 08:22:19 -0800 (PST)") Message-ID: <87vauclh42.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 25243 Cc: 25243@debbugs.gnu.org, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Drew Adams writes: > Amusing backstory: Thank you very much for adding more info to the report! > Wrt the proposed patch: > > 1. It is `ffap-string-at-point' that picks up the active > region text as a string and removes its properties. > Since that is what is slow, I think it is in that > function that preventing this from happening should > occur. The patch tries to control this only in > `ffap-file-at-point', and it does so _after_ calling > `ffap-string-at-point', which is too late (AFAICS). > > I think that `ffap-string-at-point' should control > this. It should not try to pick up a file name from > a 14 KB diff buffer. Agreed. See updated patch below. > 2. I'm not sure that a user option is really what's called > for here. I'd suggest a defvar, but only because Emacs > Dev does not really like programs to bind option values > (I have little problem with that, myself), and that is > the main place where I expect the value to be changed: > programmatically. Agreed. It's good to follow an uniform style throughout core packages. I've updated the patch to use a defvar instead. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 46507ea7de34bd54154b9ecb05e607104ef99d67 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Thu, 22 Dec 2016 13:14:22 +0900 Subject: [PATCH] ffap-string-at-point: Limit max length of active region Do not spend time checking large strings which are likely not valid candidates (Bug#25243). * lisp/ffap.el (ffap-max-region-length): New variable. (ffap-string-at-point): Use it. * test/lisp/ffap-tests.el: New test suite. (ffap-tests-25243): Add test for this bug. --- lisp/ffap.el | 17 +++++++++++----- test/lisp/ffap-tests.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 test/lisp/ffap-tests.el diff --git a/lisp/ffap.el b/lisp/ffap.el index 3d7cebadcf..ad4b70d737 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -203,6 +203,9 @@ ffap-foo-at-bar-prefix ) :group 'ffap) +(defvar ffap-max-region-length 1024 + "Maximum allowed region length in `ffap-string-at-point'.") + ;;; Peanut Gallery (More User Variables): ;; @@ -1119,11 +1122,15 @@ ffap-string-at-point (save-excursion (skip-chars-forward (car args)) (skip-chars-backward (nth 2 args) pt) - (point))))) - (setq ffap-string-at-point - (buffer-substring-no-properties - (setcar ffap-string-at-point-region beg) - (setcar (cdr ffap-string-at-point-region) end))))) + (point)))) + (region-len (- (max beg end) (min beg end)))) + (if (or (null ffap-max-region-length) + (< region-len ffap-max-region-length)) ; Bug#25243. + (setf ffap-string-at-point-region (list beg end) + ffap-string-at-point + (buffer-substring-no-properties beg end)) + (setf ffap-string-at-point-region (list 1 1) + ffap-string-at-point "")))) (defun ffap-string-around () ;; Sometimes useful to decide how to treat a string. diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el new file mode 100644 index 0000000000..ca6a1f4d78 --- /dev/null +++ b/test/lisp/ffap-tests.el @@ -0,0 +1,53 @@ +;;; ffap-tests.el --- Test suite for ffap.el -*- lexical-binding: t -*- + +;; Copyright (C) 2016 Free Software Foundation, Inc. + +;; Author: Tino Calancha + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'ffap) + +(ert-deftest ffap-tests-25243 () + "Test for http://debbugs.gnu.org/25243 ." + (let ((file (make-temp-file "test-Bug#25243"))) + (unwind-protect + (with-temp-file file + (let ((str "diff --git b/lisp/ffap.el a/lisp/ffap.el +index 3d7cebadcf..ad4b70d737 100644 +--- b/lisp/ffap.el ++++ a/lisp/ffap.el +@@ -203,6 +203,9 @@ ffap-foo-at-bar-prefix +")) + (transient-mark-mode 1) + (insert + (concat + str + (make-string ffap-max-region-length #xa) + (format "%s ENDS HERE" file))) + (mark-whole-buffer) + (should (equal "" (ffap-string-at-point))) + (should (equal '(1 1) ffap-string-at-point-region)))) + (and (file-exists-p file) (delete-file file))))) + +(provide 'ffap-tests) + +;;; ffap-tests.el ends here -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.4) of 2016-12-22 Repository revision: de0671096706bf7404cddce277b918c8d769f17b From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 22 12:22:50 2016 Received: (at 25243) by debbugs.gnu.org; 22 Dec 2016 17:22:50 +0000 Received: from localhost ([127.0.0.1]:51802 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cK74s-0001oc-It for submit@debbugs.gnu.org; Thu, 22 Dec 2016 12:22:50 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:43664) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cK74q-0001oO-12 for 25243@debbugs.gnu.org; Thu, 22 Dec 2016 12:22:48 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uBMHMe7v026254 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 22 Dec 2016 17:22:41 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id uBMHMejc029546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 22 Dec 2016 17:22:40 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id uBMHMeWw016274; Thu, 22 Dec 2016 17:22:40 GMT MIME-Version: 1.0 Message-ID: Date: Thu, 22 Dec 2016 09:22:38 -0800 (PST) From: Drew Adams To: Tino Calancha Subject: RE: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> <36cb0896-f437-41f6-92d1-1f8897ff141d@default> <87vauclh42.fsf@gmail.com> In-Reply-To: <87vauclh42.fsf@gmail.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6753.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-Spam-Score: -5.4 (-----) X-Debbugs-Envelope-To: 25243 Cc: 25243@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.4 (-----) Thanks for working on this, Tino. Some minor comments below. > +(defvar ffap-max-region-length 1024 > + "Maximum allowed region length in `ffap-string-at-point'.") 1. I think it should say "active region". Very minor (can be ignored): If we say something is not allowed it is unclear what happens. In particular, it can suggest that we raise an error. You might want to say here that if the active region is larger ... it is considered empty. (Or just refer to `ffap-string-at-point', which you do already.)=20 > + (region-len (- (max beg end) (min beg end)))) > + (if (or (null ffap-max-region-length) > + (< region-len ffap-max-region-length)) ; Bug#25243. > + (setf ffap-string-at-point-region (list beg end) > + ffap-string-at-point > + (buffer-substring-no-properties beg end)) > + (setf ffap-string-at-point-region (list 1 1) > + ffap-string-at-point "")))) 1. The doc string should say that if the active region is larger than `ffap-max-region-length' then those two vars are set to ... and .... 2. Instead of testing whether the max-length var is nil, I'd suggest testing it with `natnump', to take care of the unexpected case where it might get assigned a non-number. From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 23 02:12:56 2016 Received: (at 25243) by debbugs.gnu.org; 23 Dec 2016 07:12:56 +0000 Received: from localhost ([127.0.0.1]:52007 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cKK2C-0004b4-9N for submit@debbugs.gnu.org; Fri, 23 Dec 2016 02:12:56 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cKK28-0004ap-MM for 25243@debbugs.gnu.org; Fri, 23 Dec 2016 02:12:54 -0500 Received: by mail-pf0-f195.google.com with SMTP id i88so13488263pfk.2 for <25243@debbugs.gnu.org>; Thu, 22 Dec 2016 23:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=VPv87xwfTXx8kcUNOOB3spLblz8Q29uEGw62pkzTd9g=; b=ESkHFPBXBPyTt61foarRcDNxjlccVisnr6YHvzp175kea9/UjD00saMh50c6NReKRl FH2xmeM3ouxLxFGr3BWxC2wqk1Zofx8tyXI5nwxi16u1M7gKx2Yi+KixUTEM98iU2MEf gEVL+KFugHFmFSh1bmOP/e1PHo9fYaf6qFVgmuvWt1MZW7Cuq4UE6F9F0PwK5CLxAtUM CQ1Bc/wyzmorTpug19thQDDSch/5Omz7s7bBXAa3mpitq2t6Wy5AdCA582IMszLuRDA8 W3MYD+bgOlKn82EfmfwiNKx8ANiCNVjShIc1QWsId05NoG8GMy13K1+C7qmz66VQwP/b 11sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=VPv87xwfTXx8kcUNOOB3spLblz8Q29uEGw62pkzTd9g=; b=a7snwBT5iShWTLPYxs/2Ntah3fKzf3ns/CR8CpKvLU60QohP3KnQh0dwdIXLL/MPw0 kSbQH7sTWYNqtWcv+N5viwHik/2MVIDQIgCrV/BmMc0lmqg3om64F8VD0bubVfM9Mdar +St+s7tOjX0VqzRev1soB2sV1xtvLUN7UtizYFzZDodS2Tpwa3K+zyp2WKvTTNprXB7H WYJFBm/WGDqKvrRhklLhGRm+gqba7wvaWxprw67yEkP8fNCy3sJDbQHOf+ld0s5ci2Bi 9CrX2JyI0T4tIq8aPtcHrxH3e279vRQidQGbBW/DrqoYRkkYHclYGjf9fbtg0RQtzki/ My1g== X-Gm-Message-State: AIkVDXJbAkiIFRG5vT9Otfugs9wngd6q9uIz50zJQR9wmAltppi94YSvTXbQV9aQntb5vQ== X-Received: by 10.99.65.65 with SMTP id o62mr23738288pga.73.1482477166994; Thu, 22 Dec 2016 23:12:46 -0800 (PST) Received: from calancha-pc (177.192.218.133.dy.bbexcite.jp. [133.218.192.177]) by smtp.gmail.com with ESMTPSA id y15sm59830468pgc.43.2016.12.22.23.12.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Dec 2016 23:12:46 -0800 (PST) From: Tino Calancha To: Drew Adams Subject: Re: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> <36cb0896-f437-41f6-92d1-1f8897ff141d@default> <87vauclh42.fsf@gmail.com> Date: Fri, 23 Dec 2016 16:12:41 +0900 In-Reply-To: (Drew Adams's message of "Thu, 22 Dec 2016 09:22:38 -0800 (PST)") Message-ID: <871swzjeza.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 25243 Cc: 25243@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Drew Adams writes: Thanks for the comments! I answer below. >> +(defvar ffap-max-region-length 1024 >> + "Maximum allowed region length in `ffap-string-at-point'.") > > 1. I think it should say "active region". Agreed. > > Very minor (can be ignored): If we say something is not allowed it is > unclear what happens. In particular, it can suggest that we raise an > error. You might want to say here that if the active region is larger > ... it is considered empty. (Or just refer to `ffap-string-at-point', > which you do already.) OK. >> + (region-len (- (max beg end) (min beg end)))) >> + (if (or (null ffap-max-region-length) >> + (< region-len ffap-max-region-length)) ; Bug#25243. >> + (setf ffap-string-at-point-region (list beg end) >> + ffap-string-at-point >> + (buffer-substring-no-properties beg end)) >> + (setf ffap-string-at-point-region (list 1 1) >> + ffap-string-at-point "")))) > > 1. The doc string should say that if the active region is > larger than `ffap-max-region-length' then those two vars > are set to ... and .... I see. I added some text. The var `ffap-string-at-point' gets the returned value of the function with the same name; so it suffices to say that in that case the func. returns "". I also mention that `ffap-string-at-point-region' is set to '(1 1). > 2. Instead of testing whether the max-length var is nil, I'd suggest > testing it with `natnump', to take care of the unexpected case where > it might get assigned a non-number. Yes, `natnump' is a better choice. Following is the updated patch: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/lisp/ffap.el b/lisp/ffap.el index 3d7cebadcf..d91f50e060 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -203,6 +203,11 @@ ffap-foo-at-bar-prefix ) :group 'ffap) +(defvar ffap-max-region-length 1024 + "Maximum active region length. +When the region is active and larger than this value, +`ffap-string-at-point' returns an empty string.") + ;;; Peanut Gallery (More User Variables): ;; @@ -1101,8 +1106,10 @@ ffap-string-at-point string syntax parameters in `ffap-string-at-point-mode-alist'. If MODE is not found, we use `file' instead of MODE. If the region is active, return a string from the region. -Sets the variable `ffap-string-at-point' and the variable -`ffap-string-at-point-region'." +Set the variable `ffap-string-at-point' and the variable +`ffap-string-at-point-region'. +When the region is active and larger than `ffap-max-region-length', +return an empty string, and set `ffap-string-at-point-region' to '(1 1)." (let* ((args (cdr (or (assq (or mode major-mode) ffap-string-at-point-mode-alist) @@ -1119,11 +1126,15 @@ ffap-string-at-point (save-excursion (skip-chars-forward (car args)) (skip-chars-backward (nth 2 args) pt) - (point))))) - (setq ffap-string-at-point - (buffer-substring-no-properties - (setcar ffap-string-at-point-region beg) - (setcar (cdr ffap-string-at-point-region) end))))) + (point)))) + (region-len (- (max beg end) (min beg end)))) + (if (or (not (natnump ffap-max-region-length)) + (< region-len ffap-max-region-length)) ; Bug#25243. + (setf ffap-string-at-point-region (list beg end) + ffap-string-at-point + (buffer-substring-no-properties beg end)) + (setf ffap-string-at-point-region (list 1 1) + ffap-string-at-point "")))) (defun ffap-string-around () ;; Sometimes useful to decide how to treat a string. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.4) of 2016-12-21 Repository revision: 8661313efd5fd5b0a27fe82f276a1ff862646424 From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 23 10:41:15 2016 Received: (at 25243) by debbugs.gnu.org; 23 Dec 2016 15:41:15 +0000 Received: from localhost ([127.0.0.1]:52839 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cKRy7-0001fm-3q for submit@debbugs.gnu.org; Fri, 23 Dec 2016 10:41:15 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:51491) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cKRy5-0001fY-LC for 25243@debbugs.gnu.org; Fri, 23 Dec 2016 10:41:14 -0500 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uBNFf76j024900 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Dec 2016 15:41:07 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id uBNFf6Cg006176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Dec 2016 15:41:07 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id uBNFf5iP010921; Fri, 23 Dec 2016 15:41:05 GMT MIME-Version: 1.0 Message-ID: Date: Fri, 23 Dec 2016 07:41:02 -0800 (PST) From: Drew Adams To: Tino Calancha Subject: RE: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> <36cb0896-f437-41f6-92d1-1f8897ff141d@default> <87vauclh42.fsf@gmail.com> <871swzjeza.fsf@gmail.com> In-Reply-To: <871swzjeza.fsf@gmail.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6753.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-Spam-Score: -5.4 (-----) X-Debbugs-Envelope-To: 25243 Cc: 25243@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.4 (-----) below > > 2. Instead of testing whether the max-length var is nil, I'd suggest > > testing it with `natnump', to take care of the unexpected case where > > it might get assigned a non-number. > Yes, `natnump' is a better choice. > + (if (or (not (natnump ffap-max-region-length)) > + (< region-len ffap-max-region-length)) ; Bug#25243. > + (setf ffap-string-at-point-region (list beg end) > + ffap-string-at-point > + (buffer-substring-no-properties beg end)) > + (setf ffap-string-at-point-region (list 1 1) > + ffap-string-at-point "")))) I'd suggest the other way around. What you have lets someone or some code assign a non-number and get the same slow behavior we want to avoid. I'd say (and (natnump ...) (< region-len ...)). IOW, if it's not a natnump and the size is not smaller than that number then don't use the region. The rest sounds good to me. From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 23 21:53:41 2016 Received: (at 25243) by debbugs.gnu.org; 24 Dec 2016 02:53:41 +0000 Received: from localhost ([127.0.0.1]:53086 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cKcSr-0003bt-3F for submit@debbugs.gnu.org; Fri, 23 Dec 2016 21:53:41 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33265) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cKcSo-0003be-RO for 25243@debbugs.gnu.org; Fri, 23 Dec 2016 21:53:39 -0500 Received: by mail-pg0-f65.google.com with SMTP id g1so2334182pgn.0 for <25243@debbugs.gnu.org>; Fri, 23 Dec 2016 18:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=8x2R4579yOluJuiLq8GOUEirPGDgGV99KbVZkVOTSqs=; b=t+EWlej2pVWRizLD4K7gDqLgGK5Wz1bqQoE25QDF9YpwoXgFbzG6EYmMRf0Kf24OUu GBnY7ULIj8jU1PzBnEytHKlvvuYbYuObDfGedxkStWE2y+Qfg8wcIjmVwt8/Udzvr8sG 0Z36h4rjzi7PptACeQmYRJ2OtqsPRAXvYZ+pZvOe4FZME6CTb21D6KW7z75WUWo1rKqn jwIvVbF9oZGsh8c8Es7RvWqZQg9Y/DY7A0C73KbWTk88Nh3ihODLlGX2Rp0KoNYBmh5X E3ty2M7BKiyhV8z3WErMle80Kth9bQcqF9jibgqA+wgYtiIj4R+r0OyerOiZXJAsEr91 4ZVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=8x2R4579yOluJuiLq8GOUEirPGDgGV99KbVZkVOTSqs=; b=d1v0Yt6zDDkOri5MmE1OX39gfjCMdvEDrMM6yEHjEEbwmGsgvx10JYWzIsYR6R4LWt /IQgepOURs/n+VeyzzGfilnSF1mPG8758renqvm4Uj6AcMLaAhMa7oMnpf6UoswJgarp p1k2+1BuiEYs3NDL/c5IhuHs9uAjgy3da8OyqKPH7JFgEOcD3b9hSYEjmY/yfADISBve HXrHQSZoLhx8utSLwKu3Qiz+nsTmW4+vuFwF9lcqnrBxoP8sKhccc768IQLR9gyYoVaw ATYlX6rKseEazjqAhV42bPN68DdksMWGyMWXT8a0PXuj6cWMLKlqZ68bsAlmb3/64YJ7 ZW3w== X-Gm-Message-State: AIkVDXLi38pw3jVNemeQE3G0LI+ypz+sduWcGOP9ZVzDomsBO/lOoxwA9Siv77Ar3PF+yA== X-Received: by 10.84.211.7 with SMTP id b7mr34975841pli.83.1482548013020; Fri, 23 Dec 2016 18:53:33 -0800 (PST) Received: from calancha-pc (177.192.218.133.dy.bbexcite.jp. [133.218.192.177]) by smtp.gmail.com with ESMTPSA id 1sm65619303pgp.1.2016.12.23.18.53.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Dec 2016 18:53:32 -0800 (PST) From: Tino Calancha To: Drew Adams Subject: Re: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> <36cb0896-f437-41f6-92d1-1f8897ff141d@default> <87vauclh42.fsf@gmail.com> <871swzjeza.fsf@gmail.com> Date: Sat, 24 Dec 2016 11:53:27 +0900 In-Reply-To: (Drew Adams's message of "Fri, 23 Dec 2016 07:41:02 -0800 (PST)") Message-ID: <87k2aqdom0.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 25243 Cc: 25243@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Drew Adams writes: > below > >> > 2. Instead of testing whether the max-length var is nil, I'd suggest >> > testing it with `natnump', to take care of the unexpected case where >> > it might get assigned a non-number. >> Yes, `natnump' is a better choice. > >> + (if (or (not (natnump ffap-max-region-length)) >> + (< region-len ffap-max-region-length)) ; Bug#25243. >> + (setf ffap-string-at-point-region (list beg end) >> + ffap-string-at-point >> + (buffer-substring-no-properties beg end)) >> + (setf ffap-string-at-point-region (list 1 1) >> + ffap-string-at-point "")))) > > I'd suggest the other way around. What you have lets someone or > some code assign a non-number and get the same slow behavior we > want to avoid. I'd say (and (natnump ...) (< region-len ...)). > > IOW, if it's not a natnump and the size is not smaller than that > number then don't use the region. It sounds reasonable. Thank you. If i don't see further comments in a few days i will push the following patch to the master branch: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 7e8268b975c8385015769755e8ba1e9854d64da1 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sat, 24 Dec 2016 11:31:53 +0900 Subject: [PATCH] ffap-string-at-point: Limit max length of active region Do not spend time checking large strings which are likely not valid candidates (Bug#25243). * lisp/ffap.el (ffap-max-region-length): New variable. (ffap-string-at-point): Use it. * test/lisp/ffap-tests.el: New test suite. (ffap-tests-25243): Add test for this bug. --- lisp/ffap.el | 25 ++++++++++++++++------- test/lisp/ffap-tests.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 test/lisp/ffap-tests.el diff --git a/lisp/ffap.el b/lisp/ffap.el index 3d7cebadcf..99bb65faaf 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -203,6 +203,11 @@ ffap-foo-at-bar-prefix ) :group 'ffap) +(defvar ffap-max-region-length 1024 + "Maximum active region length. +When the region is active and larger than this value, +`ffap-string-at-point' returns an empty string.") + ;;; Peanut Gallery (More User Variables): ;; @@ -1101,8 +1106,10 @@ ffap-string-at-point string syntax parameters in `ffap-string-at-point-mode-alist'. If MODE is not found, we use `file' instead of MODE. If the region is active, return a string from the region. -Sets the variable `ffap-string-at-point' and the variable -`ffap-string-at-point-region'." +Set the variable `ffap-string-at-point' and the variable +`ffap-string-at-point-region'. +When the region is active and larger than `ffap-max-region-length', +return an empty string, and set `ffap-string-at-point-region' to '(1 1)." (let* ((args (cdr (or (assq (or mode major-mode) ffap-string-at-point-mode-alist) @@ -1119,11 +1126,15 @@ ffap-string-at-point (save-excursion (skip-chars-forward (car args)) (skip-chars-backward (nth 2 args) pt) - (point))))) - (setq ffap-string-at-point - (buffer-substring-no-properties - (setcar ffap-string-at-point-region beg) - (setcar (cdr ffap-string-at-point-region) end))))) + (point)))) + (region-len (- (max beg end) (min beg end)))) + (if (and (natnump ffap-max-region-length) + (< region-len ffap-max-region-length)) ; Bug#25243. + (setf ffap-string-at-point-region (list beg end) + ffap-string-at-point + (buffer-substring-no-properties beg end)) + (setf ffap-string-at-point-region (list 1 1) + ffap-string-at-point "")))) (defun ffap-string-around () ;; Sometimes useful to decide how to treat a string. diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el new file mode 100644 index 0000000000..61fa891fe7 --- /dev/null +++ b/test/lisp/ffap-tests.el @@ -0,0 +1,54 @@ +;;; ffap-tests.el --- Test suite for ffap.el -*- lexical-binding: t -*- + +;; Copyright (C) 2016 Free Software Foundation, Inc. + +;; Author: Tino Calancha + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'ffap) + +(ert-deftest ffap-tests-25243 () + "Test for http://debbugs.gnu.org/25243 ." + (let ((file (make-temp-file "test-Bug#25243"))) + (unwind-protect + (with-temp-file file + (let ((str "diff --git b/lisp/ffap.el a/lisp/ffap.el +index 3d7cebadcf..ad4b70d737 100644 +--- b/lisp/ffap.el ++++ a/lisp/ffap.el +@@ -203,6 +203,9 @@ ffap-foo-at-bar-prefix +")) + (transient-mark-mode 1) + (when (natnump ffap-max-region-length) + (insert + (concat + str + (make-string ffap-max-region-length #xa) + (format "%s ENDS HERE" file))) + (mark-whole-buffer) + (should (equal "" (ffap-string-at-point))) + (should (equal '(1 1) ffap-string-at-point-region))))) + (and (file-exists-p file) (delete-file file))))) + +(provide 'ffap-tests) + +;;; ffap-tests.el ends here -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.5) of 2016-12-23 Repository revision: eff901b8a39f42ddedf4c1db833b9071cae5962f From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 30 01:41:32 2016 Received: (at 25243-done) by debbugs.gnu.org; 30 Dec 2016 06:41:32 +0000 Received: from localhost ([127.0.0.1]:59514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cMqse-0005So-Hs for submit@debbugs.gnu.org; Fri, 30 Dec 2016 01:41:32 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cMqsd-0005Sb-Ak for 25243-done@debbugs.gnu.org; Fri, 30 Dec 2016 01:41:31 -0500 Received: by mail-pg0-f68.google.com with SMTP id b1so21167078pgc.1 for <25243-done@debbugs.gnu.org>; Thu, 29 Dec 2016 22:41:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=Z+uDiUAYunAJjk4Iqjm73ksyw0vR3mbIaMTftxAx+zE=; b=tOXU4YH2bZRoN349dDOWgfQ1snQj0iJVPCqSxrqO7DaOtisZwMyXVa3rB8IyHbdsch hhaNpcII8huqh+GBVoxEufsy6/QeHOU5KYJq9tPlRsrdCs2/dibS21CbExTPxfx6+4iA Smo0+18XXKQDwV9Xif2QbHFhy8OFubDPVqMJ04bXJ9Rm2GH1F5ElQZSQvo1uQK241ABh YaXixhKAAY0LUY2hQcI11KQUOjSB63lzMLg791q5C6l1vGbXn2y5EgnOCj8TJHtvdDZl wIILLpmaycBRWoCxRd8lwtj/ihexNZk/v0lU4SC8180+OXM4tPXHSaBMCB3IQ2AEFq4w YLPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Z+uDiUAYunAJjk4Iqjm73ksyw0vR3mbIaMTftxAx+zE=; b=N1g35sHBL9KejN8FTK92kQVpe/7j7O3aAXeOVwI4TFXUJxHbjNm9sLz1GfeJAHpW7S 2RXTaZgg4Kv78EBW4gchIhV3yfYw5bIqbGqLparrn9tCASd1VFXs3oqySYXhv8KS/GpO E1hCTx6rQ4ctjwo3UaKm2bHFK0EVk+movt5u+GiRsIryQaXsIk4dKbGg0Kp92sxkwOtl DO5sDVQCzGCvbG4zqC0irVedMIQJ0f2HGbG0Gm9BjxtGWcOnRac0Qof7yR4Y9ys8S/zJ U+zUQYs8uMVpBRmb5NCSNJYcC2EiuRE0Qvv76e1zL3xUAbAqITGCaNeATCjGIuXtsaXQ y2Jw== X-Gm-Message-State: AIkVDXJk5Cck/wCATRSMOMLZiHPi+Py4QwCJNt2CEH5nxAsNAmeS8bVQyhA2z1stnsiVPw== X-Received: by 10.99.168.69 with SMTP id i5mr83989186pgp.10.1483080085251; Thu, 29 Dec 2016 22:41:25 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id c2sm109390208pfl.66.2016.12.29.22.41.23 for <25243-done@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Dec 2016 22:41:24 -0800 (PST) From: Tino Calancha To: 25243-done@debbugs.gnu.org Subject: Re: bug#25243: 26.0.50; ffap-guesser very slow w/ region active in large diff files References: <87k2at2t28.fsf@gmail.com> <36cb0896-f437-41f6-92d1-1f8897ff141d@default> <87vauclh42.fsf@gmail.com> <871swzjeza.fsf@gmail.com> <87k2aqdom0.fsf@gmail.com> Date: Fri, 30 Dec 2016 15:41:20 +0900 In-Reply-To: <87k2aqdom0.fsf@gmail.com> (Tino Calancha's message of "Sat, 24 Dec 2016 11:53:27 +0900") Message-ID: <871swphqb3.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 25243-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Tino Calancha writes: > If i don't see further comments in a few days i will push > the following patch to the master branch: Pushed fix into master branch as commit c336420d9f From unknown Sat Jun 21 03:04:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 27 Jan 2017 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator