From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Hansen Newsgroups: gmane.emacs.help Subject: Re: empty-line-p Date: Fri, 30 Mar 2007 10:56:28 +0200 Organization: disorganized Message-ID: <877iszcdoj.fsf@localhorst.mine.nu> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1175311172 11692 80.91.229.12 (31 Mar 2007 03:19:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 31 Mar 2007 03:19:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 30 23:08:36 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 1HXOKq-0001rx-6y for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Mar 2007 23:08:36 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HXONZ-0007gz-Bb for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Mar 2007 16:11:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HXONN-0007gC-6s for help-gnu-emacs@gnu.org; Fri, 30 Mar 2007 17:11:13 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HXONL-0007fl-JP for help-gnu-emacs@gnu.org; Fri, 30 Mar 2007 17:11:12 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HXONL-0007fg-93 for help-gnu-emacs@gnu.org; Fri, 30 Mar 2007 16:11:11 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HXOKb-0004dP-AG for help-gnu-emacs@gnu.org; Fri, 30 Mar 2007 17:08:21 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HXOKY-0006KC-Jb for help-gnu-emacs@gnu.org; Fri, 30 Mar 2007 23:08:18 +0200 Original-Received: from e178039027.adsl.alicedsl.de ([85.178.39.27]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 Mar 2007 23:08:18 +0200 Original-Received: from david.hansen by e178039027.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 Mar 2007 23:08:18 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 33 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: e178039027.adsl.alicedsl.de Mail-Copies-To: nobody User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) Cancel-Lock: sha1:E370aYdjOhO3376G1mqUaEA9wsw= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) 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:42315 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) wrap it in a `save-match-data'. David