Make sure match pos includes cursor pos:
Am 14.05.19 um 16:34 schrieb npostavs@gmail.com:
Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
Yes, in this case, since the loop over looking-at only needs to iterateHmm, 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"))
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]+"):What's this recursive call for? It triggers (error "Lisp nesting
(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))
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:
(defun ar-regexp-atpt (regexp)
"Return t if REGEXP matches at or before point, nil otherwise.