From: Tim X <timx@spamto.devnul.com>
Subject: Re: defining functions in emacs
Date: 25 Jan 2006 19:09:10 +1100 [thread overview]
Message-ID: <87y814raop.fsf@tiger.rapttech.com.au> (raw)
In-Reply-To: mailman.11.1138142928.2878.help-gnu-emacs@gnu.org
Matt Brown <mbrown83@ucsc.edu> writes:
> Hi everyone
>
> I wrote my first emacs function! Here's my function:
>
>
> (defun read-environment ()
> (setq outbuf (generate-new-buffer "read-environment-outbuf"))
> (call-process "read-environment.sh" nil outbuf nil)
> (eval-buffer outbuf)
> (kill-buffer outbuf))
>
> It uses read-environment.sh to generate a whole bunch of setenv lines,
> and then evaluates them. Basically, it sources .bashrc and sets the
> new variables in emacs. It works fine, but I want to be able to run
> it by
> M-x read-environment
>
> This doesn't work. I have to put
> (read-environment)
> into *scratch*, move to the ')' and do C-x C-e to evaluate it. Pretty lame.
>
> From the digging around I've done, it seems like it should just work.
> Any ideas? BTW, the defun is in my .emacs
>
> Thanks
> Matt
>
>
You need to include (interactive) in your defun
,----[ C-h f interactive RET ]
| interactive is a special form.
| (interactive ARGS)
|
| Specify a way of parsing arguments for interactive use of a function.
| For example, write
| (defun foo (arg) "Doc string" (interactive "p") ...use arg...)
| to make ARG be the prefix argument when `foo' is called as a command.
| The "call" to `interactive' is actually a declaration rather than a function;
| it tells `call-interactively' how to read arguments
| to pass to the function.
| When actually called, `interactive' just returns nil.
|
| The argument of `interactive' is usually a string containing a code letter
| followed by a prompt. (Some code letters do not use I/O to get
| the argument and do not need prompts.) To prompt for multiple arguments,
| give a code letter, its prompt, a newline, and another code letter, etc.
| Prompts are passed to format, and may use % escapes to print the
| arguments that have already been read.
| If the argument is not a string, it is evaluated to get a list of
| arguments to pass to the function.
| Just `(interactive)' means pass no args when calling interactively.
|
| Code letters available are:
| a -- Function name: symbol with a function definition.
| b -- Name of existing buffer.
| B -- Name of buffer, possibly nonexistent.
| c -- Character (no input method is used).
| C -- Command name: symbol with interactive function definition.
| d -- Value of point as number. Does not do I/O.
| D -- Directory name.
| e -- Parametrized event (i.e., one that's a list) that invoked this command.
| If used more than once, the Nth `e' returns the Nth parameterized event.
| This skips events that are integers or symbols.
| f -- Existing file name.
| F -- Possibly nonexistent file name.
| i -- Ignored, i.e. always nil. Does not do I/O.
| k -- Key sequence (downcase the last event if needed to get a definition).
| K -- Key sequence to be redefined (do not downcase the last event).
| m -- Value of mark as number. Does not do I/O.
| M -- Any string. Inherits the current input method.
| n -- Number read using minibuffer.
| N -- Raw prefix arg, or if none, do like code `n'.
| p -- Prefix arg converted to number. Does not do I/O.
| P -- Prefix arg in raw form. Does not do I/O.
| r -- Region: point and mark as 2 numeric args, smallest first. Does no I/O.
| s -- Any string. Does not inherit the current input method.
| S -- Any symbol.
| v -- Variable name: symbol that is user-variable-p.
| x -- Lisp expression read but not evaluated.
| X -- Lisp expression read and evaluated.
| z -- Coding system.
| Z -- Coding system, nil if no prefix arg.
| In addition, if the string begins with `*'
| then an error is signaled if the buffer is read-only.
| This happens before reading any arguments.
| If the string begins with `@', then Emacs searches the key sequence
| which invoked the command for its first mouse click (or any other
| event which specifies a window), and selects that window before
| reading any arguments. You may use both `@' and `*'; they are
| processed in the order that they appear.
`----
--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!
next parent reply other threads:[~2006-01-25 8:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.11.1138142928.2878.help-gnu-emacs@gnu.org>
2006-01-25 8:09 ` Tim X [this message]
2006-01-26 6:17 ` defining functions in emacs Barry Margolin
2006-01-24 21:40 Matt Brown
2006-01-24 23:13 ` Edward O'Connor
2006-01-25 16:02 ` Kevin Rodgers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y814raop.fsf@tiger.rapttech.com.au \
--to=timx@spamto.devnul.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.