This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/core/tools/doc-fmt/run.bash
syl20bnr 7f07a965ad core: expand doc-fmt usage to any form of formatting
Add argument `action` as first positional argument, the second
positonal argument is for tests.

Add actions `doc` and `config`, doc works on org files and config works
on configuration file like packages.el.
The special action `all` performs all actions.

Move test files to `test` sub-folder.

Choose between `md5sum` and `md5` (on OS X) executables.

Add a new formatting function `move-packages-to-config` to move
package lists to config.el file.
2016-05-27 00:32:05 -04:00

70 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
# Formatting/Migration tool for Spacemacs
#
# Arguments:
# $1: action name can be `all`, `doc`, `config`
# $2: if equal to `test` then use test files as input
# TODO a function to add headers to config.el, packages.el etc...
if ! [ -d "./.git" ]
then
echo "Should be executed from the repo root."
exit 1
fi
#Use "sed" or "gsed" if avaliable.
seder="sed"
if hash gsed 2>/dev/null; then
seder="gsed"
fi
#Use md5 or md5sum
mdfive="md5sum"
if hash md5 2>/dev/null; then
mdfive="md5"
fi
if [[ $2 = "test" ]]
then
places=("./core/tools/doc-fmt/tests")
else
places=("./doc" "./layers")
fi
for place in "${places[@]}"
do :
before_md5="foo"
after_md5="bar"
while ! [ "$before_md5" = "$after_md5" ]
do
# Calculate md5 of the files in $place before formating
before_md5=$(find $place -type f -exec $mdfive {} \; | sort -k 2 | $mdfive)
if [ $1 = "all" ] || [ $1 == "doc" ]
then
# Remove trailing delimiters in headlines
find $place -name "*.org" -type f -exec $seder -i 's/^\(*\+\s\+.*\)[;,.]$/\1/g' {} \;
# Remove trailing spaces
find $place -name "*.org" -type f -exec $seder -i 's/[ \t]*$//' {} \;
# Remove #+HTML_HEAD_EXTRA: ... readtheorg.css" />
find $place -name "*.org" -type f -exec $seder -i '/#+HTML_HEAD_EXTRA.*readtheorg.css.*/d' {} \;
# Replace multiply empty lines with a single empty line
find $place -name "*.org" -type f -exec $seder -i '/^$/N;/^\n$/D' {} \;
# Replace :TOC_4_org: with :TOC_4_gh:
find $place -name "*.org" -type f -exec $seder -i 's/:TOC_4_org:/:TOC_4_gh:/' {} \;
# apply toc-org
find $place -name "*.org" -type f -exec emacs -batch -l ./core/tools/doc-fmt/fmt.el '{}' -f apply-all \;
fi
if [ $1 = "all" ] || [ $1 == "config" ]
then
# migrate packages lists to config.el
find $place -name "packages.el" -type f -exec emacs -batch -l ./core/tools/doc-fmt/fmt.el '{}' -f move-packages-to-config \;
fi
# Calculate md5 of the files in $place after formating
after_md5=$(find $place -type f -exec $mdfive {} \; | sort -k 2 | $mdfive)
done
done