File: .lake/packages/batteries/Batteries/Tactic/PermuteGoals.lean

full_name: Batteries.Tactic.splitGoalsAndGetNth
code: /--
If the current goals are `g₁ ⋯ gᵢ ⋯ gₙ`, `splitGoalsAndGetNth i` returns
`(gᵢ, [g₁, ⋯, gᵢ₋₁], [gᵢ₊₁, ⋯, gₙ])`.

If `reverse` is passed as `true`, the `i`-th goal is picked by counting backwards.
For instance, `splitGoalsAndGetNth 1 true` puts the last goal in the first component
of the returned term.
-/
def splitGoalsAndGetNth (nth : Nat) (reverse : Bool := false) :
    TacticM (MVarId × List MVarId × List MVarId) 
goal: Lean.Elab.Tactic.TacticM (Lean.MVarId × List Lean.MVarId × List Lean.MVarId)

full_name: Batteries.Tactic.«tacticPick_goal-_»
code: /--
`pick_goal n` will move the `n`-th goal to the front.

`pick_goal -n` will move the `n`-th goal (counting from the bottom) to the front.

See also `Tactic.rotate_goals`, which moves goals from the front to the back and vice-versa.
-/
elab "pick_goal " reverse:"-"? n:num : tactic => do
  let (g, gl, gr) ← splitGoalsAndGetNth n.1.toNat !reverse.isNone
  setGoals $ g :: (gl ++ gr)
goal: Lean.ParserDescr

full_name: Batteries.Tactic.«_aux_.lake_packages_batteries_Batteries_Tactic_PermuteGoals___elabRules_Batteries_Tactic_tacticPick_goal-__1»
code: /--
`pick_goal n` will move the `n`-th goal to the front.

`pick_goal -n` will move the `n`-th goal (counting from the bottom) to the front.

See also `Tactic.rotate_goals`, which moves goals from the front to the back and vice-versa.
-/
elab "pick_goal " reverse:"-"? n:num : tactic => do
  let (g, gl, gr) ← splitGoalsAndGetNth n.1.toNat !reverse.isNone
  setGoals $ g :: (gl ++ gr)
goal: Lean.Elab.Tactic.Tactic

full_name: Batteries.Tactic.tacticSwap
code: macro "swap" : tactic => `(tactic| pick_goal 2)
goal: Lean.ParserDescr

full_name: Batteries.Tactic.«_aux_.lake_packages_batteries_Batteries_Tactic_PermuteGoals___macroRules_Batteries_Tactic_tacticSwap_1»
code: macro "swap" : tactic => `(tactic| pick_goal 2)
goal: Lean.Macro

full_name: Batteries.Tactic.«tacticOn_goal-_=>_»
code: /--
`on_goal n => tacSeq` creates a block scope for the `n`-th goal and tries the sequence
of tactics `tacSeq` on it.

`on_goal -n => tacSeq` does the same, but the `n`-th goal is chosen by counting from the
bottom.

The goal is not required to be solved and any resulting subgoals are inserted back into the
list of goals, replacing the chosen goal.
-/
elab "on_goal " reverse:"-"? n:num " => " seq:tacticSeq : tactic => do
  let (g, gl, gr) ← splitGoalsAndGetNth n.1.toNat !reverse.isNone
  setGoals [g]
  evalTactic seq
  setGoals $ gl ++ (← getUnsolvedGoals) ++ gr
goal: Lean.ParserDescr

full_name: Batteries.Tactic.«_aux_.lake_packages_batteries_Batteries_Tactic_PermuteGoals___elabRules_Batteries_Tactic_tacticOn_goal-_=>__1»
code: /--
`on_goal n => tacSeq` creates a block scope for the `n`-th goal and tries the sequence
of tactics `tacSeq` on it.

`on_goal -n => tacSeq` does the same, but the `n`-th goal is chosen by counting from the
bottom.

The goal is not required to be solved and any resulting subgoals are inserted back into the
list of goals, replacing the chosen goal.
-/
elab "on_goal " reverse:"-"? n:num " => " seq:tacticSeq : tactic => do
  let (g, gl, gr) ← splitGoalsAndGetNth n.1.toNat !reverse.isNone
  setGoals [g]
  evalTactic seq
  setGoals $ gl ++ (← getUnsolvedGoals) ++ gr
goal: Lean.Elab.Tactic.Tactic