unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jesper Harder <harder@myrealbox.com>
Subject: Re: Lisp hints with VM, BBDB and Personality Crisis
Date: Mon, 15 Sep 2003 04:28:26 +0200	[thread overview]
Message-ID: <m3znh6iy45.fsf@defun.localdomain> (raw)
In-Reply-To: 87znh7aue5.fsf@dell.i-did-not-set--mail-host-address--so-shoot-me

spam@juliva.com writes:


> I am not an expert in elisp and I was wondering if there is a way to
> shorten the code? Especially, in checking nil variables, I tend to do
> a lot of (unless (eq thingy nil).

You can express it more succinctly as:

        (when thingy
           ...)

which is equivalent to (unless (eq thingy nil) ...).

There's also `null', which is the usual way of testing for a nil
value:

        (null thingy) == (eq thingy nil)

Sometimes `not' (which is just another name for `null') might express
your intent better.

> Any other comments are appreciated.
>
> (defun my-check-efriend()
>   "Fetch the 'to' address from the e-mail. Look up in bbdb for the given
> address. Look in the note field and check for the string
> 'efriend'. Returns t when that's the case"

The style guideline is to write the first line of a docstring as a
self-contained sentence.  Because in some cases -- e.g. when you use
`M-x apropos' -- only the first line is displayed.

>    (when (string-match "efriend" note) t)

`when' is redundant here.  Just returning the result of

    (string-match "efriend" note)

is the conventional way of doing it (the docstring should then say
"Return non-nil when ...", of course).

  reply	other threads:[~2003-09-15  2:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-14 22:16 Lisp hints with VM, BBDB and Personality Crisis spam
2003-09-15  2:28 ` Jesper Harder [this message]
2003-09-18 13:07   ` Ivan Kanis

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m3znh6iy45.fsf@defun.localdomain \
    --to=harder@myrealbox.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).