GNU bug report logs - #35708
[27.0.50]: thingatpt.el, thing-at-point-looking-at redundant

Previous Next

Package: emacs;

Reported by: Andreas Röhler <andreas.roehler <at> easy-emacs.de>

Date: Mon, 13 May 2019 07:19:01 UTC

Severity: wishlist

Tags: notabug, wontfix

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #17 received at 35708 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: npostavs <at> gmail.com
Cc: 35708 <at> debbugs.gnu.org
Subject: Re: bug#35708: [27.0.50]: thingatpt.el, thing-at-point-looking-at
 redundant
Date: Tue, 14 May 2019 12:02:15 +0200
On 13.05.19 21:25, npostavs <at> gmail.com wrote:
> Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
>
>> Thought at something like below, which should pass the test:
>>
>> (defun ar-thing-at-point-looking-at (regexp)
>>    "Return t if regexp matches at or before point, nil otherwise."
>>    (save-excursion
>>        (while (not (or (looking-at regexp)(bolp)))
>>        (forward-char -1))
>>        (looking-at regexp)))
> I think it's an optimization to use re-search-backward instead of moving
> on character at a time and calling looking-at in lisp.
>
>

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))
    (let ((m2 (progn (search-forward "2abcd")
                     (match-data))))
      (goto-char (point-min))
      (search-forward "2ab")
      (should (thing-at-point-looking-at "2abcd"))
      (should (equal (match-data) m2)))))

But let me correct the alternative delivered, as it didn't match before 
point:

(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
        (save-excursion
          (and (not (bobp))
           (progn (backward-char) (looking-at regexp)))))
      (while (not (or (bobp) (backward-char) (looking-at regexp))))
      (ar-regexp-atpt regexp))
    (looking-at regexp)))





This bug report was last modified 5 years and 362 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.