Emacs macro for joining strings?

I have several thousand lines with delimiters. Unfortunately, some of my data is wrapped in a new line. How can I search for all lines that do not contain my delimeter, and then join the previous line, go to the next line, and then continue to the end of the buffer?

Buffer to

1243 | This is all one. line
1235 | This corresponds to one line.
43223 | This line wraps for some reason.

Buffer after

1243 | This is all one line.
1235 | This corresponds to one line.
43223 | This line is wrapped for some reason.

+6
emacs
source share
3 answers

This is a good job for keyboard macros. Try something like this:

Cx ( Mx isearch-forward-regexp RET ^[^|]*$ RET M-^ Cx ) where Cx ( begins recording a keyboard macro, which consists of Mx isearch-forward-regexp RET searching forward using a regular expression ^[^|]*$ representing a line containing no | characters, then M-^ joining the current line to the previous line and Cx ) ending the keyboard macro definition. 

This macro can be called manually several times using Cx e (kmacro-end-and-call-macro), or you can save it as a function and call it programmatically, as described at http://www.emacswiki.org/emacs/ KeyboardMacrosTricks .

+5
source share

Try Mx query-replace-regexp , find

 ^\(.\+|.\+\)\n\([^|]\+\)$ 

And replacement:

 \1\2 

NTN

+4
source share

(global key set (kbd "Cc Cj") 'connection line)

+1
source share

All Articles