Additions for templates-hint.

This pull request contains various fixes and improvements. Some was adapted from pull request #7.

1. Auto-indent lines, and fix position of token markers on everything after the first line (adapted from #7).
2. Enter key cycles through tokens, and move to `${cursor}` after completing all the variables. *Perhaps Tab should behave the same?*
3. Encapsulate template functionality in a reusable class.
4. Use the above class in JavaScript function autocompletion, with each parameter being a token.
5. Exclude optional paramters from JavaScript function autocompletion.

Please let me know if you want me to rather split those items into individual pull requests.

As a side note, this functionality should probably belong in a separate repository, since it has nothing to do with XQuery. It's the best autocompletion functionality for CodeMirror I've found so far (both for templates and JavaScript functions), but it's quite hidden away at the moment :)