Subject: Re: bug#17284: Host name completion in shell mode take 45 seconds

From: martin rudalics <[email-masked]>
Date: Sat, 04 Apr 2015 10:29:52 +0200

> 1. Is it really about LIMIT?  Or is it instead about looking back
 >     at a literal string of chars?  And typically a short string.
 >     I'm guessing that that is the use case to pursue here.

Right.

 > 2. Instead of (or in addition to) a byte-compiler warning for
 >     `looking-back', how about adding a function `chars-before'?

This would be useful.

 > Since I use multiple Emacs versions, some quite old, I use this.
 > But I'm sure that a much better (including prettier) definition
 > can be had for recent Emacs.  Or (better) define it in C.

I guess something like

(defun string-before-p (string)
   "Return t if string before `point' equals STRING."
   (let ((start (- (point) (length string))))
     (and (>= start (point-min))
	 (string-equal
	  (buffer-substring-no-properties start (point))
	  string))))

would do.  And for simpler cases giving `char-before' a second argument
to specify the position of the character before `point' might help too.

But many occurrences of `looking-back' in the code base are inherently
tied to regexps specified via defcustoms or passed as arguments and it
doesn't seem easy to get rid of them.  Hence we should probably add a
TODO item to fix all occurrences of `looking-back' either via the LIMIT
argument, by string or character comparison.  An appetizing formulation
of such an item would be very welcome.

martin