* What's wrong with this seemingly simple function for unwrapping text?
@ 2007-01-12 11:00 Endless Story
2007-01-12 11:28 ` Tassilo Horn
2007-01-12 15:01 ` B. T. Raven
0 siblings, 2 replies; 4+ messages in thread
From: Endless Story @ 2007-01-12 11:00 UTC (permalink / raw)
I like autofill mode, but it has one disadvantage: the filled lines
require unfilling if I want to copy the text over into a Word
processor, e.g. Word or OpenOffice. This can be rather tedious, so I
thought I would write a simple function and put it in my .init file to
make everything easy:
(defun unwrap-text ()
(interactive)
(setq fill-column 5000)
(mark-whole-buffer)
(fill-region)
(setq fill-column '70)
)
When the function gets to fill-region, it bombs out, complaining about
'wrong number of variables.' So my questions are:
1) For any lisp experts, what's going wrong here?
2) Is there some built-in way for doing what I want to do?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What's wrong with this seemingly simple function for unwrapping text?
2007-01-12 11:00 What's wrong with this seemingly simple function for unwrapping text? Endless Story
@ 2007-01-12 11:28 ` Tassilo Horn
2007-01-12 15:01 ` B. T. Raven
1 sibling, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2007-01-12 11:28 UTC (permalink / raw)
"Endless Story" <usable.thought@gmail.com> writes:
Hi,
> (defun unwrap-text ()
> (interactive)
> (setq fill-column 5000)
> (mark-whole-buffer)
^^^^^^^^^^^^^^^^^
,----[ C-h f mark-whole-buffer RET ]
| mark-whole-buffer is an interactive compiled Lisp function in `simple.el'.
| It is bound to C-x h, <menu-bar> <edit> <mark-whole-buffer>.
| (mark-whole-buffer)
|
| Put point at beginning and mark at end of buffer.
| You probably should not use this function in Lisp programs;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| it is usually a mistake for a Lisp function to use any subroutine
| that uses or sets the mark.
`----
> (fill-region)
^^^^^^^^^^^
That function has two mandatory arguments.
,----[ C-h f fill-region RET ]
| fill-region is an interactive compiled Lisp function in `fill.el'.
| It is bound to <menu-bar> <edit> <fill>.
| (fill-region FROM TO &optional JUSTIFY NOSQUEEZE TO-EOP)
| ^^^^ ^^
| Fill each of the paragraphs in the region.
| A prefix arg means justify as well.
| Ordinarily the variable `fill-column' controls the width.
|
| Noninteractively, the third argument JUSTIFY specifies which
| kind of justification to do: `full', `left', `right', `center',
| or `none' (equivalent to nil). t means handle each paragraph
| as specified by its text properties.
|
| The fourth arg NOSQUEEZE non-nil means to leave
| whitespace other than line breaks untouched, and fifth arg TO-EOP
| non-nil means to keep filling to the end of the paragraph (or next
| hard newline, if variable `use-hard-newlines' is on).
|
| Return the fill-prefix used for filling the last paragraph.
|
| If `sentence-end-double-space' is non-nil, then period followed by one
| space does not end a sentence, so don't break a line there.
`----
> (setq fill-column '70)
^
The quote is quite irritating.
> )
>
> When the function gets to fill-region, it bombs out, complaining about
> 'wrong number of variables.' So my questions are:
>
> 1) For any lisp experts, what's going wrong here?
See above.
> 2) Is there some built-in way for doing what I want to do?
Don't think so, but this should work:
--8<---------------cut here---------------start------------->8---
(defun unwrap-text ()
(interactive)
(let ((fill-column 9999))
(fill-region (point-min) (point-max))))
--8<---------------cut here---------------end--------------->8---
Regards,
Tassilo
--
* delYsid has mortgage, opportunity and penis in his score file.
<delYsid> thats pretty effective against spam
<Luke> aren't you worried about missing opportunities to mortgage
your penis?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What's wrong with this seemingly simple function for unwrapping text?
2007-01-12 11:00 What's wrong with this seemingly simple function for unwrapping text? Endless Story
2007-01-12 11:28 ` Tassilo Horn
@ 2007-01-12 15:01 ` B. T. Raven
2007-01-13 12:18 ` Endless Story
1 sibling, 1 reply; 4+ messages in thread
From: B. T. Raven @ 2007-01-12 15:01 UTC (permalink / raw)
"Endless Story" <usable.thought@gmail.com> wrote in message
news:1168599607.154137.166990@q2g2000cwa.googlegroups.com...
> I like autofill mode, but it has one disadvantage: the filled lines
> require unfilling if I want to copy the text over into a Word
> processor, e.g. Word or OpenOffice. This can be rather tedious, so I
> thought I would write a simple function and put it in my .init file to
> make everything easy:
>
> (defun unwrap-text ()
> (interactive)
> (setq fill-column 5000)
> (mark-whole-buffer)
> (fill-region)
> (setq fill-column '70)
> )
>
> When the function gets to fill-region, it bombs out, complaining about
> 'wrong number of variables.' So my questions are:
>
> 1) For any lisp experts, what's going wrong here?
> 2) Is there some built-in way for doing what I want to do?
>
Tassilo already fixed your problem but here are two more, in case you
might not always want to affect the whole buffer:
(defun unfill-paragraph () "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 () "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))))
Ed
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What's wrong with this seemingly simple function for unwrapping text?
2007-01-12 15:01 ` B. T. Raven
@ 2007-01-13 12:18 ` Endless Story
0 siblings, 0 replies; 4+ messages in thread
From: Endless Story @ 2007-01-13 12:18 UTC (permalink / raw)
Thanks to all. Via a quick Google I also found good recipes for
unfilling paragraph, region, or paragraphs with region, all by Sean
Burke at
http://interglacial.com/~sburke/pub/emacs/sburke_dot_emacs.config
B. T. Raven wrote:
> "Endless Story" <usable.thought@gmail.com> wrote in message
> news:1168599607.154137.166990@q2g2000cwa.googlegroups.com...
> > I like autofill mode, but it has one disadvantage: the filled lines
> > require unfilling if I want to copy the text over into a Word
> > processor, e.g. Word or OpenOffice. This can be rather tedious, so I
> > thought I would write a simple function and put it in my .init file to
> > make everything easy:
> >
> > (defun unwrap-text ()
> > (interactive)
> > (setq fill-column 5000)
> > (mark-whole-buffer)
> > (fill-region)
> > (setq fill-column '70)
> > )
> >
> > When the function gets to fill-region, it bombs out, complaining about
> > 'wrong number of variables.' So my questions are:
> >
> > 1) For any lisp experts, what's going wrong here?
> > 2) Is there some built-in way for doing what I want to do?
> >
>
> Tassilo already fixed your problem but here are two more, in case you
> might not always want to affect the whole buffer:
>
> (defun unfill-paragraph () "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 () "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))))
>
> Ed
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-01-13 12:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-12 11:00 What's wrong with this seemingly simple function for unwrapping text? Endless Story
2007-01-12 11:28 ` Tassilo Horn
2007-01-12 15:01 ` B. T. Raven
2007-01-13 12:18 ` Endless Story
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).