The issue with the code turns out to be a facet of how macros work. This macro accepts a parameter num
, but based on macro eval rules, num
itself is actually the original symbol you passed into the function since macro arguments are never evaluated before they are given to the macro body.
With backquoting you can extract the actual value of num
, but you won’t be able to do it for the intern
call because it’s being evaluated in the macro expansion pass (no access to the value of num
). You would need to pass a number literal in for num
for this to work, and that’s why your manual invocations were working.
(defmacro ct/tab-bar-select-action-define (num)
`(defun ,(intern (format "ct/tab-bar-select-%d" num)) ()
,(format "Select tab %d by its absolute number." num)
(interactive)