jorgenschaefer / emacs-buttercup

Behavior-Driven Emacs Lisp Testing
GNU General Public License v3.0
362 stars 44 forks source link

Make sure carriage movement characters are not colorized #172

Closed snogge closed 4 years ago

snogge commented 4 years ago

Fixes #171, which reports that adding ansi-color-apply-on-region to compilation-filter-hook did not work with colorized buttercup output. This was because in the compilation-filter function, carriage movment characters \r and \n are handled (by comint-carriage-motion? ) beforecompilation-filter-hook? .

It is often recommended to use

;; either `point' or `point-max' work as the second argument
(ansi-color-apply-on-region compilation-filter-start (point))

in a compilation-filter-hook function to handle ANSI or SGR control sequences in compilation output. But carriage motion may cause point to move to before compilation-filter-start. Then ansi-color-apply-on-region will miss SGR control sequences in the point --- compilation-filter-start range. Using

(ansi-color-apply-on-region
    (save-excursion
        (goto-char compilation-filter-start)
        (line-beginning-position))
    (point))))

instead will at least avoid this problem for carriage motion that does not move point to preceding lines.

snogge commented 4 years ago

On second though, the ANSI codes that are not interpreted probably depends on how the input happens to be processed by the compilation process and is passed to it's input filer compilation-filter. This commit has no way to guarantee that the codes are interpreted correcvtly, it just makes them available to compilation-filter which is then free to screw it up.