* elisp code for replacing every other occurence in a line?
@ 2014-05-12 17:32 Frank Stutzman
2014-05-12 17:41 ` Grant Rettke
2014-05-12 19:22 ` Frank Stutzman
0 siblings, 2 replies; 4+ messages in thread
From: Frank Stutzman @ 2014-05-12 17:32 UTC (permalink / raw)
To: help-gnu-emacs
This is probably trivial for emacs-masters, but I'm not one and
the solution is escaping me...
Say I have a buffer that have intermittant lines that look like:
a,b,c,DD,e,f,g,DD,h
i,j,k,DD,l,m,n,DD,o
I'm trying to write some lisp code that will change them so that
they look like:
a,b,c,DD,e,f,g,YY,h
i,j,k,DD,l,m,n,ZZ,o
DD,YY and ZZ will always be the same strings. These pairs of lines
may not always be found sequentially in the file. For what its worth,
this buffer is a CSV delimited buffer although I would prefer to do this
without using any special mdoes.
--
Frank Stutzman
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: elisp code for replacing every other occurence in a line?
2014-05-12 17:32 elisp code for replacing every other occurence in a line? Frank Stutzman
@ 2014-05-12 17:41 ` Grant Rettke
2014-05-12 19:22 ` Frank Stutzman
1 sibling, 0 replies; 4+ messages in thread
From: Grant Rettke @ 2014-05-12 17:41 UTC (permalink / raw)
To: Frank Stutzman; +Cc: Emacs Help
What is the first simple case you want to handle that you would define
as successful?
May you post 3-5 sample tests of how you want it to work and would
know that it is working correctly?
Grant Rettke | AAAS, ACM, ASA, FSF, IEEE, SIAM, Sigma Xi
grettke@acm.org | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson
On Mon, May 12, 2014 at 12:32 PM, Frank Stutzman <stutzman@cat2.kjsl.com> wrote:
> This is probably trivial for emacs-masters, but I'm not one and
> the solution is escaping me...
>
> Say I have a buffer that have intermittant lines that look like:
>
> a,b,c,DD,e,f,g,DD,h
> i,j,k,DD,l,m,n,DD,o
>
> I'm trying to write some lisp code that will change them so that
> they look like:
>
> a,b,c,DD,e,f,g,YY,h
> i,j,k,DD,l,m,n,ZZ,o
>
> DD,YY and ZZ will always be the same strings. These pairs of lines
> may not always be found sequentially in the file. For what its worth,
> this buffer is a CSV delimited buffer although I would prefer to do this
> without using any special mdoes.
>
> --
> Frank Stutzman
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: elisp code for replacing every other occurence in a line?
2014-05-12 17:32 elisp code for replacing every other occurence in a line? Frank Stutzman
2014-05-12 17:41 ` Grant Rettke
@ 2014-05-12 19:22 ` Frank Stutzman
2014-05-12 20:43 ` Robert Thorpe
1 sibling, 1 reply; 4+ messages in thread
From: Frank Stutzman @ 2014-05-12 19:22 UTC (permalink / raw)
To: help-gnu-emacs
Nevermind....
It took quite a while to get my brain into elisp mode. Once that happened I
realized that my solution was write there on the help page for replace-string.
Right there where it says you probably don't want to use replace-string.
Pretty much the only real change I had to do was to use the COUNT option on
search-forward.
--
Frank Stutzman
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: elisp code for replacing every other occurence in a line?
2014-05-12 19:22 ` Frank Stutzman
@ 2014-05-12 20:43 ` Robert Thorpe
0 siblings, 0 replies; 4+ messages in thread
From: Robert Thorpe @ 2014-05-12 20:43 UTC (permalink / raw)
To: Frank Stutzman; +Cc: help-gnu-emacs
Frank Stutzman <stutzman@cat2.kjsl.com> writes:
> Nevermind....
>
> It took quite a while to get my brain into elisp mode. Once that happened I
> realized that my solution was write there on the help page for replace-string.
> Right there where it says you probably don't want to use replace-string.
> Pretty much the only real change I had to do was to use the COUNT option on
> search-forward.
You don't necessarily have to write any elisp at all for things like
this. If you can use replace-string or search-forward then you can use
a macro. Start recording with F3, do the search and replaces with
something like M-% then finish with F4. Then do M-x insert-kbd-macro
and it'll give you a bit of elisp code. You can turn that into a defun
and put into your init file if you want to.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-12 20:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-12 17:32 elisp code for replacing every other occurence in a line? Frank Stutzman
2014-05-12 17:41 ` Grant Rettke
2014-05-12 19:22 ` Frank Stutzman
2014-05-12 20:43 ` Robert Thorpe
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).