Due to my lazy nature, I made something like this:
(defmacro iλ (x)
`(lambda () (interactive) ,x))
(defmacro iλd (x y)
`(lambda () ,x (interactive) ,y))
(global-set-key (kbd "<f8>") (iλ (message "hello lambdas")))
(global-set-key (kbd "<f7>") (iλd "Func Docu" (message "hello lambda with docus")))
Due to my lazy nature, I would like to merge these two but it's 10:16pm in the evening and I can't seem to figure it out. I would like something like this (Pseudo code follows):
(defmacro iλ (x &optional y) ;y is optional parameter:
if x & y are defined:
`(lambda () ,x (interactive) ,y))
else if only x is defined:
`(lambda () (interactive) ,y)
)
Can this be done, if so how?
[edit solution] As per Malabarba's answer below, I now use the clever bit of code:
(defmacro iλ (x &rest y)
(if (and (stringp x) y)
`(lambda () ,x (interactive) ,@y)
`(lambda () (interactive) ,x ,@y)))
;Example usage:
(global-set-key (kbd "<f8>") (iλ "A message that prints a hello" (message "hello 2")))
(global-set-key (kbd "<f9>") (iλ (message "hello 1")))
&rest
? What if you then write(iλ x &x)
?(x &optional y)
thank you for pointing this out.