From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: npostavs@gmail.com
Cc: 35708@debbugs.gnu.org
Subject: bug#35708: [27.0.50]: thingatpt.el, thing-at-point-looking-at redundant
Date: Wed, 15 May 2019 12:11:05 +0200 [thread overview]
Message-ID: <a369b03c-a16b-a841-a37a-8940ea8fdd1f@easy-emacs.de> (raw)
In-Reply-To: <6bf2ad95-5a41-cbf1-c5ea-07dc06d0f9a1@easy-emacs.de>
[-- Attachment #1: Type: text/plain, Size: 2755 bytes --]
Am 15.05.19 um 08:59 schrieb Andreas Röhler:
>
> Am 14.05.19 um 16:34 schrieb npostavs@gmail.com:
>> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>>
>>>> Hmm, current thing-at-point-looking-at might be slow with large
>>>> buffers. The slightly modified test should reveal it:
>>>>
>>>> (ert-deftest thing-at-point-looking-at-2 ()
>>>> (with-temp-buffer
>>>> (insert "1abcd 222abcd")
>>>> (dotimes (_ 99999) (insert " asdf "))
>>>> (goto-char (point-min))
>>>> (search-forward "2ab")
>>>> (should (thing-at-point-looking-at "2abcd"))
>> Yes, in this case, since the loop over looking-at only needs to iterate
>> twice, so it will be faster. But what about when there is no match?
>> E.g.,
>>
>> (with-temp-buffer
>> (dotimes (_ 99999) (insert " asdf "))
>> (goto-char (point-max))
>> (list :ar-regexp-atpt (benchmark-run (ar-regexp-atpt "foo"))
>> :thing-at-point-looking-at (benchmark-run
>> (thing-at-point-looking-at "foo"))))
>>
>>> Another fix, as a bug showed up when testing (ar-regexp-atpt "[a-z]+"):
>>>
>>> (defun ar-regexp-atpt (regexp)
>>> "Return t if REGEXP matches at or before point, nil otherwise.
>>>
>>> Changes match-data"
>>> (save-excursion
>>> (if (looking-at regexp)
>>> (while
>>> (and (not (bobp))
>>> (or (progn (backward-char) (looking-at regexp))
>>> (forward-char 1))))
>>> (while (not (or (bobp) (backward-char) (looking-at regexp))))
>>> (ar-regexp-atpt regexp))
>> What's this recursive call for? It triggers (error "Lisp nesting
>> exceeds ‘max-lisp-eval-depth’") in the benchmark above.
>>
>>> (looking-at regexp)))
>
>
> The recursive call needed a guard: (unless (bobp)
>
> It is called after function went backward while not looking-at matches,
>
> Now the result for the 99999 is
>
> (:ar-regexp-atpt (0.774574453 0 0.0) :thing-at-point-looking-at
> (0.000798669 0 0.0))
>
>
> The fixed form:
>
>
Make sure match pos includes cursor pos:
(defun ar-regexp-atpt (regexp)
"Return t if REGEXP matches at or before point, nil otherwise.
Changes match-data"
(save-excursion
(let ((orig (point)))
(if (looking-at regexp)
(while
(and (not (bobp))
(or (progn (backward-char) (looking-at regexp))
(forward-char 1))))
(while (not (or (bobp) (backward-char) (looking-at regexp))))
(unless (bobp) (ar-regexp-atpt regexp)))
(and
(looking-at regexp)
(<= (match-beginning 0) orig)
(>= (match-end 0) orig)))))
[-- Attachment #2: Type: text/html, Size: 4943 bytes --]
next prev parent reply other threads:[~2019-05-15 10:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 7:19 bug#35708: [27.0.50]: thingatpt.el, thing-at-point-looking-at redundant Andreas Röhler
2019-05-13 12:41 ` Noam Postavsky
2019-05-13 18:31 ` Andreas Röhler
2019-05-13 19:25 ` npostavs
2019-05-14 10:02 ` Andreas Röhler
2019-05-14 10:49 ` Andreas Röhler
2019-05-14 14:34 ` npostavs
2019-05-15 6:59 ` Andreas Röhler
2019-05-15 10:11 ` Andreas Röhler [this message]
2019-05-20 17:17 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a369b03c-a16b-a841-a37a-8940ea8fdd1f@easy-emacs.de \
--to=andreas.roehler@easy-emacs.de \
--cc=35708@debbugs.gnu.org \
--cc=npostavs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.