unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Need help with a simple macro to define a new function
@ 2007-11-15 19:47 Lennart Borgman (gmail)
  2007-11-15 19:52 ` Davis Herring
  0 siblings, 1 reply; 3+ messages in thread
From: Lennart Borgman (gmail) @ 2007-11-15 19:47 UTC (permalink / raw)
  To: Emacs Devel

Can someone please explain how to write this:

(defmacro new-defun (function)
   (declare (doc-string 3))
   (let* ((name (symbol-name function))
          (new-name (concat "new-" name))
          (new-sym (make-symbol new-name)))
     `(defun ,new-sym ()
        (interactive)
        (message "new function")(sit-for 2)
        (call-interactively ,function))))

(new-defun forward-char)

I expected a new function named new-forward-char, but that did not happen.

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

* Re: Need help with a simple macro to define a new function
  2007-11-15 19:47 Need help with a simple macro to define a new function Lennart Borgman (gmail)
@ 2007-11-15 19:52 ` Davis Herring
  2007-11-15 20:01   ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 3+ messages in thread
From: Davis Herring @ 2007-11-15 19:52 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

>           (new-sym (make-symbol new-name)))

Surely you want the new symbol to be interned, so that it can be read? 
Then you want (intern new-name).  (This also allows you to re-use an
existing "new-foo" symbol if it exists, which again you surely want.)

> I expected a new function named new-forward-char, but that did not happen.

What happened instead?  Perhaps you simply mean that (fboundp
'new-forward-char) was nil afterwards, which would be a result of your
uninterned symbol.  But maybe you mean something else?

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

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

* Re: Need help with a simple macro to define a new function
  2007-11-15 19:52 ` Davis Herring
@ 2007-11-15 20:01   ` Lennart Borgman (gmail)
  0 siblings, 0 replies; 3+ messages in thread
From: Lennart Borgman (gmail) @ 2007-11-15 20:01 UTC (permalink / raw)
  To: herring; +Cc: Emacs Devel

Davis Herring wrote:
>>           (new-sym (make-symbol new-name)))
> 
> Surely you want the new symbol to be interned, so that it can be read? 
> Then you want (intern new-name).  (This also allows you to re-use an
> existing "new-foo" symbol if it exists, which again you surely want.)


Thanks, that was the problem.

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

end of thread, other threads:[~2007-11-15 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-15 19:47 Need help with a simple macro to define a new function Lennart Borgman (gmail)
2007-11-15 19:52 ` Davis Herring
2007-11-15 20:01   ` Lennart Borgman (gmail)

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).