unfill-paragraph (region) and indentation

View: New views
10 Messages — Rating Filter:   Alert me  

unfill-paragraph (region) and indentation

by Uwe Brauer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello

I am aware of various un-filling or un-wrapping functions (either for
the region or the paragraph) for example this simple one:

(defun unfill-paragraph-or-region ()
  (interactive)
  (filladapt-mode nil);this is important, because
                      ;otherwise    the   result  is   distorted  by the
                      ;filladapt function stuff
  (let ((fill-column (point-max)))
    (fill-paragraph-or-region nil)
    (filladapt-mode nil)))              ;on again


However none of these functions unfills paragraphs (or regions) with
indentation

Hello this
  and this

Will not be changed to

Hello this   and this


So I wrote up a very simple function which does precisely that: it unfills
paragraphs with indentation. I am not sure whether it is sufficient
efficient. Any comments?

(defun delete-indentation-region (start end)
  "Unfills regions with indentation."
  (interactive "r")
      (save-restriction
        (save-excursion
          (narrow-to-region start end)
          (goto-char (point-min))
                       (while (< (point) (point-max))
          (delete-indentation nil)
                  (forward-line 1)))))


Uwe Brauer




Re: unfill-paragraph (region) and indentation

by Lluis-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

`fill-paragraph-or-region' has been conflated with `fill-paragraph' [1] (don't know in which
version), so your code should be something like:

(defun unfill-paragraph-or-region ()
  (interactive)
  (filladapt-mode nil);this is important, because
                      ;otherwise    the   result  is   distorted  by the
                      ;filladapt function stuff
  (let ((fill-column (point-max)))
    (fill-paragraph nil)
    (filladapt-mode nil)))              ;on again

Note that this will not work with a region containing multiple paragraphs.


Footnotes:
[1]  http://www.opensubscriber.com/message/emacs-devel@.../7807359.html

--
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



Re: unfill-paragraph (region) and indentation

by Lennart Borgman (gmail) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Nov 2, 2009 at 7:21 PM, Lluís <xscript@...> wrote:

> `fill-paragraph-or-region' has been conflated with `fill-paragraph' [1] (don't know in which
> version), so your code should be something like:
>
> (defun unfill-paragraph-or-region ()
>  (interactive)
>  (filladapt-mode nil);this is important, because
>                      ;otherwise    the   result  is   distorted  by the
>                      ;filladapt function stuff
>  (let ((fill-column (point-max)))
>    (fill-paragraph nil)
>    (filladapt-mode nil)))              ;on again
>
> Note that this will not work with a region containing multiple paragraphs.

I think I have sent something like those very simple functions below a
couple of times here (they are part of nXhtml):

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Unfilling
;;
;; The idea is from
;;   http://interglacial.com/~sburke/pub/emacs/sburke_dot_emacs.config

