all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Refilling paragraphs to remove hard returns?
@ 2010-05-05 11:50 Jesse Sheidlower
  2010-05-05 12:22 ` Marc Mientki
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Jesse Sheidlower @ 2010-05-05 11:50 UTC (permalink / raw)
  To: help-gnu-emacs


I imagine this is a common problem, so I don't know why I'm
having so much trouble finding an answer.

Suppose I have a text document that I've worked on in
text-mode. It is filled using the usual fill tools, so it
wraps at 72 characters, with a hard return after each line.
Paragraphs are separated by an extra hard return; there's no
other indentation.

I now need to give this document to someone who wants to work
on it in a word processor, who complains that there are hard
returns after every line. What's the easy way to remove these?

Going forward, I could work on such documents in
longlines-mode. But it's not clear how to fix what I have. The
trick mentioned in the Emacs wiki of resetting fill-column to
a large number and then refilling the region doesn't work,
because each paragraph is seen as one line, rather than the
block of text set off by two newlines. Yes, I can regex
replace all examples of return (not followed by another
return) with a space, but I'd think there must be something
more organic.

What trick am I missing?

Thanks.

Jesse Sheidlower


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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 11:50 Refilling paragraphs to remove hard returns? Jesse Sheidlower
@ 2010-05-05 12:22 ` Marc Mientki
  2010-05-05 13:07   ` B. T. Raven
  2010-05-05 13:12 ` Xah Lee
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Marc Mientki @ 2010-05-05 12:22 UTC (permalink / raw)
  To: help-gnu-emacs

Am 05.05.2010 13:50, schrieb Jesse Sheidlower:
> I imagine this is a common problem, so I don't know why I'm
> having so much trouble finding an answer.
>
> Suppose I have a text document that I've worked on in
> text-mode. It is filled using the usual fill tools, so it
> wraps at 72 characters, with a hard return after each line.
> Paragraphs are separated by an extra hard return; there's no
> other indentation.
>
> I now need to give this document to someone who wants to work
> on it in a word processor, who complains that there are hard
> returns after every line. What's the easy way to remove these?

Some way may be unfill-region, that I found here at NG some years
ago:

(defun unfill-region (start end)
   "Make all START to END a single line."
   (interactive "*r")
   (save-excursion
     (goto-char end)
     (while
         (progn (goto-char (point-at-bol)) (< start (point)))
       (delete-indentation))))


But for long texts I use simply fill-paragraph or
fill-individual-paragraphs on whole text (buffer is in
text-mode, no longlines-mode is active). The result is
one lines per paragraph.

regards
Marc



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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 12:22 ` Marc Mientki
@ 2010-05-05 13:07   ` B. T. Raven
  0 siblings, 0 replies; 10+ messages in thread
From: B. T. Raven @ 2010-05-05 13:07 UTC (permalink / raw)
  To: help-gnu-emacs

Marc Mientki wrote:
> Am 05.05.2010 13:50, schrieb Jesse Sheidlower:
>> I imagine this is a common problem, so I don't know why I'm
>> having so much trouble finding an answer.
>>
>> Suppose I have a text document that I've worked on in
>> text-mode. It is filled using the usual fill tools, so it
>> wraps at 72 characters, with a hard return after each line.
>> Paragraphs are separated by an extra hard return; there's no
>> other indentation.
>>
>> I now need to give this document to someone who wants to work
>> on it in a word processor, who complains that there are hard
>> returns after every line. What's the easy way to remove these?
> 
> Some way may be unfill-region, that I found here at NG some years
> ago:
> 
> (defun unfill-region (start end)
>   "Make all START to END a single line."
>   (interactive "*r")
>   (save-excursion
>     (goto-char end)
>     (while
>         (progn (goto-char (point-at-bol)) (< start (point)))
>       (delete-indentation))))
> 
> 
> But for long texts I use simply fill-paragraph or
> fill-individual-paragraphs on whole text (buffer is in
> text-mode, no longlines-mode is active). The result is
> one lines per paragraph.
> 
> regards
> Marc
> 

