* string-replace interactive function hit or miss?
@ 2006-02-11 20:01 ChristineLWilson
2006-02-13 21:26 ` Kevin Rodgers
0 siblings, 1 reply; 2+ messages in thread
From: ChristineLWilson @ 2006-02-11 20:01 UTC (permalink / raw)
Hi,
I have a large text file that I need to replace multiple pieces of
text with other chunks...so I open my file in emacs, make my function
interactive, but it seems as though the replacements are happening hit
or miss. Any ideas why this isn't running properly and how I can make
it complete/reliable? Please see the function and text chunk below.
Thanks,
Christine
;;the interactive function
(defun replacegoals ()
(interactive)
(goto-char (point-min))
(replace-string "(goal qleadin" "\"Consider the following
question:<P>\", \"GNAME:qleadin\",")
(replace-string "(goal e1b1.q" "\"<B>Suppose that the suitcase has no
wheels, and is instead subject to a frictional force as it slides
across the floor. If everything else were the same, how would the work
done by the strap on the suitcase change?</B>\", \"GNAME:e1b1.q\",")
(replace-string "(goal dummyans" "\"<P>Please enter your answer:\",
\"GNAME:dummyans\",")
(replace-string "(goal ialeadin" "\"Here is how a physics expert
answered the same question:<P>\", \"GNAME:ialeadin\",")
;;;and so on....
)
;;a chunk of the text file
(goal e1b1ctr
(goal qleadin
"Consider the following question:<P>")
(goal e1b1.q
"<B>Suppose that the suitcase has no wheels, and is instead subject to
a frictional force as it slides across the floor. If everything else
were the
same, how would the work done by the strap on the suitcase
change?</B>")
(goal dummyans "<P>Please enter your answer:"
(("$anything else$")))
(goal ialeadin
"Here is how a physics expert answered the same question:<P>")
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: string-replace interactive function hit or miss?
2006-02-11 20:01 string-replace interactive function hit or miss? ChristineLWilson
@ 2006-02-13 21:26 ` Kevin Rodgers
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Rodgers @ 2006-02-13 21:26 UTC (permalink / raw)
ChristineLWilson@gmail.com wrote:
> I have a large text file that I need to replace multiple pieces of
> text with other chunks...so I open my file in emacs, make my function
> interactive, but it seems as though the replacements are happening hit
> or miss. Any ideas why this isn't running properly and how I can make
> it complete/reliable? Please see the function and text chunk below.
>
> Thanks,
> Christine
>
> ;;the interactive function
> (defun replacegoals ()
> (interactive)
> (goto-char (point-min))
> (replace-string "(goal qleadin" "\"Consider the following
> question:<P>\", \"GNAME:qleadin\",")
> (replace-string "(goal e1b1.q" "\"<B>Suppose that the suitcase has no
> wheels, and is instead subject to a frictional force as it slides
> across the floor. If everything else were the same, how would the work
> done by the strap on the suitcase change?</B>\", \"GNAME:e1b1.q\",")
> (replace-string "(goal dummyans" "\"<P>Please enter your answer:\",
> \"GNAME:dummyans\",")
> (replace-string "(goal ialeadin" "\"Here is how a physics expert
> answered the same question:<P>\", \"GNAME:ialeadin\",")
> ;;;and so on....
> )
Don't use replace-string. Do as its doc string suggests, making sure
you move point to the beginning of the buffer before each replacement:
| This function is usually the wrong thing to use in a Lisp program.
| What you probably want is a loop like this:
| (while (search-forward FROM-STRING nil t)
| (replace-match TO-STRING nil t))
| which will run faster and will not set the mark or print anything.
| (You may need a more complex loop if FROM-STRING can match the null string
| and TO-STRING is also null.)
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-02-13 21:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-11 20:01 string-replace interactive function hit or miss? ChristineLWilson
2006-02-13 21:26 ` 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.