* How to detect C-u supplied arguments from other prefix arguments
@ 2007-08-07 21:46 Dieter Wilhelm
2007-08-08 5:06 ` Kevin Rodgers
[not found] ` <mailman.4513.1186549602.32220.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 9+ messages in thread
From: Dieter Wilhelm @ 2007-08-07 21:46 UTC (permalink / raw)
To: help-gnu-emacs
Hi
I'd like to detect whether prefix arguments of a command are supplied
by C-u or otherwise.
My idea is to use this-command-keys and compare it to some string,
like the following pseudo code:
(defun bla (arg)
(interactive "p")
(when (string= "C-u" (substring (this-command-keys) 0 2))
(message "hurray")))
I just don't understand how to compare key sequences. Or maybe
there's better way of doing it?
--
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to detect C-u supplied arguments from other prefix arguments
2007-08-07 21:46 How to detect C-u supplied arguments from other prefix arguments Dieter Wilhelm
@ 2007-08-08 5:06 ` Kevin Rodgers
[not found] ` <mailman.4513.1186549602.32220.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2007-08-08 5:06 UTC (permalink / raw)
To: help-gnu-emacs
Dieter Wilhelm wrote:
> Hi
>
> I'd like to detect whether prefix arguments of a command are supplied
> by C-u or otherwise.
>
> My idea is to use this-command-keys and compare it to some string,
> like the following pseudo code:
>
> (defun bla (arg)
> (interactive "p")
> (when (string= "C-u" (substring (this-command-keys) 0 2))
> (message "hurray")))
>
> I just don't understand how to compare key sequences. Or maybe
> there's better way of doing it?
Yuck. If all you're concerned about is whether the prefix arg was
specified by 1 or more C-u keys (with no minus sign or digits), you
can use (consp current-prefix-arg).
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.4513.1186549602.32220.help-gnu-emacs@gnu.org>]
* Re: How to detect C-u supplied arguments from other prefix arguments
[not found] ` <mailman.4513.1186549602.32220.help-gnu-emacs@gnu.org>
@ 2007-08-08 8:32 ` dieter.wilhelm
0 siblings, 0 replies; 9+ messages in thread
From: dieter.wilhelm @ 2007-08-08 8:32 UTC (permalink / raw)
To: help-gnu-emacs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 1065 bytes --]
On 8 août, 07:06, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> Dieter Wilhelm wrote:
> > I'd like to detect whether prefix arguments of a command are supplied
> > by C-u or otherwise.
> > My idea is to use this-command-keys and compare it to some string,
> > like the following pseudo code:
>
> > (defun bla (arg)
> > (interactive "p")
> > (when (string= "C-u" (substring (this-command-keys) 0 2))
> > (message "hurray")))
>
> > I just don't understand how to compare key sequences. Or maybe
> > there's better way of doing it?
>
> Yuck. If all you're concerned about is whether the prefix arg was
> specified by 1 or more C-u keys (with no minus sign or digits), you
> can use (consp current-prefix-arg).
Unfortunately this doesn't work in all cases: I'd also like to
specify numerical
arguments with C-u (not only powers of 4). For example
C-u 3 M-x some-command
and would like to distinguish it from other means of supplying
numerical
arguments e.g.:
M-3 M-x some-command
> Kevin Rodgers
Thanks
Dieter
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.4504.1186523154.32220.help-gnu-emacs@gnu.org>]
* Re: How to detect C-u supplied arguments from other prefix arguments
[not found] <mailman.4504.1186523154.32220.help-gnu-emacs@gnu.org>
@ 2007-08-08 11:55 ` Johan Bockgård
2007-08-08 12:27 ` dieter.wilhelm
2007-08-09 17:49 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Johan Bockgård @ 2007-08-08 11:55 UTC (permalink / raw)
To: help-gnu-emacs
Dieter Wilhelm <dieter@duenenhof-wilhelm.de> writes:
> I'd like to detect whether prefix arguments of a command are supplied
> by C-u or otherwise.
>
> My idea is to use this-command-keys and compare it to some string,
> like the following pseudo code:
>
> (defun bla (arg)
> (interactive "p")
> (when (string= "C-u" (substring (this-command-keys) 0 2))
> (message "hurray")))
>
> I just don't understand how to compare key sequences.
You want to check for the character ^U, not the three-character string
`C - u'. Like
(eq ?\C-u (aref (this-command-keys) 0))
(The whole idea seems a bit ugly though.)
`(substring ... 0 2)' returns a string of length 2, btw.
--
Johan Bockgård
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to detect C-u supplied arguments from other prefix arguments
2007-08-08 11:55 ` Johan Bockgård
@ 2007-08-08 12:27 ` dieter.wilhelm
2007-08-09 4:04 ` Barry Margolin
0 siblings, 1 reply; 9+ messages in thread
From: dieter.wilhelm @ 2007-08-08 12:27 UTC (permalink / raw)
To: help-gnu-emacs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 1185 bytes --]
On 8 août, 13:55, bojohan+n...@dd.chalmers.se (Johan Bockgård) wrote:
> Dieter Wilhelm <die...@duenenhof-wilhelm.de> writes:
> > I'd like to detect whether prefix arguments of a command are supplied
> > by C-u or otherwise.
>
> > My idea is to use this-command-keys and compare it to some string,
> > like the following pseudo code:
>
> > (defun bla (arg)
> > (interactive "p")
> > (when (string= "C-u" (substring (this-command-keys) 0 2))
> > (message "hurray")))
>
> > I just don't understand how to compare key sequences.
>
> You want to check for the character ^U, not the three-character string
> `C - u'. Like
>
> (eq ?\C-u (aref (this-command-keys) 0))
hurray it works, thanks a lot!
>
> (The whole idea seems a bit ugly though.)
Why? In Emacs there are just too little short key combinations free.
I'd like to achieve
a switch for certain functions depending whether their arguments ARG
are supplied by C-u or not.
For example: M-d might kill ARG word with the following boundary/
whitespace or without,
or C-t might drag a character ARG chars away and in the other case
merely transpose neighbouring chars some ARG chars away.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to detect C-u supplied arguments from other prefix arguments
2007-08-08 12:27 ` dieter.wilhelm
@ 2007-08-09 4:04 ` Barry Margolin
2007-08-09 6:52 ` Dieter Wilhelm
0 siblings, 1 reply; 9+ messages in thread
From: Barry Margolin @ 2007-08-09 4:04 UTC (permalink / raw)
To: help-gnu-emacs
In article <1186576048.530383.47680@q75g2000hsh.googlegroups.com>,
dieter.wilhelm@googlemail.com wrote:
> On 8 ao?t, 13:55, bojohan+n...@dd.chalmers.se (Johan Bockg?rd) wrote:
> > Dieter Wilhelm <die...@duenenhof-wilhelm.de> writes:
> > > I'd like to detect whether prefix arguments of a command are supplied
> > > by C-u or otherwise.
> >
> > > My idea is to use this-command-keys and compare it to some string,
> > > like the following pseudo code:
> >
> > > (defun bla (arg)
> > > (interactive "p")
> > > (when (string= "C-u" (substring (this-command-keys) 0 2))
> > > (message "hurray")))
> >
> > > I just don't understand how to compare key sequences.
> >
> > You want to check for the character ^U, not the three-character string
> > `C - u'. Like
> >
> > (eq ?\C-u (aref (this-command-keys) 0))
>
> hurray it works, thanks a lot!
> >
> > (The whole idea seems a bit ugly though.)
>
> Why? In Emacs there are just too little short key combinations free.
> I'd like to achieve
> a switch for certain functions depending whether their arguments ARG
> are supplied by C-u or not.
>
> For example: M-d might kill ARG word with the following boundary/
> whitespace or without,
> or C-t might drag a character ARG chars away and in the other case
> merely transpose neighbouring chars some ARG chars away.
And what if the user decides to bind a different keystroke to
universal-argument?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to detect C-u supplied arguments from other prefix arguments
2007-08-09 4:04 ` Barry Margolin
@ 2007-08-09 6:52 ` Dieter Wilhelm
0 siblings, 0 replies; 9+ messages in thread
From: Dieter Wilhelm @ 2007-08-09 6:52 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin <barmar@alum.mit.edu> writes:
> In article <1186576048.530383.47680@q75g2000hsh.googlegroups.com>,
> dieter.wilhelm@googlemail.com wrote:
>
>> On 8 ao?t, 13:55, bojohan+n...@dd.chalmers.se (Johan Bockg?rd) wrote:
>> > Dieter Wilhelm <die...@duenenhof-wilhelm.de> writes:
>> > > I'd like to detect whether prefix arguments of a command are supplied
>> > > by C-u or otherwise.
>> >
>> > > My idea is to use this-command-keys and compare it to some string,
>> > > like the following pseudo code:
>> >
>> > > (defun bla (arg)
>> > > (interactive "p")
>> > > (when (string= "C-u" (substring (this-command-keys) 0 2))
>> > > (message "hurray")))
>> >
>> > > I just don't understand how to compare key sequences.
>> >
>> > You want to check for the character ^U, not the three-character string
>> > `C - u'. Like
>> >
>> > (eq ?\C-u (aref (this-command-keys) 0))
>>
>> hurray it works, thanks a lot!
>> >
>> > (The whole idea seems a bit ugly though.)
>>
>> Why? In Emacs there are just too little short key combinations free.
>> I'd like to achieve
>> a switch for certain functions depending whether their arguments ARG
>> are supplied by C-u or not.
>>
>> For example: M-d might kill ARG word with the following boundary/
>> whitespace or without,
>> or C-t might drag a character ARG chars away and in the other case
>> merely transpose neighbouring chars some ARG chars away.
>
> And what if the user decides to bind a different keystroke to
> universal-argument?
True, from this point of view it's a very bad idea, C-u would be not
customisable any longer. But I think it's only a marginal problem and
on the other hand I feel the need to expand the Emacs key-binding
space, this is my only idea so far and I will test its feasibility.
Thanks
--
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to detect C-u supplied arguments from other prefix arguments
[not found] <mailman.4504.1186523154.32220.help-gnu-emacs@gnu.org>
2007-08-08 11:55 ` Johan Bockgård
@ 2007-08-09 17:49 ` Stefan Monnier
2007-08-09 20:16 ` Dieter Wilhelm
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2007-08-09 17:49 UTC (permalink / raw)
To: help-gnu-emacs
> I'd like to detect whether prefix arguments of a command are supplied
> by C-u or otherwise.
> My idea is to use this-command-keys and compare it to some string,
> like the following pseudo code:
> (defun bla (arg)
> (interactive "p")
Use (interactive "P") and then `arg' will have different shapes in the
different cases: either nil, or a number (if entered via C-u N1 N2 N3, or
via C-N1 C-N2 C-N3), or a one-element list containing a number 4^N if
entered via sequence of N times C-u.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to detect C-u supplied arguments from other prefix arguments
2007-08-09 17:49 ` Stefan Monnier
@ 2007-08-09 20:16 ` Dieter Wilhelm
0 siblings, 0 replies; 9+ messages in thread
From: Dieter Wilhelm @ 2007-08-09 20:16 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> I'd like to detect whether prefix arguments of a command are supplied
>> by C-u or otherwise.
>
>> My idea is to use this-command-keys and compare it to some string,
>> like the following pseudo code:
>
>> (defun bla (arg)
>> (interactive "p")
>
> Use (interactive "P") and then `arg' will have different shapes in the
> different cases: either nil, or a number (if entered via C-u N1 N2 N3, or
> via C-N1 C-N2 C-N3), or a one-element list containing a number 4^N
> if
By the way C-N1 N2 N3 works as well as C-N1 C-N2 ...
> entered via sequence of N times C-u.
Sorry, I wasn't precise, I meant to distinguish also when supplying
numbers: Between C-u furnished and C- or M- furnished prefix arguments.
I'll work now with the hint from Johan Bockgård
(eq ?\C-u (aref (this-command-keys) 0))
Thanks
--
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-08-09 20:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-07 21:46 How to detect C-u supplied arguments from other prefix arguments Dieter Wilhelm
2007-08-08 5:06 ` Kevin Rodgers
[not found] ` <mailman.4513.1186549602.32220.help-gnu-emacs@gnu.org>
2007-08-08 8:32 ` dieter.wilhelm
[not found] <mailman.4504.1186523154.32220.help-gnu-emacs@gnu.org>
2007-08-08 11:55 ` Johan Bockgård
2007-08-08 12:27 ` dieter.wilhelm
2007-08-09 4:04 ` Barry Margolin
2007-08-09 6:52 ` Dieter Wilhelm
2007-08-09 17:49 ` Stefan Monnier
2007-08-09 20:16 ` Dieter Wilhelm
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).