Some comments: 1. It's necessary to insert text into the grep buffer, which is a bit concerning because 'compilation-filter-start' is not a marker, just a number. This could cause other filter functions to get confused. This is why I'm adding to 'compilation-filter-hook at a higher depth. Perhaps there are better approaches here. 2. One could get rid of the awkward first alternative of `grep-heading-regexp' if there was a way to distringuish the grep process output from the header and footer added by grep-mode.