help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `looking-back' strange warning


From: Andreas Röhler
Subject: Re: `looking-back' strange warning
Date: Sat, 03 Oct 2015 08:45:48 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0


Am 03.10.2015 um 08:26 schrieb Tassilo Horn:
Drew Adams <drew.adams@oracle.com> writes:

This version is about 6 times faster in the t case and a still a bit
faster in the nil case where the char before point is already different
(which is the best case for your function).

(defun chars-before (chars)
   "Return non-nil if the literal string CHARS is right before point.
This is more efficient that `looking-back' for this use case."
   (let ((beg (- (point) (length chars))))
     (unless (< beg 0)
       (save-excursion
          (goto-char beg)
          (looking-at (regexp-quote chars))))))
OK.  Good to know.

See also bug #17284,
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17284,
where this has been discussed and I and others proposed
code for this.
Martin's version is faster than mine, so no need to propose it.

You are welcome to contribute to that (short) bug thread,
or to otherwise try to get such a function added to Emacs.
I think that function is not really a viable drop-in replacement for
typical `looking-back' calls.  The latter is most frequently used to
decide "am I behind some word or sequence of words, and I don't care
about whitespace?".

Bye,
Tassilo


Just for fun:

(defun looking-back-string (string)
  "Return non-nil if the literal STRING is right before point.
This is more efficient that `looking-back' for this use case."
(string= string (ignore-errors (buffer-substring-no-properties (- (point) (length string)) (point)))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]