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

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

Re: calling similar function


From: Giorgos Keramidas
Subject: Re: calling similar function
Date: Sat, 08 Jul 2006 07:07:30 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (berkeley-unix)

On 7 Jul 2006 19:54:54 -0700, "scm" <scm.info.search@gmail.com> wrote:
> Greetings,
>
> I was wondering if someone could shed some light on how I could call an
> interactive function by another interactive function. I want to do this
> to save on some coding, as the two functions are identical except their
> names.
>
> Here is the function I want to call:
>
> (defun list (command)
>   (interactive "sCommand> ")
>     (if (string-match "ls" command)
>         (shell-command "ls")))

Don't use `list' as a function name.  (list ...) is already an Emacs
Lisp function, which is used in hundreds of places, and you are probably
breaking all those places by redefining it to have completely different
semantics.

> Here is my attempt at coding an interactive calling function.
>
> (defun list-foo ()
>   (interactive)
>   (list))
>
> I want to be able to M-x list-foo and have list be called.

You can use `defalias' for this:

    (defun list-files (command)
        (interactive "sCommand> ")
        (if (string-match "ls" command)
            (shell-command "ls")))
    
    (defalias 'my-list 'list-files)



reply via email to

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