|
From: | Kevin Rodgers |
Subject: | Re: need help with a defun |
Date: | Wed, 09 Jul 2003 17:50:45 -0600 |
User-agent: | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 |
Barry Margolin wrote:
In article <3F09E01F.10207@gmx.de>, Bernd Wolter <mathae.wolter@gmx.de> wrote:(defun clean () "Doc string" (while (not (eobp)) (re-search-forward ";\\s-*") ;;pattern of interest delimited by "; " (search-backward ";") (let* ((beg (point)))(while (looking-at "[; ]") ;;is there another pattern on the same line?(forward-char)) (delete-region beg (point))) (if (looking-at "[\n]") ;;are we looking at the end of a line (forward-char) ;;goto the next line (insert-string "\n")) ;;otherwise divide the line (clean)))
...
Why are you calling it recursively at all? You're in a while loop, which will repeat the code until it's done. What you're missing is that the while loop should also terminate when the re-search-forward fails, so it should be: (while (and (not (eobp)) (re-search-forward ";\\s-*"))
Wouldn't re-search-forward effectively terminate the loop as originally written, by signalling an error? -- Kevin Rodgers
[Prev in Thread] | Current Thread | [Next in Thread] |