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

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

RE: How to simulate pressing a key


From: Drew Adams
Subject: RE: How to simulate pressing a key
Date: Fri, 19 Sep 2008 23:19:23 -0700

> >> I can not just call the function which key is binding for it may
> >> have uncertainty parameter, like tab's function forward-button has
> >> parameter, but lisp-indent-line does not.
> >> 
> >> although execute-extended-command works perfect, but I can not use
> >> it in my elisp function.
> >
> > I'm not sure I understand your question, but if I do, have 
> > a look at function `call-interactively'. It lets you call an
> > interactive function (command) in such a way that the function's
> > `interactive' spec is used to obtain the argument values.
> >
> > See the Elisp manual, node `Interactive Call'.
> 
> Thanks for your reply.
> 
> I do not want to interactive call a function but call it like 
> pressing a key. for example, press tab in help-mode will cause
> forward-button function which has a parameter, however I do
> not need give it parameter and it get parameter by itself.

Sorry, I'm unable to follow you. Hopefully someone else will understand and
answer you.

> my aim is to binding a funtion to tab key in every mode: if 
> cursor is at the end of word then call M-TAB's function, else
> call TAB's function.
> 
> (defun my-indent-or-complete ()
>    "if cursor is at 
>    the end of word then call M-TAB's function, else call 
> TAB's function."
>   (interactive)
>   ;; ^C^t is binding to tab key's function in mode-hook.
>   (let ((TAB-func (key-binding "^C^t"))
>           (M-TAB-func (key-binding "\M-\t")))
>    (if (looking-at "\\>")
>           (apply M-TAB-func '())
>         (apply TAB-func '()))))
> 
> my way is only suitable for lisp-indent-line but not forward-button.

As you said, `forward-button' expects at least one argument, and you are
applying it to zero arguments. Above, you say "it get parameter by itself". It's
unclear to me what you mean by that. 

Calling the command interactively (call-interactively #'button) will provide the
needed arguments (by default, N=1, WRAP=(point), DISPLAY-MESSAGE=(point), which
I think will do just what you want - but you say you don't want that.

Again, perhaps someone else can help you better.

Also, it sounds like you are trying to do something that several others have
already done. Take a look here and see if you don't find what you're looking for
already made: http://www.emacswiki.org/cgi-bin/wiki/TabCompletion

[BTW, you don't need to quote nil: '(). () evaluates to itself.]






reply via email to

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