all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* calling similar function
@ 2006-07-08  2:54 scm
  2006-07-08  4:07 ` Giorgos Keramidas
  2006-07-08  4:11 ` Drew Adams
  0 siblings, 2 replies; 3+ messages in thread
From: scm @ 2006-07-08  2:54 UTC (permalink / raw)


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

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.

Thanks in advance to anyone who has the time to lend to this question.

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

* Re: calling similar function
  2006-07-08  2:54 calling similar function scm
@ 2006-07-08  4:07 ` Giorgos Keramidas
  2006-07-08  4:11 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Giorgos Keramidas @ 2006-07-08  4:07 UTC (permalink / raw)


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)

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

* RE: calling similar function
  2006-07-08  2:54 calling similar function scm
  2006-07-08  4:07 ` Giorgos Keramidas
@ 2006-07-08  4:11 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Drew Adams @ 2006-07-08  4:11 UTC (permalink / raw)


    how I could call an interactive function by another
    interactive function. Here is the function I want to call:

    (defun list (command)
      (interactive "sCommand> ")
        (if (string-match "ls" command)
            (shell-command "ls")))

You don't want to redefine the function `list'; believe me, you do *not*
want to do that ;-). Call it `my-ls' or `je!iov??%moiyp', but not `list'.

    (defun list-foo () (interactive)(list))

That works (after renaming `list') - it calls `my-ls'.

Now, if you want to have list-foo call `my-ls' *interactively*, so that it
reads the command, then you need to use (call-interactively 'my-ls) instead
of just (my-ls).

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

end of thread, other threads:[~2006-07-08  4:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-08  2:54 calling similar function scm
2006-07-08  4:07 ` Giorgos Keramidas
2006-07-08  4:11 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.