reddit / emacs

Thoughts on improving compilation mode

ideasman_42 · 2022-07-16 04:20
Until recently I didn't use compilation mode much and preferred to compile in a terminal (for C/C++). ​ [Example output.](https://preview.redd.it/xo67ft2u9xb91.jpg?width=818&format=pjpg&auto=webp&s=56a7f9293fc9418bb0317324e08c580613de6200) Compilation mode has some quirks that I wasn't sure how to workaround. * No color (no support for color diagnostics for example). * No support for outputting progress output onto a single line (ninja does this, ensuring only warnings/errors are shown in the final output). * Erratic scrolling (scrolling jumps at times halfway down the screen, instead of smooth scrolling). This made the experience with CMake/Ninja C/C++ projects not so great, as with anything Emacs related, it's always *possible* to tweak to your hearts content, nevertheless, I avoided compilation mode for years because of these limits. More recently I looked into improving the behavior and with help on stackexchange, managed to resolve all these issues with surprising ease. This left me wondering if It's worth a small package or proposing changes up-stream. The changes are as follows: (setq compilation-environment '("TERM=tmux-256color")) (setq compilation-max-output-line-length nil) (defun my/advice-compilation-filter (f proc string) (funcall f proc (ansi-color-apply string))) (advice-add 'compilation-filter :around #'my/advice-compilation-filter) (advice-add 'compilation-filter :after #'my/advice-compilation-filter) (add-hook 'compilation-mode-hook (lambda () (setq-local compilation-scroll-output t) (setq-local scroll-conservatively most-positive-fixnum) (setq-local scroll-margin 0))) \--- Edit, [made a package for this](https://codeberg.org/ideasman42/emacs-fancy-compilation).
guitmz · 2022-07-30 21:02
wow I like this a lot, it works like a charm! Thank you! had this issue while building docker images with dockerfile-mode
ideasman_42 · 2022-07-31 04:32
So far I've tested it for CMake/Ninja & Python-Sphinx (documentation system), works nicely for both, glad to here it works for dockerfile-mode too :)
guitmz · 2022-07-31 15:50
Actually I did some more testing today and it seems that it does not support the carriage return (\r) character. Things just continue to get printed in new lines instead of the same (docker build command for example). Have you had this issue before? I can provide a visual example if needed.
ideasman_42 · 2022-08-01 09:20
No, this should work correctly, could you report a bug?
guitmz · 2022-08-01 10:30
Will do in the repository:)