Algorithm for parts integration

You can specify the cases for when $u$ and $v$ are free of variable.

ByParts[u_, v_, t_] := 
 With[{w = Integrate[v, t]}, u w - Integrate[D[u, t] w, t]]
ByParts[u_, v_, t_] := u Integrate[v, t] /; FreeQ[u, t]
ByParts[u_, v_, t_] := v Integrate[u, t] /; FreeQ[v, t]

I think I can answer my question.

Mathematically, it makes sense to tell Mma which variable is the one to integrate by parts, like LaplaceTransform or D. Taking this into account, I redefine parts like this

parts[u_,v_,{x_,n_}]:= Sum[(-1)^m D[u,{x,m}] Nest[Integrate[#,x]&,v,m+1],{m,0,n-1}] +
        (-1)^n Integrate[D[u,{x,n}] Nest[Integrate[#,x]&,v,n],x]

Again, I believe is rather amateurish, and I'd appreciate comments and other answers.