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

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

macroexpansion and (function ...)


From: Faried Nawaz
Subject: macroexpansion and (function ...)
Date: 10 Jul 2003 14:49:02 -0700

Hello,

I have a macro, and it's not working the way I think it should.  Here's my code:

(defvar trigger-table nil)

(defun say-something (msg)
  (save-excursion
    (set-buffer "output")
    (insert (concat msg "\n"))))

(defun add-to-table (name func regex)
  (setq trigger-table (cons (list name func regex) trigger-table)))

; apologies for the formatting
(defmacro trigger-register (name regex response-fn response-string)
  `(add-to-table ,name
                 (function (lambda () (,response-fn ,response-string)))
                 ,regex))

Now, if I eval it manually, it does the right thing:

(trigger-register "trig1" "[Ee]macs" say-something "you said emacs!")
=> (("trig1" (lambda nil (say-something "you said emacs!")) "[Ee]macs"))

However, this produces weird results:

(for-each
 (lambda (triglist)
   (trigger-register
    (first triglist)
    (second triglist)
    say-something
    (third triglist)))
 '(("trig2" "[Xx]emacs" "you said xemacs!")
   ("trig3" "vi"        "vi vi vi")))
=> nil

trigger-table
=> (("trig3" (lambda nil (say-something (third triglist))) "vi")
    ("trig2" (lambda nil (say-something (third triglist))) "[Xx]emacs")
    ("trig1" (lambda nil (say-something "you said emacs!")) "[Ee]macs"))

Why do I have (third triglist) in there instead of the messages?


Faried.


reply via email to

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