Add several macros to format Golang code and comment/uncomment and indent/unindent code blocks.
# ~/.local/share/mc/mc.macros
[editor]
ctrl-alt-f = ExecuteScript:0
ctrl-c = ExecuteScript:1
ctrl-alt-c = ExecuteScript:2
ctrl-tab = ExecuteScript:3
ctrl-shift-tab = ExecuteScript:4
# ~/.local/share/mc/mcedit/macros.d/macro.0.sh
u gofmt
echo 'Formatting %f'
go fmt "%f"
# ~/.local/share/mc/mcedit/macros.d/macro.1.sh
c comment
TMPFILE=$(mktemp ${MC_TMPDIR:-/tmp}/comment.XXXXXX) || exit 1
EXT=$(echo %f | sed 's/.*\.//')
cat %b > $TMPFILE
if [[ $EXT == 'go' ]]; then
cat $TMPFILE | sed 's,^,// ,' > %b
else
cat $TMPFILE | sed 's/^/# /' > %b
fi
rm -f $TMPFILE
# ~/.local/share/mc/mcedit/macros.d/macro.2.sh
u uncomment
TMPFILE=`mktemp ${MC_TMPDIR:-/tmp}/uncomment.XXXXXX` || exit 1
EXT=$(echo %f | sed 's/.*\.//')
cat %b > $TMPFILE
if [[ $EXT == 'go' ]]; then
cat $TMPFILE | sed 's,^// ,,' > %b
else
cat $TMPFILE | sed 's/^# //' > %b
fi
rm -f $TMPFILE
# ~/.local/share/mc/mcedit/macros.d/macro.3.sh
i indent
TMPFILE=`mktemp ${MC_TMPDIR:-/tmp}/indent.XXXXXX` || exit 1
EXT=$(echo %f | sed 's/.*\.//')
cat %b > $TMPFILE
if [[ $EXT == 'go' ]]; then
cat $TMPFILE | sed -E 's/^([^$])/\t\1/' > %b
else
cat $TMPFILE | sed -E 's/^([^$])/ \1/' > %b
fi
rm -f $TMPFILE
# ~/.local/share/mc/mcedit/macros.d/macro.4.sh
u unindent
TMPFILE=`mktemp ${MC_TMPDIR:-/tmp}/unindent.XXXXXX` || exit 1
EXT=$(echo %f | sed 's/.*\.//')
cat %b > $TMPFILE
if [[ $EXT == 'go' ]]; then
cat $TMPFILE | sed 's/^\t//' > %b
else
cat $TMPFILE | sed 's/^\ \ //' > %b
fi
rm -f $TMPFILE