These also work (with the help of a large magic number). I don't know if
it's better practice to use interactive "r" and start, end or point and
mark:

(defun unfill-paragraph () ;; bound to C-x M-q
  "Do the opposite of fill-paragraph; stuff all lines in the current
paragraph into a single long line."
  (interactive)
  (let ((fill-column 90002000))
    (fill-paragraph nil)))

(defun unfill-region () ;; bound to C-x s-q
  "Do the opposite of fill-region; stuff all paragraphs in the current
region into long lines."
  (interactive)
  (let ((fill-column 90002000))
    (fill-region (point) (mark))))


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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 11:50 Refilling paragraphs to remove hard returns? Jesse Sheidlower
  2010-05-05 12:22 ` Marc Mientki
@ 2010-05-05 13:12 ` Xah Lee
  2010-05-05 17:29 ` Uday S Reddy
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Xah Lee @ 2010-05-05 13:12 UTC (permalink / raw)
  To: help-gnu-emacs

On May 5, 4:50 am, jes...@panix.com (Jesse Sheidlower) wrote:
> I imagine this is a common problem, so I don't know why I'm
> having so much trouble finding an answer.
>
> Suppose I have a text document that I've worked on in
> text-mode. It is filled using the usual fill tools, so it
> wraps at 72 characters, with a hard return after each line.
> Paragraphs are separated by an extra hard return; there's no
> other indentation.
>
> I now need to give this document to someone who wants to work
> on it in a word processor, who complains that there are hard
> returns after every line. What's the easy way to remove these?
>
> Going forward, I could work on such documents in
> longlines-mode. But it's not clear how to fix what I have. The
> trick mentioned in the Emacs wiki of resetting fill-column to
> a large number and then refilling the region doesn't work,
> because each paragraph is seen as one line, rather than the
> block of text set off by two newlines. Yes, I can regex
> replace all examples of return (not followed by another
> return) with a space, but I'd think there must be something
> more organic.
>
> What trick am I missing?
>
> Thanks.
>
> Jesse Sheidlower

there's unfill-region or something builtin in emacs i think since 22,
but isn't loaded by default... (or was it in )

anyway, there's code here:

• Suggestions on Emacs's Line-Cutting Commands
  http://xahlee.org/emacs/modernization_fill-paragraph.html

or, if you want a simple code, use this:

(defun remove-line-breaks ()
  "Remove line endings in a paragraph."
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))

from:

• Emacs Lisp Examples
  http://xahlee.org/emacs/elisp_examples.html

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 11:50 Refilling paragraphs to remove hard returns? Jesse Sheidlower
  2010-05-05 12:22 ` Marc Mientki
  2010-05-05 13:12 ` Xah Lee
@ 2010-05-05 17:29 ` Uday S Reddy
  2010-05-06 17:53   ` jpkotta
  2010-05-06 18:08 ` Ross A. Laird
  2010-05-07  5:38 ` Jonathan Groll
  4 siblings, 1 reply; 10+ messages in thread
From: Uday S Reddy @ 2010-05-05 17:29 UTC (permalink / raw)
  To: help-gnu-emacs

jester@panix.com (Jesse Sheidlower) writes:

> Going forward, I could work on such documents in
> longlines-mode. But it's not clear how to fix what I have. The
> trick mentioned in the Emacs wiki of resetting fill-column to
> a large number and then refilling the region doesn't work,
> because each paragraph is seen as one line, rather than the
> block of text set off by two newlines.

I use the trick mentioned in Emacs wiki all the time.  I am not sure
why you say it doesn't work.

Make sure that you don't have longlines-mode turned on while you do
the unfilling.

Cheers,
Uday Reddy


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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 17:29 ` Uday S Reddy
@ 2010-05-06 17:53   ` jpkotta
  0 siblings, 0 replies; 10+ messages in thread
From: jpkotta @ 2010-05-06 17:53 UTC (permalink / raw)
  To: help-gnu-emacs

On May 5, 12:29 pm, Uday S Reddy <U.S.Re...@cs.bham.ac.uk> wrote:
> jes...@panix.com (Jesse Sheidlower) writes:
> > Going forward, I could work on such documents in
> > longlines-mode. But it's not clear how to fix what I have. The
> > trick mentioned in the Emacs wiki of resetting fill-column to
> > a large number and then refilling the region doesn't work,
> > because each paragraph is seen as one line, rather than the
> > block of text set off by two newlines.
>
> I use the trick mentioned in Emacs wiki all the time.  I am not sure
> why you say it doesn't work.
>
> Make sure that you don't have longlines-mode turned on while you do
> the unfilling.
>
> Cheers,
> Uday Reddy

I used to use that trick too, but then I started using filladapt.  It
acts like it doesn't know about fill-column (and glancing at the code
it seems to modify it on the fly in some cases).  I like filladapt
more than unfilling and it never bothered me enough to fix it.


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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 11:50 Refilling paragraphs to remove hard returns? Jesse Sheidlower
                   ` (2 preceding siblings ...)
  2010-05-05 17:29 ` Uday S Reddy
@ 2010-05-06 18:08 ` Ross A. Laird
  2010-05-07  5:38 ` Jonathan Groll
  4 siblings, 0 replies; 10+ messages in thread
From: Ross A. Laird @ 2010-05-06 18:08 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: jester

jester@panix.com (Jesse Sheidlower) writes:

> I imagine this is a common problem, so I don't know why I'm
> having so much trouble finding an answer.
>
> Suppose I have a text document that I've worked on in
> text-mode. It is filled using the usual fill tools, so it
> wraps at 72 characters, with a hard return after each line.
> Paragraphs are separated by an extra hard return; there's no
> other indentation.
>
> I now need to give this document to someone who wants to work
> on it in a word processor, who complains that there are hard
> returns after every line. What's the easy way to remove these?
>
> Going forward, I could work on such documents in
> longlines-mode. But it's not clear how to fix what I have. The
> trick mentioned in the Emacs wiki of resetting fill-column to
> a large number and then refilling the region doesn't work,
> because each paragraph is seen as one line, rather than the
> block of text set off by two newlines. Yes, I can regex
> replace all examples of return (not followed by another
> return) with a space, but I'd think there must be something
> more organic.

Instead of using longlines-mode, look into visual-line-mode. It's much
better.

As for un-filling, I use this in my ~/.emacs:

;unfill paragraph
(defun unfill-paragraph ()
  (interactive)
  (let ((fill-column (point-max)))
  (fill-paragraph nil)))
(global-set-key (kbd "<f6>") 'unfill-paragraph)

Works like a charm. I hit F6 and the paragraph is instantly
re-formatted as an Emacs line. If visual-line-mode is on when I do this,
the paragraph is automagically wrapped as well (but with no hard returns).

Ross

-- 
Ross A. Laird, PhD
www.rosslaird.com





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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-05 11:50 Refilling paragraphs to remove hard returns? Jesse Sheidlower
                   ` (3 preceding siblings ...)
  2010-05-06 18:08 ` Ross A. Laird
@ 2010-05-07  5:38 ` Jonathan Groll
  2010-05-07 13:08   ` Lennart Borgman
  4 siblings, 1 reply; 10+ messages in thread
From: Jonathan Groll @ 2010-05-07  5:38 UTC (permalink / raw)
  To: Jesse Sheidlower, help-gnu-emacs

On Wed, May 05, 2010 at 07:50:55AM -0400, Jesse Sheidlower wrote:
>
>I imagine this is a common problem, so I don't know why I'm
>having so much trouble finding an answer.
>
>Suppose I have a text document that I've worked on in
>text-mode. It is filled using the usual fill tools, so it
>wraps at 72 characters, with a hard return after each line.
>Paragraphs are separated by an extra hard return; there's no
>other indentation.
>
>I now need to give this document to someone who wants to work
>on it in a word processor, who complains that there are hard
>returns after every line. What's the easy way to remove these?
>
>Going forward, I could work on such documents in
>longlines-mode. But it's not clear how to fix what I have. The
>trick mentioned in the Emacs wiki of resetting fill-column to
>a large number and then refilling the region doesn't work,
>because each paragraph is seen as one line, rather than the
>block of text set off by two newlines. Yes, I can regex
>replace all examples of return (not followed by another
>return) with a space, but I'd think there must be something
>more organic.
>
>What trick am I missing?

I'm not sure why no-one has mentioned it but my Emacs (GNU Emacs
23.1.90.1) comes standard (I think!) with
unfill-individual-paragraphs:

unfill-individual-paragraphs is an interactive Lisp function in
`ourcomments-util.el'.

