Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 51 additions & 19 deletions indent.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
#!/bin/bash
#
# Install emacs:
# sudo apt-get install emacs
#
# Get the indentation emacs script as follows:
# wget https://raw.github.com/Glavin001/atom-beautify/master/src/beautifiers/fortran-beautifier/emacs-fortran-formating-script.lisp
#
# Change to downcase:
# sed 's/-upcase-/-downcase-/g' emacs-fortran-formating-script.lisp > emacs-fortran-formating-script-down.lisp
#
# To use it just call this script from the main qmd-progress folder.
# ./tools/indent.sh

PROGRESS_PATH=$(dirname $(readlink -f $0))

for file in $PROGRESS_PATH/src/*.F90
do
emacs -batch -l $PROGRESS_PATH/emacs-fortran-formating-script-down.lisp -f f90-batch-indent-region $file
done

set -x

: ${EMACS:=$(command -v emacs)}
: ${INDENT_ARGS:="-gnu -nut -i4 -bli0 -cli4 -ppi0 -cbi0 -npcs -bfda"}

declare -a C_FILES
declare -a FORTRAN_FILES

if ! git status > /dev/null; then
cat <<EOF
We are not inside a git repository. Please specify the files to indent
manually.
EOF
exit 1
fi

if (( $# > 0 )); then
for file in "$@"; do
case "${file##*.}" in
"c" | "h")
C_FILES[${#C_FILES[@]}]="$file"
;;
"F90")
FORTRAN_FILES[${#FORTRAN_FILES[@]}]="$file"
;;
*)
echo "unknown suffix"
;;
esac
done
else
readarray -t C_FILES < <(git ls-files -- *.c *.h)
readarray -t FORTRAN_FILES < <(git ls-files -- *.F90)
fi

for f in "${C_FILES[@]}" "${FORTRAN_FILES[@]}"; do
sed -i -e 's:\s\+$::' "${f}"
done

for f in "${C_FILES[@]}"; do
indent ${INDENT_ARGS} "${f}"
done

for f in "${FORTRAN_FILES[@]}"; do
${EMACS} --batch \
"${f}" \
--eval "(setq f90-do-indent 2)" \
--eval "(setq f90-if-indent 2)" \
--eval "(setq f90-type-indent 2)" \
--eval "(indent-region (minibuffer-prompt-end) (point-max) nil)" \
-f save-buffer
done