Subject: Re: bug#44983: Truncate long lines of grep output

From: Juri Linkov <[email-masked]>
Date: Sat, 05 Dec 2020 21:47:06 +0200

>> I suggested to request the equivalent of "cut -c" to be a feature
>> added to Grep.
>>
>> Failing that, I don't think Emacs should do something like that,
>> especially since 'cut' is not guaranteed to be available.  Users who
>> have such problems can, of course, modify the Grep command to do that.
>
> Finally I solved the long-standing problem by customizing
> grep-find-template to
>
>   "find <D> <X> -type f <F> -print0 | sort -z | xargs -0 -e grep <C> --color=always -inH -e <R> | cut -c -200"

I noticed the problems caused by "cut -c": it counts bytes,
not multi-byte characters.  Even though it documentation says
that -b selects bytes, and -c selects characters, still
when used with "cut -c -200" it selects bytes, not UTF characters.

Often it cuts in the middle of a multi-byte UTF-8 character,
so octal codes are displayed at the end of grep lines.

This is like the character limit for a SMS message is 160 characters,
whereas actually this means not characters, but bytes, because
on an UTF text the SMS limit is only 70 characters.