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

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

Re: elisp issues on (cond ((when ...) t) ((when) t))


From: Kevin Rodgers
Subject: Re: elisp issues on (cond ((when ...) t) ((when) t))
Date: Fri, 10 Feb 2006 10:50:38 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Sebastian Meisel wrote:
> I'm trying to enhance my flyspell a little bit for german usage and
> succeeded in some aspects, but now come again to the shortcomings of
> my knowledge of elisp. I tried the following code:
> ------->
> (add-hook 'flyspell-incorrect-hook 'flyspell-zusammen())

The () probably does not do what you think -- it's equivalent to the
following, so just get rid of it:

(add-hook 'flyspell-incorrect-hook 'flyspell-zusammen nil)

> (defun flyspell-zusammen (beg end poss)
> "Better spell-checking for german combined words."
> (cond (
>        (when (re-search-backward "\"-" (- beg 2) t)
>     (when (consp poss)
>       (setq temp-buffer (get-buffer-create " *flyspell-temp*"))
>       (save-excursion
>         (copy-to-buffer temp-buffer beg end)
>         (set-buffer temp-buffer)
>         (goto-char (point-min))
>         (setq word (capitalize (buffer-string)))
>         (message word)
>         (when (member word (nth 2 poss)) t)
>         ))) t)  ;;(when (re-search
> ((when (and (re-search-forward "-" (+ end 2) t) (re-search-backward
> "s" (1- end) t))
>     (when (consp poss)
>       (setq temp-buffer (get-buffer-create " *flyspell-temp*"))
>       (save-excursion
>         (copy-to-buffer temp-buffer beg (1- end))
>         (set-buffer temp-buffer)
>         (goto-char (point-min))
>         (setq word (capitalize (buffer-string)))
>         (message word)
>         (when (member word (nth 2 poss)) t)
>         ))) t) ;; (when (and (re-search
>       ))
> <------------
>
> When I try the function without (cond) and with only one (when
> (re-search ...) it works, but (cond ((when ...) t) ((when ...) t))
> seems not to return nil as aspected, when both conditions fail. So no
> word are considered incorrect.
>
> What is the error I made?

Do not use when.  Do not create global variables like temp-buffer and
word unnecessarily.  Remember that when re-search-* succeeds it moves
point, so if you want subsequent searches to start from the same point,
you need to wrap it in save-excursion.

Here's an attempt to clean up your code, without really understanding
it:

(defun flyspell-zusammen (beg end poss)
  "Better spell-checking for german combined words."
  ;; Where is point in relation to beg and end?
  (cond ((and (save-excursion (re-search-backward "\"-" (- beg 2) t))
              (consp poss)
              (let ((word (capitalize (buffer-substring beg end))))
                (message word)
                (member word (nth 2 poss)))))
        ((and (save-excursion (and (re-search-forward "-" (+ end 2) t)
                                   (re-search-backward "s" (1- end) t)))
              (consp poss)
              (let ((word (capitalize (buffer-substring beg (1- end)))))
                (message word)
                (member word (nth 2 poss)))))))

--
Kevin Rodgers





reply via email to

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