From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Possible problem with looking-back function Date: Fri, 20 Aug 2010 15:07:21 +0200 Message-ID: References: <4C6C85AD.1010500@ig.com.br> <49933.130.55.132.107.1282185810.squirrel@webmail.lanl.gov> <4C6DE451.5080706@ig.com.br> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1282309654 14474 80.91.229.12 (20 Aug 2010 13:07:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 20 Aug 2010 13:07:34 +0000 (UTC) Cc: GNU Emacs To: Vinicius Jose Latorre Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 20 15:07:32 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OmRJj-0007v9-Br for ged-emacs-devel@m.gmane.org; Fri, 20 Aug 2010 15:07:31 +0200 Original-Received: from localhost ([127.0.0.1]:44677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OmRJi-0003Ah-Az for ged-emacs-devel@m.gmane.org; Fri, 20 Aug 2010 09:07:30 -0400 Original-Received: from [140.186.70.92] (port=55610 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OmRJc-0003Ac-Sz for emacs-devel@gnu.org; Fri, 20 Aug 2010 09:07:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OmRJb-0006gP-P8 for emacs-devel@gnu.org; Fri, 20 Aug 2010 09:07:24 -0400 Original-Received: from impaqm4.telefonica.net ([213.4.138.4]:51658) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OmRJb-0006gJ-Il for emacs-devel@gnu.org; Fri, 20 Aug 2010 09:07:23 -0400 Original-Received: from IMPmailhost6.adm.correo ([10.20.102.127]) by IMPaqm4.telefonica.net with bizsmtp id wYXD1e00p2kvMAa3Qd7Nt2; Fri, 20 Aug 2010 15:07:22 +0200 Original-Received: from ceviche.home ([83.61.35.93]) by IMPmailhost6.adm.correo with BIZ IMP id wd7M1e00620aCvn1md7NSM; Fri, 20 Aug 2010 15:07:22 +0200 X-Brightmail-Tracker: AAAAAA== X-TE-authinfo: authemail="monnier$movistar.es" |auth_email="monnier@movistar.es" X-TE-AcuTerraCos: auth_cuTerraCos="cosuitnetc01" Original-Received: by ceviche.home (Postfix, from userid 20848) id 9196E660E9; Fri, 20 Aug 2010 15:07:21 +0200 (CEST) In-Reply-To: <4C6DE451.5080706@ig.com.br> (Vinicius Jose Latorre's message of "Thu, 19 Aug 2010 23:11:29 -0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:128920 Archived-At: > Ok, so looking-back should be replaced by: > (progn > (goto-char 11) ; go to end of buffer > ;; ---- looking-back replacement --- BEGIN > (save-excursion > (when (/= 0 (skip-chars-backward " \t\n" 1)) > (unless (bolp) > (forward-line 1)) > (looking-at "^\\([ \t\n]+\\)"))) > ;; ---- looking-back replacement --- END > (match-beginning 1)) > Now it returns 1. Or you can still use a regexp, with something like (defun other-looking-back (re limit) (save-restriction (narrow-to-region (point-min) (point)) (goto-char limit) (re-search-forward (concat "\\(?:" re "\\)\\'") nil t))) Note that it imposes a few different constraints on the regexp, mostly it can't use things like \> or \< or \b at the end because narrow-to-region will prevent it from peeking at the next char. Stefan