When I grep inside emacs, it begins to be completelly laggy when lines are too long (just try to grep in your home emacs directory and you will see what I mean). How to set limit to line lengths in grep output buffer?

The effect can be reproduced with the following emacs lisp form. One can run the code in the scratch buffer.

(let ((file (make-temp-file "greptest")))
  (with-temp-file file
    (dotimes (i 100)
      (dotimes (j 100)
        (dotimes (k 100)
          (insert (string (+ 32 (random (- 127 32))))))
        (insert "test"))
      (insert "\n")))
  (grep (concat "grep --color -nH --text -e test " file))

It is clear that the effect depends on the performance of the computer. So it might be that you need to play around with the numbers to see the lagging.

  • 1
    Here is a link that I found with Googling: grep truncate. "How to truncate long matching lines returned by grep or ack": stackoverflow.com/questions/2034799/… It's not an Emacs solution, but perhaps it would help. – lawlist Dec 2 '17 at 23:51
  • @lawlist I think your comment makes a good answer. I tested it. The only small problem with the option -oE is that it highlights also the surrounding characters. That might be acceptable. – Tobias Dec 3 '17 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.