all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* function evaluated, but cannot execute
@ 2011-04-26 21:25 ken
  2011-04-26 21:35 ` Drew Adams
  2011-04-26 21:48 ` PJ Weisberg
  0 siblings, 2 replies; 4+ messages in thread
From: ken @ 2011-04-26 21:25 UTC (permalink / raw
  To: GNU Emacs List

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


-- 
Anything is easy if you know how to do it.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: function evaluated, but cannot execute
  2011-04-26 21:25 function evaluated, but cannot execute ken
@ 2011-04-26 21:35 ` Drew Adams
  2011-04-26 21:48 ` PJ Weisberg
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2011-04-26 21:35 UTC (permalink / raw
  To: gebser, 'GNU Emacs List'

> But when I do "M-x my-prepend-to-file RET", emacs responds 
> "[No match]".  So what's wrong?

This might be the #1 FAQ. You need an `interactive' spec to turn your function
into a command (interactive function).  See the Elisp manual, node `Using
Interactive'.

Consider also reading the integrated manual "An Introduction to Programming in
Emacs Lisp" (Emacs Lisp Intro). It will help greatly with things like this.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function evaluated, but cannot execute
  2011-04-26 21:25 function evaluated, but cannot execute ken
  2011-04-26 21:35 ` Drew Adams
@ 2011-04-26 21:48 ` PJ Weisberg
  2011-04-26 22:17   ` ken
  1 sibling, 1 reply; 4+ messages in thread
From: PJ Weisberg @ 2011-04-26 21:48 UTC (permalink / raw
  To: gebser@mousecar.com; +Cc: GNU Emacs List

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'.

-- 

-PJ



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function evaluated, but cannot execute
  2011-04-26 21:48 ` PJ Weisberg
@ 2011-04-26 22:17   ` ken
  0 siblings, 0 replies; 4+ messages in thread
From: ken @ 2011-04-26 22:17 UTC (permalink / raw
  To: PJ Weisberg; +Cc: GNU Emacs List

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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-26 22:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26 21:25 function evaluated, but cannot execute ken
2011-04-26 21:35 ` Drew Adams
2011-04-26 21:48 ` PJ Weisberg
2011-04-26 22:17   ` ken

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.