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

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

Re: function evaluated, but cannot execute


From: PJ Weisberg
Subject: Re: function evaluated, but cannot execute
Date: Tue, 26 Apr 2011 14:48:39 -0700

On Tuesday, April 26, 2011, ken <address@hidden> wrote:
> Testing little function to learn from...
>
> (defun my-prepend-to-file ()
>   "Prepend some hard-coded text to specified file."
>   (let ((oldbuf (current-buffer)))
>     (save-current-buffer
>       (set-buffer (get-buffer-create "/home/zl/tmp/test.html"))
>       (insert "\n\nText inserted by my-prepend-to-file.\n\n"))))
>
> I evaluate this function.  No problem.
>
> I do "C-h f my-prepend-to-file RET", emacs displays in the other window:
>
> my-prepend-to-file is a Lisp function.
>
> (my-prepend-to-file)
>
> Prepend some hard-coded text to specified file.
>
> [back]
>
> But when I do "M-x my-prepend-to-file RET", emacs responds "[No match]".
>  So what's wrong?
>
>
> tia,
> ken

Right after the docstring, put (interactive).  (If the function took
arguments you would have to put more stuff inside the 'interactive'
form, but that's enough to be able to call it from M-x or with a
keybinding.

And you want 'find-file' or 'find-file-noselect' instead of 'get-buffer-create'.

-- 

-PJ



reply via email to

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