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: Sat, 31 Mar 2007 07:49:11 +0200 Message-ID: <460DF657.40201@easy-emacs.de> References: <877iszcdoj.fsf@localhorst.mine.nu> 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 1175323703 20030 80.91.229.12 (31 Mar 2007 06:48:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 31 Mar 2007 06:48:23 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: David Hansen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 31 08:48:17 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 1HXXNn-0000uJ-RZ for geh-help-gnu-emacs@m.gmane.org; Sat, 31 Mar 2007 08:48:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HXXQY-0000u0-Tl for geh-help-gnu-emacs@m.gmane.org; Sat, 31 Mar 2007 01:51:06 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HXXQK-0000mp-9y for help-gnu-emacs@gnu.org; Sat, 31 Mar 2007 02:50:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HXXQI-0000k3-Oi for help-gnu-emacs@gnu.org; Sat, 31 Mar 2007 02:50:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HXXQI-0000ju-L7 for help-gnu-emacs@gnu.org; Sat, 31 Mar 2007 01:50:50 -0500 Original-Received: from moutng.kundenserver.de ([212.227.126.177]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HXXNU-0001Ea-IR for help-gnu-emacs@gnu.org; Sat, 31 Mar 2007 02:47:57 -0400 Original-Received: from [84.190.128.121] (helo=[192.168.178.25]) by mrelayeu.kundenserver.de (node=mrelayeu1) with ESMTP (Nemesis), id 0MKwpI-1HXXNM37Z9-0004nZ; Sat, 31 Mar 2007 08:47:49 +0200 User-Agent: Thunderbird 1.5.0.4 (X11/20060516) In-Reply-To: <877iszcdoj.fsf@localhorst.mine.nu> X-Provags-ID: V01U2FsdGVkX199V8OPa4KmFOfMg/eNPuJi/tiyvbJEwEq29/w hYp3Bxex7w5PFwB8g4k7/ZuqBm23VpAXG5NcI4HHoEoNUwJBgG vFiY08hnaH+q62S3OJdvw== 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:42316 Archived-At: David Hansen schrieb: > On 29 Mar 2007 14:32:05 GMT Joost Kremers wrote: > > >> Andreas Roehler wrote: >> >>> needed a check at several occassions, if the current line >>> contains printable characters. >>> >>> What about the following to solve this? >>> >>> (defun empty-line-p () >>> "Returns t if cursor is at an empty line " >>> (interactive) >>> (save-excursion >>> (beginning-of-line) >>> (if >>> (looking-at "^[ \t\f\r]*$") >>> t >>> nil))) >>> >> you don't need the if-statement here: >> >> (defun empty-line-p () >> "Returns t if cursor is at an empty line " >> (interactive) >> (save-excursion >> (beginning-of-line) >> (looking-at "^[ \t\f\r]*$"))) >> >> looking-at already returns t or nil. >> > > And to avoid some painful bug hunting (happened to me with nearly > the same code) What about to collect minor tools like this somewhere? > wrap it in a `save-match-data'. > > David > OK, thanks. So I got this now: (defcustom empty-line-p-chars "^[ \t\f\r]*$" "empty-line-p-chars" :type 'regexp :group 'convenience) (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 (when ispec (message "%s" (looking-at empty-line-p-chars))) (looking-at empty-line-p-chars)))) ;;;;; Andreas