emacs-lisp-style-guide icon indicating copy to clipboard operation
emacs-lisp-style-guide copied to clipboard

Determining arguments to interactive functions

Open vermiculus opened this issue 7 years ago • 2 comments

Is there any prevailing wisdom on when to use the (interactive (list ...)) form over the body code (setq arg-1 (or arg-1 (get-default))? Personally I prefer (and more often see) the former, but I've realized I have no good reasoning either way.

vermiculus avatar Sep 21 '18 18:09 vermiculus

If the mandatory argument can be worked out with the interactive code letters I prefer that and set the optional args in the body. So if I have (beg end &optional flag) then I would use (interactive "r") because that's probably the intended semantics.

I would never set optional args in the interactive form if they are not for interactive use. If they are some flags which can be determined during interactive use I would prefer the list spec except when it would be overly complicated (then I would prefer simple code letters/prompts and the logic in the body).

I understand my answer is pretty vague :D But a definitive rule for me is: never use the interactive list spec if non-interactive use-case can run through it.

Fuco1 avatar Sep 21 '18 20:09 Fuco1

@Fuco1 Seems to me you want to write the rule about this in the guide. ;-)

bbatsov avatar Sep 22 '18 08:09 bbatsov