(unfill-individual-paragraphs)

Unfill individual paragraphs in the current region.

This sounds exactly like what you need.

Cheers,
Jonathan




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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-07  5:38 ` Jonathan Groll
@ 2010-05-07 13:08   ` Lennart Borgman
  2010-05-07 13:36     ` Jonathan Groll
  0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2010-05-07 13:08 UTC (permalink / raw)
  To: Jonathan Groll; +Cc: help-gnu-emacs, Jesse Sheidlower

On Fri, May 7, 2010 at 7:38 AM, Jonathan Groll <lists@groll.co.za> wrote:
>
> I'm not sure why no-one has mentioned it but my Emacs (GNU Emacs
> 23.1.90.1) comes standard (I think!) with
> unfill-individual-paragraphs:
>
> unfill-individual-paragraphs is an interactive Lisp function in
> `ourcomments-util.el'.


That (ourcomments-util.el) is a part of nXhtml, not core Emacs. (It
comes however with the patched version of Emacs+EmacsW32.)


> (unfill-individual-paragraphs)
>
> Unfill individual paragraphs in the current region.
>
> This sounds exactly like what you need.
>
> Cheers,
> Jonathan
>
>
>




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

* Re: Refilling paragraphs to remove hard returns?
  2010-05-07 13:08   ` Lennart Borgman
@ 2010-05-07 13:36     ` Jonathan Groll
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Groll @ 2010-05-07 13:36 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, May 07, 2010 at 03:08:22PM +0200, Lennart Borgman wrote:
>On Fri, May 7, 2010 at 7:38 AM, Jonathan Groll <lists@groll.co.za> wrote:
>>
>> I'm not sure why no-one has mentioned it but my Emacs (GNU Emacs
>> 23.1.90.1) comes standard (I think!) with
>> unfill-individual-paragraphs:
>>
>> unfill-individual-paragraphs is an interactive Lisp function in
>> `ourcomments-util.el'.
>
>
>That (ourcomments-util.el) is a part of nXhtml, not core Emacs. (It
>comes however with the patched version of Emacs+EmacsW32.)
>
Yes, that is where I must have got it from. nXhtml comes with other
goodies too, like the excellent:
hfyview-buffer is an interactive Lisp function in 'hfyview.el'.

It is bound to <menu-bar> <file> <hfyview-print>
<hfyview-browser-pre>.

(hfyview-buffer &optional REGION-ONLY)

Convert buffer to html preserving faces and show in web browser.

And, of course, it is great for XHTML! Thank you Lennart.

Cheers,
Jonathan




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

end of thread, other threads:[~2010-05-07 13:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-05 11:50 Refilling paragraphs to remove hard returns? Jesse Sheidlower
2010-05-05 12:22 ` Marc Mientki
2010-05-05 13:07   ` B. T. Raven
2010-05-05 13:12 ` Xah Lee
2010-05-05 17:29 ` Uday S Reddy
2010-05-06 17:53   ` jpkotta
2010-05-06 18:08 ` Ross A. Laird
2010-05-07  5:38 ` Jonathan Groll
2010-05-07 13:08   ` Lennart Borgman
2010-05-07 13:36     ` Jonathan Groll

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.