* [C-u M-q] -> unfill-paragraph
@ 2011-11-09 21:15 Tom Roche
2011-11-10 3:55 ` Eric Abrahamsen
2011-11-10 17:29 ` Tom Roche
0 siblings, 2 replies; 8+ messages in thread
From: Tom Roche @ 2011-11-09 21:15 UTC (permalink / raw)
To: help-gnu-emacs
I'm running
$ lsb_release -ds
Linux Mint Debian Edition # Update Pack 3
$ uname -rv
2.6.39-2-amd64 #1 SMP Tue Jul 5 02:51:22 UTC 2011
$ emacs --version
GNU Emacs 23.3.1
on which M-q "runs the command fill-paragraph". Therefore ISTM
C-u M-q should run the command unfill-paragraph ... but it does not.
How to accomplish that? I tried
- (define-key global-map "\C-u\M-q" 'unfill-paragraph)
but that fails with error=
- Lisp error: (error "Key sequence C-u M-q starts with non-prefix key C-u")
Apologies if this is a FAQ: feel free to send links to RTFM.
TIA, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-09 21:15 [C-u M-q] -> unfill-paragraph Tom Roche
@ 2011-11-10 3:55 ` Eric Abrahamsen
2011-11-10 17:29 ` Tom Roche
1 sibling, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2011-11-10 3:55 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, Nov 10 2011, Tom Roche wrote:
> I'm running
>
> $ lsb_release -ds
> Linux Mint Debian Edition # Update Pack 3
> $ uname -rv
> 2.6.39-2-amd64 #1 SMP Tue Jul 5 02:51:22 UTC 2011
> $ emacs --version
> GNU Emacs 23.3.1
>
> on which M-q "runs the command fill-paragraph". Therefore ISTM
> C-u M-q should run the command unfill-paragraph ... but it does not.
> How to accomplish that? I tried
First of all, on my setup (emacs 24) there's no `unfill-paragraph'
command, are you sure you've got one? I had to make my own.
Your basic problem is that C-u is a prefix argument: ie, it's used to
feed a numerical argument (specifically, 4) to whatever command you call
next. You can't actually bind it as part of a key sequence to call a
specific command. Prefix keys have to be defined specially, and C-u
isn't.
In order for a command to change its behavior in the presence of a
prefix argument, the function definition itself has to look for the
argument and handle it. A function that doesn't handle it just ignores
it. In this case, `fill-paragraph' does handle a prefix argument, but
takes it to mean that you want to justify the paragraph.
You would have to rewrite the function definition to make it treat a
prefix argument differently. Even then, you wouldn't bind any new
function to C-u M-q, you'd just call `fill-paragraph' with a prefix
argument (which is the key combination C-u M-q), and the function would
behave differently.
So, provided you actually have an `unfill-paragraph' command, you'll
have to bind it to some other key (like C-M-q).
Sure hope that makes sense,
Eric
> - (define-key global-map "\C-u\M-q" 'unfill-paragraph)
>
> but that fails with error=
>
> - Lisp error: (error "Key sequence C-u M-q starts with non-prefix key C-u")
>
> Apologies if this is a FAQ: feel free to send links to RTFM.
>
> TIA, Tom Roche <Tom_Roche@pobox.com>
>
>
--
GNU Emacs 24.0.91.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
of 2011-11-07 on pellet
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-09 21:15 [C-u M-q] -> unfill-paragraph Tom Roche
2011-11-10 3:55 ` Eric Abrahamsen
@ 2011-11-10 17:29 ` Tom Roche
2011-11-10 19:00 ` Scott Frazer
` (3 more replies)
1 sibling, 4 replies; 8+ messages in thread
From: Tom Roche @ 2011-11-10 17:29 UTC (permalink / raw)
To: help-gnu-emacs
Tom Roche Wed, 09 Nov 2011 16:15:00 -0500
>> $ emacs --version
>> GNU Emacs 23.3.1
>> on which M-q "runs the command fill-paragraph". Therefore ISTM
>> C-u M-q should run the command unfill-paragraph ... but it does not.
Eric Abrahamsen Thu, 10 Nov 2011 11:55:56 +0800
> First of all, on my setup (emacs 24) there's no `unfill-paragraph'
> command, are you sure you've got one?
Turns out nxhtml
http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
provides unfill-paragraph:
`C-h f`
>>> unfill-paragraph is an interactive compiled Lisp function in
>>> `ourcomments-util.el'.
nxhtml_2.08/util/ourcomments-util.el (slightly edited for email)
>>>> ;;; 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))
>>>> ;;;###autoload
>>>> (defun unfill-region ()
>>>> "Unfill the current region."
>>>> (interactive) (with-unfilling 'fill-region))
>>>> ;;;###autoload
>>>> (defun unfill-individual-paragraphs ()
>>>> "Unfill individual paragraphs in the current region."
>>>> (interactive) (with-unfilling 'fill-individual-paragraphs))
>>>> (defun with-unfilling (fn)
>>>> "Unfill using the fill function FN."
>>>> (let ((fill-column (1+ (point-max)))) (call-interactively fn)))
> In order for a command to change its behavior in the presence of a
> prefix argument, the function definition itself has to look for the
> argument and handle it. A function that doesn't handle it just ignores
> it. In this case, `fill-paragraph' does handle a prefix argument, but
> takes it to mean that you want to justify the paragraph.
Which I don't want.
> You would have to rewrite the function definition to make it treat a
> prefix argument differently. Even then, you wouldn't bind any new
> function to C-u M-q, you'd just call `fill-paragraph' with a prefix
> argument (which is the key combination C-u M-q)
So is there an easy, userland way to write one's own `fill-paragraph' façade such that
* my `fill-paragraph' would hide (e.g., be earlier in a $PATH) the emacs-provided `fill-paragraph'
* my `fill-paragraph' could delegate to the emacs-provided `fill-paragraph' except when called with prefix argument
? Your assistance is appreciated, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-10 17:29 ` Tom Roche
@ 2011-11-10 19:00 ` Scott Frazer
2011-11-13 1:50 ` Tom Roche
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Scott Frazer @ 2011-11-10 19:00 UTC (permalink / raw)
To: help-gnu-emacs
On 11/10/11 12:29 PM, Tom Roche wrote:
>
> Tom Roche Wed, 09 Nov 2011 16:15:00 -0500
>>> $ emacs --version
>>> GNU Emacs 23.3.1
>
>>> on which M-q "runs the command fill-paragraph". Therefore ISTM
>>> C-u M-q should run the command unfill-paragraph ... but it does not.
Try this:
(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)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-10 17:29 ` Tom Roche
2011-11-10 19:00 ` Scott Frazer
@ 2011-11-13 1:50 ` Tom Roche
2011-11-13 15:52 ` Tom Roche
2011-11-14 17:27 ` Tom Roche
3 siblings, 0 replies; 8+ messages in thread
From: Tom Roche @ 2011-11-13 1:50 UTC (permalink / raw)
To: help-gnu-emacs
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 (e.g., be earlier in a $PATH) 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)
Thanks! that seems to work as desired.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-10 17:29 ` Tom Roche
2011-11-10 19:00 ` Scott Frazer
2011-11-13 1:50 ` Tom Roche
@ 2011-11-13 15:52 ` Tom Roche
2011-11-14 3:44 ` Eric Abrahamsen
2011-11-14 17:27 ` Tom Roche
3 siblings, 1 reply; 8+ messages in thread
From: Tom Roche @ 2011-11-13 15:52 UTC (permalink / raw)
To: help-gnu-emacs
[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 :-(
Your assistance is appreciated, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-13 15:52 ` Tom Roche
@ 2011-11-14 3:44 ` Eric Abrahamsen
0 siblings, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2011-11-14 3:44 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C-u M-q] -> unfill-paragraph
2011-11-10 17:29 ` Tom Roche
` (2 preceding siblings ...)
2011-11-13 15:52 ` Tom Roche
@ 2011-11-14 17:27 ` Tom Roche
3 siblings, 0 replies; 8+ messages in thread
From: Tom Roche @ 2011-11-14 17:27 UTC (permalink / raw)
To: help-gnu-emacs
[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).
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-11-14 17:27 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-09 21:15 [C-u M-q] -> unfill-paragraph Tom Roche
2011-11-10 3:55 ` Eric Abrahamsen
2011-11-10 17:29 ` Tom Roche
2011-11-10 19:00 ` Scott Frazer
2011-11-13 1:50 ` Tom Roche
2011-11-13 15:52 ` Tom Roche
2011-11-14 3:44 ` Eric Abrahamsen
2011-11-14 17:27 ` Tom Roche
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).