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

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

Re: Passing arguments to functions


From: Perry Smith
Subject: Re: Passing arguments to functions
Date: Tue, 22 Feb 2011 09:55:19 -0600

Let me take a stab at this.  This reply is good but I think the
user might be asking from the perspective of using emacs
instead of writing lisp code.

On Feb 22, 2011, at 8:13 AM, Drew Adams wrote:

- How do I pass arguments to a function call? i.e. if I do "M-x
some-function" and "some-function" takes optional arguments,
how do I pass those arguments to the function call?

There are two types of functions.  I may be mistaken but I think
some parts of Emacs' documentation refers to "commands" and
"functions".  In any case, some functions are "interactive" and
some are not.  For example:

isearch-forward is an interactive compiled Lisp function in
`isearch.el'.

verses

replace-match is a built-in function in `C source code'.

An interactive function uses optional arguments and prefix argument.
An interactive function is a super-set in the sense that you can call
an interactive function just like a function.  e.g. I could call:

(isearch-forward "pattern")

To get a complete gist of interactive functions, do a help on
"interactive" and it will describe how an interactive function
takes it arguments.  There are many options.

If a function is not interactive, then you can not call it via M-x.  You
can do M-: (Meta-colon) in which case you can type in a lisp
s expressions and hit return and have it evaluated.


If you are writing the function, then you do this using an `interactive' spec.
`C-h i m elisp m using interactive'.

If you are not writing the function yourself, and it has no `interactive' spec,
and it does not use the universal argument (`C-u') in any conditional way, then
you're (almost) out of luck.  In that case, you can use `M-: (function arg 1
arg2...)' or define your own command (function with an interactive spec) that
takes care of the arguments and then calls the ready-made function.

- Also, why is it that "C-h f function-name" will document
some functions, but when I type "M-x function-name" it says
[no match]?

`M-x' is for commands, that is, interactive functions, that is, functions that
have an `interactive' spec.  `[no match]' tells you that the function is not a
command.

You will help yourself if you take a look at the doc.  Start with the Emacs
manual, but the Elisp manual is helpful for writing your own functions
(including commands).  See also the `Emacs Lisp Intro' manual.

Hope this helps
Perry


reply via email to

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