Re:VS Code can do that?
by xfer on Saturday April 21, 2018 @04:55PM
(#16893391)
Or you could write a macro?
[ Parent
| on HN ]
Re:VS Code can do that?
by staticassertion on Saturday April 21, 2018 @06:49PM
(#16893790)
That sounds like considerably more work.
In Vim (on Unix), type this into the buffer
for x in type1 type2 type3 type4 type5 type6 ; do
cat <<!
impl Into<$x> for ProcessNode {
fn into(self) -> $x {
$x {some_boilerplate(self)}
}
}
!
done
Now do a line-oriented visual select of all the lines from for to done (using V + cursor movements). Then pipe to shell with !sh[Enter].Poof! The above is replaced with the following:
impl Into<type1> for ProcessNode {
fn into(self) -> type1 {
type1 {some_boilerplate(self)}
}
}
impl Into<type2> for ProcessNode {
fn into(self) -> type2 {
type2 {some_boilerplate(self)}
}
}
impl Into<type3> for ProcessNode {
fn into(self) -> type3 {
type3 {some_boilerplate(self)}
}
}
impl Into<type4> for ProcessNode {
fn into(self) -> type4 {
type4 {some_boilerplate(self)}
}
}
impl Into<type5> for ProcessNode {
fn into(self) -> type5 {
type5 {some_boilerplate(self)}
}
}
impl Into<type6> for ProcessNode {
fn into(self) -> type6 {
type6 {some_boilerplate(self)}
}
}
Don't write in some insane boilerplate-driven programming language in the first place. Anyone proliferating this kind of duplication (whether with multi-cursors or shell here docs or any other way) should be flogged.