I have this function which fails with newline processing
(defun fmt-tbl ()
"format Word tables for wiki"
(interactive)
(goto-char (point-min))
(insert "{||-")
(while (search-forward "\t")
(delete-backward-char 1)
(insert "|")
)
(goto-char (point-min))
(while (search-forward "\n")
(insert "|-")
)
(goto-char (point-max))
(insert "|}")
)
I also tried this:
(while (end-of-line)
(insert "|-")
)
But that didn't work either.
It would be ok to repeatedly move to end of next line checking for end of buffer. How could I do that?
What is the elisp idiom for do until end of buffer?
Re: What is the elisp idiom for do until end of buffer?
search-forward will throw an error by default if the string is not found. This will throw control out of your function which isn't catching errors. To use search-forward in a loop it is best to set the NOERROR argument to t:
The documentation for end-of-line says nothing about its return value, so its best to not use or rely on it, but it seems to always return nil:
Code: Select all
(while (search-forward "\t" nil t)
...)
Code: Select all
ELISP> (with-current-buffer "*scratch*" (goto-char (point-min)) (end-of-line))
nil
Parenthetically speaking, that is.