all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Roehler <andreas.roehler@easy-emacs.de>
To: David Hansen <david.hansen@gmx.net>
Cc: help-gnu-emacs@gnu.org
Subject: Re: empty-line-p
Date: Sat, 31 Mar 2007 07:49:11 +0200	[thread overview]
Message-ID: <460DF657.40201@easy-emacs.de> (raw)
In-Reply-To: <877iszcdoj.fsf@localhorst.mine.nu>

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

  reply	other threads:[~2007-03-31  5:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1577.1175177310.7795.help-gnu-emacs@gnu.org>
2007-03-29 14:32 ` empty-line-p Joost Kremers
2007-03-30  8:56   ` empty-line-p David Hansen
2007-03-31  5:49     ` Andreas Roehler [this message]
2007-03-31 15:17       ` empty-line-p Xavier Maillard
2007-04-06 14:44         ` empty-line-p Andreas Roehler
     [not found]   ` <mailman.1621.1175289074.7795.help-gnu-emacs@gnu.org>
2007-04-01 20:57     ` empty-line-p Stefan Monnier
2007-03-30  5:36 ` empty-line-p Stefan Monnier
2007-03-30  5:46   ` empty-line-p Barry Margolin
2007-04-01 20:54     ` empty-line-p Stefan Monnier
2007-03-30  6:14   ` empty-line-p Andreas Roehler
2007-03-29 13:06 empty-line-p Andreas Roehler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=460DF657.40201@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --cc=david.hansen@gmx.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.