Formatter: cursor position is saved when invoking autoformat. Fixes #2293
[sam] Fixed compile error when using math functions

Fixes #2338