help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -> unfill-paragraph


From: Xah Lee
Subject: Re: -> unfill-paragraph
Date: Wed, 28 Mar 2012 19:27:17 -0000
User-agent: G2/1.0

On Nov 14, 9:27 am, Tom Roche <Tom_Ro...@pobox.com> wrote:
> [Text-mode tables enclosed--best viewed in monospace font--
>  and there's also some utf-8]
>
> Tom Roche Thu, 10 Nov 2011 12:29:33 -0500
>
> >>>> [How] to write one's own `fill-paragraph' façade such that
> >>>> * [my-fill-paragraph hides] the emacs-provided `fill-paragraph'
> >>>> * [my-fill-paragraph delegates] to the emacs-provided
> >>>>   `fill-paragraph' except when called with [C-u]
>
> Scott Frazer Thu, 10 Nov 2011 14:00:14 -0500
>
> >>> (defun my-fill-paragraph (&optional arg)
> >>>   (interactive "P")
> >>>   (let ((fill-column (if arg (point-max) fill-column)))
> >>>     (fill-paragraph)))
> >>> (global-set-key (kbd "M-q") 'my-fill-paragraph)
>
> Tom Roche Sun, 13 Nov 2011 10:52:44 -0500
>
>
>
>
>
>
>
>
>
> >> That works, except for region handling[, i.e.,]
> >> +--------------------------------------------------------------+
> >> |                    | M-q              | C-u M-q              |
> >> +--------------------------------------------------------------+
> >> | no region selected | fill paragraph   | unfill paragraph     |
> >> |                    | surrounding or   | surrounding or       |
> >> |                    | following point  | following point      |
> >> +--------------------------------------------------------------+
> >> | region selected    | nothing          | unfills (only)       |
> >> |                    |                  | first paragraph      |
> >> |                    |                  | in the region        |
> >> +--------------------------------------------------------------+
> >> What I want is
> >> +-----------------------------------------------------------+
> >> |                    | M-q              | C-u M-q           |
> >> +-----------------------------------------------------------+
> >> | no region selected | fill paragraph   | unfill paragraph  |
> >> |                    | surrounding or   | surrounding or    |
> >> |                    | following point  | following point   |
> >> +-----------------------------------------------------------+
> >> | region selected    | fill all         | unfill all        |
> >> |                    | paragraphs in    | paragraphs in     |
> >> |                    | the region       | the region        |
> >> +-----------------------------------------------------------+
> >> Note that the wanted region-handling behaviors are those which one
> >> gets using M-x, i.e., with region selected
> >> * `M-x fill-paragraph' fills all paragraphs in the selected region
> >> * `M-x unfill-paragraph' unfills all paragraphs in the selected region
>
> Eric Abrahamsen Mon, 14 Nov 2011 11:44:11 +0800
>
> > Scott's basic approach is still correct: bind M-q to what you want,
>
> Yes, that I understand.
>
> > `call-interactively' ensures that whatever prefix arguments
> > `fill-paragraph' and `unfill-paragraph' might take (the region being
> > the important one here) are passed to those commands properly.
>
> Thanks! This indeed seems to work as desired:
>
> (defun my-fill-paragraph (&optional arg)
>   (interactive "P")
>   (if arg
>     (call-interactively 'unfill-paragraph)
>     (call-interactively 'fill-paragraph)))
>
> (global-set-key (kbd "M-q") 'my-fill-paragraph)
>
> I'll "field-test" today then post gnu-emacs-sources (with attribution).

might be better is to have a command that toggle the formatting state
of adding newline chars or removing newline chars. That is, when text
is hard-wrapped, calling the command will do “unfill”, and if it is
not hard-wrapped, calling the command will do “fill”.

also, when there's text selection, automatically work on text
selection.

when the cursor is in a programing lang source code, the command
should automatically do pretty-format the current block of text.

see

〈Suggestions on Emacs's Line Wrap Commands〉
http://xahlee.org/emacs/modernization_fill-paragraph.html

 Xah


reply via email to

[Prev in Thread] Current Thread [Next in Thread]