I understand that this is trivial with an if, but is there an option, like
%s that interpolates nil as no string at all?
(format "%?.el" nil) ; ".el" (format "%?.el" "beginner") ; "beginner.el"
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
The special form
or is useful here. This macro returns the value of the first argument, unless it's nil in which case it returns the second. So, assuming the variable you want to check is
foo, the following will do what you want:
(format "%s.el" (or foo ""))
In some ways it's better than a magic tag since it makes it clear what value should be returned if the argument is nil.