all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp issues on (cond ((when ...)  t) ((when) t))
@ 2006-02-10 14:55 Sebastian Meisel
  2006-02-10 17:50 ` Kevin Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Meisel @ 2006-02-10 14:55 UTC (permalink / raw)


Hallo,

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())

(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?

-- 
Sebastian Meisel

(P.S. I apologize, that I incidently used german language in on mail before -- 
switching mailing lists need some concentration.) 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: elisp issues on (cond ((when ...)  t) ((when) t))
  2006-02-10 14:55 Sebastian Meisel
@ 2006-02-10 17:50 ` Kevin Rodgers
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2006-02-10 17:50 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: elisp issues on (cond ((when ...)  t) ((when) t))
       [not found] <mailman.131.1139583288.2885.help-gnu-emacs@gnu.org>
@ 2006-02-10 23:02 ` Thien-Thi Nguyen
  0 siblings, 0 replies; 3+ messages in thread
From: Thien-Thi Nguyen @ 2006-02-10 23:02 UTC (permalink / raw)


Sebastian Meisel <sebastianmeisel@web.de> writes:

> What is the error I made?

are you sure both branches fail?  did you check *Messages*?

are you sure your code behaves as if it were:

  (cond (nil t) (nil t))

?  eval that in *scratch* -- what do you see?  how about:

  (cond (nil t) (nil t) (t))
  (cond (nil t) (nil t) (nil))
  (cond (nil t) (nil t) (42))
  (cond (nil t) (nil t) (t 42))
  (cond (nil t) (nil t) (t nil))
  (cond (nil t) (nil t) (42 t))
  (cond (nil t) (nil t) (42 nil))
  (cond (nil t) (nil t) (42 42))
  (cond (nil t) (nil t) (42 42 42))

why stop with one error?  life's too short to be perfect...

thi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-02-10 23:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.131.1139583288.2885.help-gnu-emacs@gnu.org>
2006-02-10 23:02 ` elisp issues on (cond ((when ...) t) ((when) t)) Thien-Thi Nguyen
2006-02-10 14:55 Sebastian Meisel
2006-02-10 17:50 ` Kevin Rodgers

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.