[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [C-u M-q] -> unfill-paragraph
From: |
Eric Abrahamsen |
Subject: |
Re: [C-u M-q] -> unfill-paragraph |
Date: |
Mon, 14 Nov 2011 11:44:11 +0800 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.91 (gnu/linux) |
On Sun, Nov 13 2011, Tom Roche wrote:
> [Text-mode table enclosed--best viewed in monospace font.]
>
> 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] would hide [the] emacs-provided
>>> `fill-paragraph'
>
>>> * [my-fill-paragraph] could delegate to the emacs-provided
>>> `fill-paragraph' except when called with prefix argument
>
> 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)
>
> That works, except for region handling. What the code above does is
>
> +----------------------------------------------------------------+
> | | M-q | C-u M-q |
> +----------------------------------------------------------------+
> | no region selected | fill the paragraph | unfill the paragraph |
> | | surrounding or | surrounding or |
> | | following point | following point |
> +----------------------------------------------------------------+
> | region selected | nothing | unfills first (only) |
> | | | paragraph in region |
> +----------------------------------------------------------------+
>
> What I want is
>
> +------------------------------------------------------------------+
> | | M-q | C-u M-q |
> +------------------------------------------------------------------+
> | no region selected | fill the paragraph | unfill the paragraph |
> | | surrounding or | surrounding or |
> | | following point | following point |
> +------------------------------------------------------------------+
> | region selected | fill all paragraphs | unfill all paragraphs |
> | | in the region | in 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
>
> How to fix? Apologies for elisp lameness. One Of These Days I really gotta
> sit down and learn the tool. But right now, I gotta learn more fortran first
> :-(
Scott's basic approach is still correct: bind M-q to what you want, not
what emacs provides. But then you can delegate:
(defun my-fill-paragraph (&optional arg)
(interactive "P")
(if arg
(call-interactively 'unfill-paragraph)
(call-interactively 'fill-paragraph)))
`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.
Hope that does the trick,
Eric
--
GNU Emacs 24.0.91.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
of 2011-11-07 on pellet