let set_mode v args =
  let len = Array.length args in
  if len > 0 then
    let name = args.(0) in
    try
      match Ed_misc.no_blanks name with
        "" -> v#set_mode None
      | _ -> v#set_mode (Some (get_mode name))
    with
      Failure s->
        Ed_misc.error_message s
  else
    let f mode =
      let com = Printf.sprintf "%s_set_mode %s"
        factory_name (Filename.quote mode)
      in
      Cam_commands.eval_command com
    in
    Ed_misc.select_string ~history: mode_history
      v#minibuffer
      ~title: "Mode"
      ~choices: (available_mode_names ())
      ""
      f