Function: commandp

commandp is a function defined in eval.c.

Signature

(commandp FUNCTION &optional FOR-CALL-INTERACTIVELY)

Documentation

Non-nil if FUNCTION makes provisions for interactive calling.

This means it contains a description for how to read arguments to give it. The value is nil for an invalid function or a symbol with no function definition.

Interactively callable functions include strings and vectors (treated as keyboard macros), lambda-expressions that contain a top-level call to interactive, autoload definitions made by autoload with non-nil fourth argument, and some of the built-in functions of Lisp.

Also, a symbol satisfies commandp if its function definition does so.

If the optional argument FOR-CALL-INTERACTIVELY is non-nil, then strings and vectors are not accepted.

Probably introduced at or before Emacs version 22.1.

Source Code

// Defined in /usr/src/emacs/src/eval.c
{
  register Lisp_Object fun;
  register Lisp_Object funcar;
  Lisp_Object if_prop = Qnil;

  fun = function;

  fun = indirect_function (fun); /* Check cycles.  */
  if (NILP (fun))
    return Qnil;

  /* Check an `interactive-form' property if present, analogous to the
     function-documentation property.  */
  fun = function;
  while (SYMBOLP (fun))
    {
      Lisp_Object tmp = Fget (fun, Qinteractive_form);
      if (!NILP (tmp))
	if_prop = Qt;
      fun = Fsymbol_function (fun);
    }

  /* Emacs primitives are interactive if their DEFUN specifies an
     interactive spec.  */
  if (SUBRP (fun))
    return XSUBR (fun)->intspec ? Qt : if_prop;

  /* Bytecode objects are interactive if they are long enough to
     have an element whose index is COMPILED_INTERACTIVE, which is
     where the interactive spec is stored.  */
  else if (COMPILEDP (fun))
    return (PVSIZE (fun) > COMPILED_INTERACTIVE ? Qt : if_prop);

#ifdef HAVE_MODULES
  /* Module functions are interactive if their `interactive_form'
     field is non-nil. */
  else if (MODULE_FUNCTIONP (fun))
    return NILP (module_function_interactive_form (XMODULE_FUNCTION (fun)))
             ? if_prop
             : Qt;
#endif

  /* Strings and vectors are keyboard macros.  */
  if (STRINGP (fun) || VECTORP (fun))
    return (NILP (for_call_interactively) ? Qt : Qnil);

  /* Lists may represent commands.  */
  if (!CONSP (fun))
    return Qnil;
  funcar = XCAR (fun);
  if (EQ (funcar, Qclosure))
    return (!NILP (Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun)))))
	    ? Qt : if_prop);
  else if (EQ (funcar, Qlambda))
    return !NILP (Fassq (Qinteractive, Fcdr (XCDR (fun)))) ? Qt : if_prop;
  else if (EQ (funcar, Qautoload))
    return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun))))) ? Qt : if_prop;
  else
    return Qnil;
}