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

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

Re: Problems with keybindings for functions with arguments


From: Nicolas Richard
Subject: Re: Problems with keybindings for functions with arguments
Date: Fri, 08 Mar 2013 17:17:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.92 (gnu/linux)

Thorsten Jolitz <tjolitz@gmail.com> writes:

> So how can I make this a (interactive) command that takes one argument,
> but doesn't ask the user about it and does not force the user to give
> prefix-args all the time (like 'C-1' e.g.)?

you could rebind keys 1 to 8 to some helper function which would inspect
the key pressed. I must admit I have no idea how to do it right, but
this works:
(defun yf/test nil ""
  (interactive)
  (let (key)
    (setq key (with-temp-buffer (call-interactively 'self-insert-command)
                                (buffer-string)))
    (message "Key pressed: %s" key)))
(local-set-key "1" 'yf/test)
(local-set-key "2" 'yf/test)

> "f", "v", "x" etc, that can be called as is or like this (with numerical
> prefix args):
>
> "C-1 f", "C-2 f", ... , "C-3 f"

I guess (interactive "P") should allow you to do that.

-- 
N.




reply via email to

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