class Rufo::Formatter

def visit_when(node)

def visit_when(node)
  # [:when, conds, body, next_exp]
  _, conds, body, next_exp = node
  consume_keyword "when"
  consume_space
  indent(@column) do
    visit_comma_separated_list conds
    skip_space
  end
  then_keyword = keyword?("then")
  inline = then_keyword || semicolon?
  if then_keyword
    next_token
    skip_space
    track_case_when
    skip_semicolons
    if newline? || comment?
      inline = false
      # Cancel tracking of `case when ... then` on a nelwine.
      @case_when_positions.pop
    else
      write " then "
    end
  elsif semicolon?
    skip_semicolons
    if newline? || comment?
      inline = false
    else
      write ";"
      track_case_when
      write " "
    end
  end
  if inline
    indent do
      visit_exps body
    end
  else
    indent_body body
  end
  if next_exp
    write_indent
    if next_exp[0] == :else
      # [:else, body]
      consume_keyword "else"
      skip_space
      if newline? || semicolon? || comment?
        indent_body next_exp[1]
      else
        write_space
        visit_exps next_exp[1]
      end
    else
      visit next_exp
    end
  end
end