From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: defining functions in emacs Date: 25 Jan 2006 19:09:10 +1100 Message-ID: <87y814raop.fsf@tiger.rapttech.com.au> References: Reply-To: timx@spamto.devnul.com NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1138176755 9901 80.91.229.2 (25 Jan 2006 08:12:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 25 Jan 2006 08:12:35 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 25 09:12:33 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F1flX-0005Wj-6V for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Jan 2006 09:12:31 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F1foG-0005tW-Ek for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Jan 2006 03:15:20 -0500 Original-Newsgroups: gnu.emacs.help Original-Lines: 101 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Original-NNTP-Posting-Host: ppp7-56.lns1.syd7.internode.on.net Original-X-Trace: duster.adelaide.on.net 1138176551 59.167.7.56 (25 Jan 2006 18:39:11 +1050) Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!news.xtra.co.nz!news-south.connect.com.au!duster.adelaide.on.net!not-for-mail Original-Xref: shelby.stanford.edu gnu.emacs.help:137220 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:32841 Archived-At: Matt Brown 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!