unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Distinguishing interactive and non-interactive functions or  customizing `execute-extended-command'?
@ 2010-07-01  9:56 Elena
  2010-07-01 10:22 ` Teemu Likonen
  0 siblings, 1 reply; 3+ messages in thread
From: Elena @ 2010-07-01  9:56 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I'd like to have some interactive command of mine whose name would
conflict with existing non-interactive functions.

For instance, I'd like to define an interactive "sort" command which
would act accordingly to context. However, a non-interactive `sort'
function already exists and I think that redefining it should be my
last (ugly) resort. I'd just like to find a way to type `M-x sort RET'
and having my own `sort' command executed.

Unless there is a way to distinguish between interactive and non-
interactive functions (I don't think so), I think I could customize
`execute-extended-command', but it's defined in C source code, and I'd
prefer to stay on the Emacs Lisp side.

Any hints? Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Distinguishing interactive and non-interactive functions or customizing `execute-extended-command'?
  2010-07-01  9:56 Distinguishing interactive and non-interactive functions or customizing `execute-extended-command'? Elena
@ 2010-07-01 10:22 ` Teemu Likonen
  2010-07-01 11:22   ` Elena
  0 siblings, 1 reply; 3+ messages in thread
From: Teemu Likonen @ 2010-07-01 10:22 UTC (permalink / raw)
  To: help-gnu-emacs

* 2010-07-01 02:56 (-0700), Elena wrote:

> For instance, I'd like to define an interactive "sort" command which
> would act accordingly to context. However, a non-interactive `sort'
> function already exists and I think that redefining it should be my
> last (ugly) resort. I'd just like to find a way to type `M-x sort RET'
> and having my own `sort' command executed.

I don't recommend doing that but it should be possible with so called
"around-advices". The idea is that your "advice" code runs instead of
the original function and then you can decide to call the original
function according to some condition (if (called-interactively-p) ...).
See the Emacs Lisp manual and section 17 Advising Emacs Lisp Functions.

But I'd just choose a different name for such user-interface sort
command and perhaps bind it to a key if it's needed often.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Distinguishing interactive and non-interactive functions or  customizing `execute-extended-command'?
  2010-07-01 10:22 ` Teemu Likonen
@ 2010-07-01 11:22   ` Elena
  0 siblings, 0 replies; 3+ messages in thread
From: Elena @ 2010-07-01 11:22 UTC (permalink / raw)
  To: help-gnu-emacs

Thanks Teemu.

I've considered an around advice, however I'd like an easy falling
back to `execute-extended-command' whenever no completion is available
among my own commands. I don't think such a customization would be
disruptive: `sort', for instance, is a non-interactive function, thus
will be ignored by `execute-extended-command' anyway.

Maybe I should explore packages which provide customizable
alternatives to `execute-extended-command', like `anything'.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-01 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-01  9:56 Distinguishing interactive and non-interactive functions or customizing `execute-extended-command'? Elena
2010-07-01 10:22 ` Teemu Likonen
2010-07-01 11:22   ` Elena

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).