|
1 | 1 | #!/bin/bash
|
2 |
| -# |
3 |
| -# Install emacs: |
4 |
| -# sudo apt-get install emacs |
5 |
| -# |
6 |
| -# Get the indentation emacs script as follows: |
7 |
| -# wget https://raw.github.com/Glavin001/atom-beautify/master/src/beautifiers/fortran-beautifier/emacs-fortran-formating-script.lisp |
8 |
| -# |
9 |
| -# Change to downcase: |
10 |
| -# sed 's/-upcase-/-downcase-/g' emacs-fortran-formating-script.lisp > emacs-fortran-formating-script-down.lisp |
11 |
| -# |
12 |
| -# To use it just call this script from the main qmd-progress folder. |
13 |
| -# ./tools/indent.sh |
14 |
| - |
15 |
| -PROGRESS_PATH=$(dirname $(readlink -f $0)) |
16 |
| - |
17 |
| -for file in $PROGRESS_PATH/src/*.F90 |
18 |
| -do |
19 |
| - emacs -batch -l $PROGRESS_PATH/emacs-fortran-formating-script-down.lisp -f f90-batch-indent-region $file |
20 |
| -done |
21 | 2 |
|
| 3 | +set -x |
22 | 4 |
|
| 5 | +: ${EMACS:=$(command -v emacs)} |
| 6 | +: ${INDENT_ARGS:="-gnu -nut -i4 -bli0 -cli4 -ppi0 -cbi0 -npcs -bfda"} |
| 7 | + |
| 8 | +declare -a C_FILES |
| 9 | +declare -a FORTRAN_FILES |
| 10 | + |
| 11 | +if ! git status > /dev/null; then |
| 12 | + cat <<EOF |
| 13 | +We are not inside a git repository. Please specify the files to indent |
| 14 | +manually. |
| 15 | +EOF |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +if (( $# > 0 )); then |
| 20 | + for file in "$@"; do |
| 21 | + case "${file##*.}" in |
| 22 | + "c" | "h") |
| 23 | + C_FILES[${#C_FILES[@]}]="$file" |
| 24 | + ;; |
| 25 | + "F90") |
| 26 | + FORTRAN_FILES[${#FORTRAN_FILES[@]}]="$file" |
| 27 | + ;; |
| 28 | + *) |
| 29 | + echo "unknown suffix" |
| 30 | + ;; |
| 31 | + esac |
| 32 | + done |
| 33 | +else |
| 34 | + readarray -t C_FILES < <(git ls-files -- *.c *.h) |
| 35 | + readarray -t FORTRAN_FILES < <(git ls-files -- *.F90) |
| 36 | +fi |
| 37 | + |
| 38 | +for f in "${C_FILES[@]}" "${FORTRAN_FILES[@]}"; do |
| 39 | + sed -i -e 's:\s\+$::' "${f}" |
| 40 | +done |
| 41 | + |
| 42 | +for f in "${C_FILES[@]}"; do |
| 43 | + indent ${INDENT_ARGS} "${f}" |
| 44 | +done |
| 45 | + |
| 46 | +for f in "${FORTRAN_FILES[@]}"; do |
| 47 | + ${EMACS} --batch \ |
| 48 | + "${f}" \ |
| 49 | + --eval "(setq f90-do-indent 2)" \ |
| 50 | + --eval "(setq f90-if-indent 2)" \ |
| 51 | + --eval "(setq f90-type-indent 2)" \ |
| 52 | + --eval "(indent-region (minibuffer-prompt-end) (point-max) nil)" \ |
| 53 | + -f save-buffer |
| 54 | +done |
0 commit comments