Script for formatting the whitespace in XKB symbols tables
Submitted by Shriramana Sharma
Assigned to xkb..@..bat.ru
Description
Created attachment 116757 Script for formatting the whitespace in XKB symbols tables
I have attached a Python (v3) script I wrote which helps to cleanup the whitespacing in the XKB symbols files and make all entries in neat to read columns to help maintainability. Please include this with the xkeyboard-config database.
Rationale:
Currently the symbols files are using a mixture of tab and space characters and the columns indicating the various levels are not very nicely aligned to say the least. As such, I am sure it would make the files much more readable and hence maintainable if the columns are aligned. This script does that. It uses only spaces to avoid the variation in tab widths from editor to editor.
If the key mappings are modified/updated for whatever reason, don't worry about the changed spacing/alignment -- just run it through the script again!
Behaviour:
The program is told to ignore lines starting with // for comments. It assumes that each internal table ends at a line beginning with }. As such it reformats only lines starting with "key <".
However, if any of those "key <" lines do not have matching brackets [] (and there are a few cases in the existing) it skips formatting such lines and outputs as is. These lines will be mentioned in a warning at the end. If the maintainer wants, they can manually correct those lines to achieve full table neatness.
Testing:
I have tested it using the contents of the symbols directory from the current commit 61fb58a9 i.e. release 2.15 and you can verify as follows that it only modifies whitespace and nothing else by doing the following from the xkeyboard-config git repo root after putting the format-symbols-table file under the symbols dir:
mkdir /tmp/xkb cd symbols for x in * do [ -d $x ] && mkdir /tmp/xkb/$x done find . -type f ! -name ".am" ! -name ".sh" -print -exec ./format-symbols-table "{}" /tmp/xkb/"{}" ";" diff -U1 -w -r . /tmp/xkb/ > /tmp/xkb-diff-report
Attachment 116757, "Script for formatting the whitespace in XKB symbols tables":
format-symbols-table