help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lisp hints with VM, BBDB and Personality Crisis


From: Jesper Harder
Subject: Re: Lisp hints with VM, BBDB and Personality Crisis
Date: Mon, 15 Sep 2003 04:28:26 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

address@hidden 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 via email to

[Prev in Thread] Current Thread [Next in Thread]