[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function evaluated, but cannot execute
From: |
ken |
Subject: |
Re: function evaluated, but cannot execute |
Date: |
Tue, 26 Apr 2011 18:17:59 -0400 |
User-agent: |
Thunderbird 2.0.0.24 (X11/20101213) |
On 04/26/2011 05:48 PM PJ Weisberg wrote:
> On Tuesday, April 26, 2011, ken <gebser@mousecar.com> 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'.
>
Thanks for the tip. Yeah, for some reason get-buffer-create fails, does
nothing. Replacing it with find-file or *-select works fine. Strange
because I scarfed the code from an emacs Info page and the *Help* page
says get-buffer-create will accept a file as an arg. I'll just say,
"That's perplexing."
thanks++,
ken
--
Anything is easy if you know how to do it.