unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* unfill-paragraph (region) and indentation
@ 2009-11-02 16:45 Uwe Brauer
  2009-11-02 18:21 ` Lluís
  2009-11-03 20:02 ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Uwe Brauer @ 2009-11-02 16:45 UTC (permalink / raw)
  To: emacs-devel


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 





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

* Re: unfill-paragraph (region) and indentation
  2009-11-02 16:45 unfill-paragraph (region) and indentation Uwe Brauer
@ 2009-11-02 18:21 ` Lluís
  2009-11-02 18:35   ` Lennart Borgman
  2009-11-03 20:02 ` Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Lluís @ 2009-11-02 18:21 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-devel

`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@gnu.org/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




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

* Re: unfill-paragraph (region) and indentation
  2009-11-02 18:21 ` Lluís
@ 2009-11-02 18:35   ` Lennart Borgman
  2009-11-03 10:08     ` Uwe Brauer
  0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2009-11-02 18:35 UTC (permalink / raw)
  To: Lluís; +Cc: Uwe Brauer, emacs-devel

On Mon, Nov 2, 2009 at 7:21 PM, Lluís <xscript@gmx.net> 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)))




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

* Re: unfill-paragraph (region) and indentation
  2009-11-02 18:35   ` Lennart Borgman
@ 2009-11-03 10:08     ` Uwe Brauer
  0 siblings, 0 replies; 10+ messages in thread
From: Uwe Brauer @ 2009-11-03 10:08 UTC (permalink / raw)
  To: emacs-devel

>>>>> "Lennart" == Lennart Borgman <lennart.borgman@gmail.com> 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 





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

* Re: unfill-paragraph (region) and indentation
  2009-11-02 16:45 unfill-paragraph (region) and indentation Uwe Brauer
  2009-11-02 18:21 ` Lluís
@ 2009-11-03 20:02 ` Stefan Monnier
  2009-11-04  9:43   ` Uwe Brauer
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2009-11-03 20:02 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-devel

> 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





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

* Re: unfill-paragraph (region) and indentation
  2009-11-03 20:02 ` Stefan Monnier
@ 2009-11-04  9:43   ` Uwe Brauer
  2009-11-04 18:40     ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2009-11-04  9:43 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>>>> "Stefan" == Stefan Monnier <monnier@IRO.UMontreal.CA> 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@arXiv.org, 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@arXiv.org, 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@arXiv.org, 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)






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

* Re: unfill-paragraph (region) and indentation
  2009-11-04  9:43   ` Uwe Brauer
@ 2009-11-04 18:40     ` Stefan Monnier
  2009-11-04 23:12       ` Miles Bader
  2009-11-06 10:01       ` unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, ) Uwe Brauer
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2009-11-04 18:40 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-devel

> 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




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

* Re: unfill-paragraph (region) and indentation
  2009-11-04 18:40     ` Stefan Monnier
@ 2009-11-04 23:12       ` Miles Bader
  2009-11-06 10:01       ` unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, ) Uwe Brauer
  1 sibling, 0 replies; 10+ messages in thread
From: Miles Bader @ 2009-11-04 23:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Uwe Brauer, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> 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.




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

* unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, )
  2009-11-04 18:40     ` Stefan Monnier
  2009-11-04 23:12       ` Miles Bader
@ 2009-11-06 10:01       ` Uwe Brauer
  2009-11-06 11:44         ` Stephen J. Turnbull
  1 sibling, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2009-11-06 10:01 UTC (permalink / raw)
  To: Miles Bader
  Cc: Uwe Brauer, XEmacs Beta Discussion, Stefan Monnier, emacs-devel

>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> 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@arXiv.org, 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





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

* unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, )
  2009-11-06 10:01       ` unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, ) Uwe Brauer
@ 2009-11-06 11:44         ` Stephen J. Turnbull
  0 siblings, 0 replies; 10+ messages in thread
From: Stephen J. Turnbull @ 2009-11-06 11:44 UTC (permalink / raw)
  To: Uwe Brauer
  Cc: XEmacs Beta Discussion, emacs-devel, Stefan Monnier, Miles Bader

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.




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

end of thread, other threads:[~2009-11-06 11:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-02 16:45 unfill-paragraph (region) and indentation Uwe Brauer
2009-11-02 18:21 ` Lluís
2009-11-02 18:35   ` Lennart Borgman
2009-11-03 10:08     ` Uwe Brauer
2009-11-03 20:02 ` Stefan Monnier
2009-11-04  9:43   ` Uwe Brauer
2009-11-04 18:40     ` Stefan Monnier
2009-11-04 23:12       ` Miles Bader
2009-11-06 10:01       ` unfill-paragraph(region) is different in GNU emacs and xemacs (was: unfill-paragraph (region) and indentation, ) Uwe Brauer
2009-11-06 11:44         ` Stephen J. Turnbull

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).