;;;###autoload
(defun unfill-paragraph ()
  "Unfill the current paragraph."
  (interactive) (with-unfilling 'fill-paragraph))
;;(defalias 'unwrap-paragraph 'unfill-paragraph)

;;;###autoload
(defun unfill-region ()
  "Unfill the current region."
  (interactive) (with-unfilling 'fill-region))
;;(defalias 'unwrap-region 'unfill-region)

;;;###autoload
(defun unfill-individual-paragraphs ()
  "Unfill individual paragraphs in the current region."
  (interactive) (with-unfilling 'fill-individual-paragraphs))
;;(defalias 'unwrap-individual-paragraphs 'unfill-individual-paragraphs)

(defun with-unfilling (fn)
  "Unfill using the fill function FN."
  (let ((fill-column 10000000)) (call-interactively fn)))



Re: unfill-paragraph (region) and indentation

by Uwe Brauer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "Lennart" == Lennart Borgman <lennart.borgman@...> writes:
   >>
   >> Note that this will not work with a region containing multiple paragraphs.

   > I think I have sent something like those very simple functions below a
   > couple of times here (they are part of nXhtml):
thanks, two comments,

    -  your code does not unfill paragraphs with indentation

    -  (let ((fill-column 10000000)) that is a huge number, but wouldn't
       (let ((fill-column (point-max))) be on the save side?


Uwe Brauer




Re: unfill-paragraph (region) and indentation

by Stefan Monnier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> However none of these functions unfills paragraphs (or regions) with
> indentation

> Hello this
>   and this

> Will not be changed to

> Hello this   and this

I do not understand.  When I try it on your above paragraph, I get

  Hello this and this

which seems to be exactly what an "unfill" should do.  Could you explain
more precisely what you mean here?


        Stefan




Re: unfill-paragraph (region) and indentation

by Uwe Brauer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "Stefan" == Stefan Monnier <monnier@...> writes:


   > I do not understand.  When I try it on your above paragraph, I get

   >   Hello this and this

   > which seems to be exactly what an "unfill" should do.  Could you
   > explain more precisely what you mean here?

I don't understand neither.

Let us consider the following 2 examples of larger texts.


-------------------------------------------------------------------------
First example

See http://front.math.ucdavis.edu/ for a math specific front-end
or point your web browser at http://arxiv.org/ for the generic front-end.
To unsubscribe, e-mail To: math@..., Subject: cancel
We consider ballistic aggregation equation for gases in which each particle
is  either by its mass and impulsion or by its sole impulsion. For
the constant aggregation rate we prove existence of self-similar solutions as
well as convergence to the self-similarity for generic solutions. For some
classes of mass and/or impulsion dependent rates we are also able to estimate
the large time decay of some moments of generic solutions or to build some new
classes of self-similar solutions.


Here unfill paragraph (or region) works fine! I do not include this
examples because text will be over the 72th column
------------------------------------------------------------------------
Second example:

See http://front.math.ucdavis.edu/ for a math specific front-end
     or point your web browser at http://arxiv.org/ for the generic front-end.
     To unsubscribe, e-mail To: math@..., Subject: cancel
     We consider ballistic aggregation equation for gases in which each particle
     is  either by its mass and impulsion or by its sole impulsion. For
     the constant aggregation rate we prove existence of self-similar solutions as
     well as convergence to the self-similarity for generic solutions. For some
     classes of mass and/or impulsion dependent rates we are also able to estimate
     the large time decay of some moments of generic solutions or to build some new
     classes of self-similar solutions.


Now as I realized just now, the unfill code works in a *message buffer*
without problems. However in a fundamental mode [1] (with all minor
modes turned off) it does not

The best I get is
See http://front.math.ucdavis.edu/ for a math specific front-end
         or point your web browser at http://arxiv.org/ for the generic front-end.  To unsubscribe, e-mail To: math@..., Subject: cancel We consider ballistic aggregation equation for gases in which each particle is either by its mass and impulsion or by its sole impulsion. For the constant aggregation rate we prove existence of self-similar solutions as well as convergence to the self-similarity for generic solutions. For some classes of mass and/or impulsion dependent rates we are also able to estimate the large time decay of some moments of generic solutions or to build some new
     classes of self-similar solutions.


That is why I wrote that small delete-indentation-region function which
works perfectly for this example.

But I am now curious why is message mode special, I mean which is the
setting which is responsible for this behavior.

Uwe

Footnotes:

[1] (and for me more important in text modes)





Re: unfill-paragraph (region) and indentation

by Stefan Monnier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> That is why I wrote that small delete-indentation-region function which
> works perfectly for this example.

> But I am now curious why is message mode special, I mean which is the
> setting which is responsible for this behavior.

It depends on the definition of what is a paragraph, so it depends on
paragraph-start and paragraph-separate.

But FWIW, I can't reporduce the behavior you describe in
fundamental-mode in Emacs-23.1.


        Stefan



Re: unfill-paragraph (region) and indentation

by Miles Bader-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Stefan Monnier <monnier@...> writes:

>> That is why I wrote that small delete-indentation-region function which
>> works perfectly for this example.
>
>> But I am now curious why is message mode special, I mean which is the
>> setting which is responsible for this behavior.
>
> It depends on the definition of what is a paragraph, so it depends on
> paragraph-start and paragraph-separate.
>
> But FWIW, I can't reporduce the behavior you describe in
> fundamental-mode in Emacs-23.1.

Me neither -- the following works perfectly for me to unfill the sample
text in both message-mode and fundamental-mode:

   (let ((fill-column 9999999)) (fill-region (point) (mark)))

However Uwe's sample code uses the function "filladapt-mode", which I
don't seem to have, and can't seem to load by doing (load-library
"filladapt") or (load-library "filladapt-mode"); is it an external
library?  If so, maybe Uwe's problem lies there...

-Miles

--
White, adj. and n. Black.



unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, )

by Uwe Brauer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "Stefan" == Stefan Monnier <monnier@...> writes:

   > It depends on the definition of what is a paragraph, so it depends on
   > paragraph-start and paragraph-separate.

It should not since the unfilling function should (also) act on the region.

   > But FWIW, I can't reporduce the behavior you describe in
   > fundamental-mode in Emacs-23.1.

Right, as I will describe below indeed the basic unfill functions behave
*differently*  in GNU emacs (I used Emacs 22.3) and Xemacs (21.4.22 Mule), so
I will also CC to xemacs beta, which seems to be the better place to
continue the discussion.

   >         Stefan


   >    (let ((fill-column 9999999)) (fill-region (point) (mark)))

   > However Uwe's sample code uses the function "filladapt-mode", which I
   > don't seem to have, and can't seem to load by doing (load-library
   > "filladapt") or (load-library "filladapt-mode"); is it an external
   > library?  If so, maybe Uwe's problem lies there...

No it does not surprise, it is Xemacs filling function itself with
behaves different.

The following I did with
emacs -q (GNU emacs 21.3)
and
xemacs -vanilla (Xemacs 21.4.22 Mule)

In both cases I set the  fill-column to 10000000 and called.

GNU emacs (fill-paragraph)

Xemacs (fill-paragraph-or-region)

The example is (a buffer in fundamental mode)


See http://front.math.ucdavis.edu/ for a math specific front-end
         or point your web browser at http://arxiv.org/ for the generic front-end.
         To unsubscribe, e-mail To: math@..., Subject: cancel
         We consider ballistic aggregation equation for gases in which each particle
         is either by its mass and impulsion or by its sole impulsion. For
         the constant aggregation rate we prove existence of self-similar solutions as
         well as convergence to the self-similarity for generic solutions. For some
         classes of mass and/or impulsion dependent rates we are also able to estimate
         the large time decay of some moments of generic solutions or to build some new
         classes of self-similar solutions.

A text which has indentation.

GNU emacs filled the line as expected Xemacs did not.

The behavior of both filling functions was identical if the text had no
indentation!

Could somebody from the Xemacs dev team comment on this?


thanks

Uwe Brauer




unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, )

by Stephen J. Turnbull-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Reply-To set to xemacs-beta, as it seems this subthread is offtopic on
emacs-devel.

Uwe Brauer writes:

 > No it does not surprise, it is Xemacs filling function itself with
 > behaves different.

 > Could somebody from the Xemacs dev team comment on this?

Yeah, they're different.  I doubt anybody has given the core fill
function love in a couple decades, everybody uses filladapt as far as
I know.  It's one of those things where we kept the core function for
compatibility with Emacs despite a far superior third-party
implementation (it was at the time, anyway; I've used nothing else for
over two decades).

On your sample text, with filladapt it does what I would expect: it
treats the first and last lines (which have different prefixes from
the rest of the lines) as separate paragraphs, and fills the middle
lines to a single line with the same indentation.