tags:

views:

827

answers:

4

I am green hand for Emacs. I have gooogled this but no good answer there. One of them is Ctrl-n Ctr-a Backspace This works but is stupid. Is there a quick ans simple way to join a block of lines into single?

Actually, I can use Esc-q to auto-fill a paragraph now, but how could I get it revert without UNDO?

+3  A: 

Just replace newlines with nothing.

Tal Pressman
+12  A: 

M-x join-line will join two lines. Just bind it to a convenient keystroke.

pgs
Yes. It works. However, it is of no use to a block of several lines(3 lines or more). Any useful command for this purpose?
jcadam
But if you go to the last line of the block and hit M-^ (the key binding for join-line) several times you will have the same effect. Goes pretty fast, so unless you have hundreds of lines to join I would prefer it over the fill-column hack. Otherwise do as Tal suggests, mark the block and replace newline (C-Q C-J) with nothing.
danielpoe
I have tried to bind join-line to M-1. It works fine also. As you you suggested, many solutions here for the purpose, so I'll try to use them all in a flexible way. Thank you very much!
jcadam
+6  A: 

You could define a new command for this, temporarily adjusting the fill width before using the the Esc-q command:

;; -- define a new command to join multiple lines together --
(defun join-lines () (interactive)
 (setq fill-column 100000)
 (fill-paragraph nil)
 (setq fill-column 78)
)

Obviously this only works, if your paragraph has less than 100000 characters.

Ralph
Without clobbering fill-column, that would be (defun join-lines () (interactive) (let ((fill-column 999999)) (fill-paragraph nil)))
huaiyuan
Yeah. This should be more graceful.
jcadam
What about this ?(defun unfill-paragraph () "Does the opposite of fill-paragraph" (interactive) (let ((fill-column (point-max))) (fill-paragraph nil)))
Gyom
+3  A: 

Place point anywhere on the last line of the group of lines that need joining and call

M-^

repeatedly until all the lines are merged.

Note: It leaves one space between all of the now joined lines.

Ray Vega
That's the one I needed... Thanks!
To1ne