From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: `looking-back' strange warning Date: Fri, 2 Oct 2015 13:28:15 -0700 (PDT) Message-ID: <190e27a5-9099-45ce-a8db-a314b9e32b35@default> References: <560B9C7F.2060301@easy-emacs.de> <560CD7CE.4010404@yandex.ru> <6524c81a-949c-40d1-b990-d214d6ee5b60@default> <560D73DF.8040403@yandex.ru> <560D7A68.8040404@easy-emacs.de> <560D8289.6010409@yandex.ru> <560D8F96.5040200@easy-emacs.de> <877fn66pag.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1443818540 20087 80.91.229.3 (2 Oct 2015 20:42:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 2 Oct 2015 20:42:20 +0000 (UTC) To: Michael Heerdegen , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 02 22:42:07 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zi79Y-0007J2-Nn for geh-help-gnu-emacs@m.gmane.org; Fri, 02 Oct 2015 22:42:04 +0200 Original-Received: from localhost ([::1]:35048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi79Y-0000ai-0b for geh-help-gnu-emacs@m.gmane.org; Fri, 02 Oct 2015 16:42:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi6wI-0002EL-SX for help-gnu-emacs@gnu.org; Fri, 02 Oct 2015 16:28:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi6wF-00010t-NK for help-gnu-emacs@gnu.org; Fri, 02 Oct 2015 16:28:22 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:37372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi6wF-0000zx-Gt for help-gnu-emacs@gnu.org; Fri, 02 Oct 2015 16:28:19 -0400 Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t92KSHba027178 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 2 Oct 2015 20:28:18 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t92KSHdZ006711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 2 Oct 2015 20:28:17 GMT Original-Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t92KSGRS024822; Fri, 2 Oct 2015 20:28:16 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9 (901082) [OL 12.0.6691.5000 (x86)] X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:107485 Archived-At: > > My two cents: Even if you specify an optimal limit, `looking-back' can > > still be unnecessarily slow. For example, > > (looking-back "xy" 2) > > is much slower than > > (and (> (point) 2) > > (save-excursion (goto-char (- (point) 2)) > > (looking-at "xy"))) > > where "xy" stands for any plain string. >=20 > Definitely. And this is in fact a typical case of the > misuse: the string to check is often a literal, so its > length is known. >=20 > This is the first thing to mention about `looking-back', > in terms of performance: avoid it altogether, if you can. BTW/FWIW - I use this function in such cases, which can be pretty common: (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* ((len (length chars)) (idx (1- len)) (pt (point))) (catch 'chars-before (dolist (char (append chars ())) (unless (condition-case nil (eq char (char-before (- pt idx))) (error nil)) ; e.g. `bobp' (throw 'chars-before nil)) (setq idx (1- idx))) t))) http://www.emacswiki.org/emacs/download/misc-fns.el