bbatsov / emacs-lisp-style-guide

A community-driven Emacs Lisp style guide
1.08k stars 53 forks source link

Determining arguments to interactive functions #51

Open vermiculus opened 5 years ago

vermiculus commented 5 years ago

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.

Fuco1 commented 5 years ago

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.

bbatsov commented 5 years ago

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