unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* What is elisp idiom for continue until end of buffer
@ 2012-08-10 14:43 acomber
  2012-08-10 16:12 ` Eric Abrahamsen
  0 siblings, 1 reply; 3+ messages in thread
From: acomber @ 2012-08-10 14:43 UTC (permalink / raw)
  To: Help-gnu-emacs

I created this elisp function

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

Which fails at  (while (search-forward "\n").  I also tried 
 (while (end-of-line)
   (insert "|-")
 )

But that also didn't work.

How can I repeatedly goto end of line on each line until EOF?




--
View this message in context: http://emacs.1067599.n5.nabble.com/What-is-elisp-idiom-for-continue-until-end-of-buffer-tp261116.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



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

* Re: What is elisp idiom for continue until end of buffer
  2012-08-10 14:43 What is elisp idiom for continue until end of buffer acomber
@ 2012-08-10 16:12 ` Eric Abrahamsen
  2012-08-10 16:16   ` acomber
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Abrahamsen @ 2012-08-10 16:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Aug 10 2012, acomber wrote:

> I created this elisp function
>
> (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 "|}")
> )
>
> Which fails at  (while (search-forward "\n").  I also tried 
>  (while (end-of-line)
>    (insert "|-")
>  )
>
> But that also didn't work.
>
> How can I repeatedly goto end of line on each line until EOF?

`search-forward' takes an optional *third* argument, NOERROR. First
(required) argument is the string to search for, second is a buffer
position to limit the search to (set to nil for whole buffer), and the
third should be set to 't' to keep the function from exploding when no
further matches are found.

Not once I have I used this function without setting NOERROR to 't'.

E

>
>
>
>
> --
> View this message in context: http://emacs.1067599.n5.nabble.com/What-is-elisp-idiom-for-continue-until-end-of-buffer-tp261116.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>
>

-- 
GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.11)
 of 2012-08-06 on pellet




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

* Re: What is elisp idiom for continue until end of buffer
  2012-08-10 16:12 ` Eric Abrahamsen
@ 2012-08-10 16:16   ` acomber
  0 siblings, 0 replies; 3+ messages in thread
From: acomber @ 2012-08-10 16:16 UTC (permalink / raw)
  To: Help-gnu-emacs

Thanks that's brilliant :)



--
View this message in context: http://emacs.1067599.n5.nabble.com/elisp-fails-while-Search-failed-why-tp261116p261135.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



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

end of thread, other threads:[~2012-08-10 16:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-10 14:43 What is elisp idiom for continue until end of buffer acomber
2012-08-10 16:12 ` Eric Abrahamsen
2012-08-10 16:16   ` acomber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).