#!/bin/bash

# Reindents the MATLAB source code files given in argument

[[ -n $1 ]] || { echo "Give filename(s) in argument" 2>&1; exit 1; }

pushd "$(dirname "$0")" > /dev/null
SCRIPTS_DIR=$(pwd)
popd > /dev/null

for f in "$@"; do
    echo "*** Indenting $f…"

    pushd "$(dirname "$f")" > /dev/null
    emacs -batch "$(basename "$f")" -l "${SCRIPTS_DIR}"/indent-matlab.el
    popd > /dev/null

    echo
done
