From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Roehler Newsgroups: gmane.emacs.help Subject: Re: empty-line-p Date: Fri, 06 Apr 2007 16:44:53 +0200 Message-ID: <46165CE5.9090904@easy-emacs.de> References: <877iszcdoj.fsf@localhorst.mine.nu> <460DF657.40201@easy-emacs.de> <200703311517.l2VFHHFN021493@localhost.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1175871821 8917 80.91.229.12 (6 Apr 2007 15:03:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 6 Apr 2007 15:03:41 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, David Hansen , Barry Margolin , Stefan Monnier , Joost Kremers To: Xavier Maillard Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 06 17:02:52 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HZpg8-0007hb-GW for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Apr 2007 16:44:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HZpjc-0007HD-Pq for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Apr 2007 10:48:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HZpjQ-0007Gw-IN for help-gnu-emacs@gnu.org; Fri, 06 Apr 2007 10:48:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HZpjP-0007GU-97 for help-gnu-emacs@gnu.org; Fri, 06 Apr 2007 10:48:04 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HZpjP-0007GP-33 for help-gnu-emacs@gnu.org; Fri, 06 Apr 2007 10:48:03 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.177]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HZpft-0005Ca-AN; Fri, 06 Apr 2007 10:44:25 -0400 Original-Received: from [84.190.185.32] (helo=[192.168.178.25]) by mrelayeu.kundenserver.de (node=mrelayeu2) with ESMTP (Nemesis), id 0MKwtQ-1HZpfT0LT5-0004nD; Fri, 06 Apr 2007 16:44:01 +0200 User-Agent: Thunderbird 1.5.0.4 (X11/20060516) In-Reply-To: <200703311517.l2VFHHFN021493@localhost.localdomain> X-Provags-ID: V01U2FsdGVkX1/3FqBeojMj/IzsBHUAkV67hfyKqig+/giGZVo Xs1heVOdB2luk3fBgYm2Zfj3TNq2mRQgPuoLCdTli1+BnY+keK E0YR/D2TDYX/hQHv9HAaA== X-detected-kernel: Linux 2.6? (barebone, rare!) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42459 Archived-At: Xavier Maillard schrieb: > > wrap it in a `save-match-data'. > > > > David > > > > OK, thanks. So I got this now: > > Here is what I would do instead: > > (defun empty-line-p (&optional ispec) > "Returns t if cursor is at an empty line, nil otherwise. > Displays result in minibuffer when called interactive." > (interactive "p") > (save-excursion > (beginning-of-line) > (save-match-data > (let ((res (looking-at empty-line-p-chars))) > (or (and ispec > (message "%s" res)) > res))))) > > > Xavier > That would probably work, however, as far as the form is conceived as a subroutine, it doesn't seem the best solution. Assume you introduced `let', because in (when ispec (message "%s" (looking-at empty-line-p-chars))) (looking-at empty-line-p-chars)))) `looking-at' is performed two times. Thought that repeat won't matter, because when called interactively, time isn't at stake. Otherwise `let' would maybe called again and again from inside a program, whereas `let' isn't really needed here. Meanwhile thought to reconcile `save-match-data' proposed by David Hansen with Stefan Monnier's objections concerning speed. The form below should `save-match-data', when called as (empty-line-p t) and without arg not. (defun empty-line-p (&optional arg ispec) "Returns t if cursor is at an empty line, nil otherwise. Displays result in minibuffer when called interactive." (interactive "P\np") (save-excursion (beginning-of-line) (if arg (save-match-data (if ispec (message "%s" (looking-at empty-line-p-chars)) (looking-at empty-line-p-chars))) (if ispec (message "%s" (looking-at empty-line-p-chars)) (looking-at empty-line-p-chars))))) (defcustom empty-line-p-chars "^[ \t\f\r]*$" "empty-line-p-chars" :type 'regexp :group 'convenience) Thanks all Andreas Roehler