Modified beginning and end of line to respect major-mode definitions.