Created
November 29, 2016 13:14
-
-
Save spacebat/994f42291352397bfb48945b3a48f4ac to your computer and use it in GitHub Desktop.
An Emacs global minor mode that prevents lines in compilation buffers from growing too long
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar truncated-compilation-line-limit 70) | |
(defvar truncated-compilation-line-trailer "…") | |
;; TODO: convert this from a post filter hook to advice on a | |
;; configured set of filter functions to prevent the insertion of text | |
;; constituting overlong lines in the first place | |
;;;###autoload | |
(defun truncate-compilation-long-lines () | |
"Emacs doesn't cope well with extremely long | |
lines. Unfortunately some processes like grep, ack, ag, rg are | |
prone to matching minified files or otherwise extremely long | |
lines. Once Added to compilation-filter-hook, this function | |
truncates lines returned by the compilation process." | |
(cl-flet ((truncate-line (pos) | |
(let* ((beginning (progn (beginning-of-line) (point))) | |
(ending (progn (end-of-line) (point))) | |
(length (- ending beginning)) | |
(excess (max (- length truncated-compilation-line-limit)))) | |
(when (plusp excess) | |
(delete-region (- ending excess) ending) | |
(when truncated-compilation-line-trailer | |
(insert truncated-compilation-line-trailer)))))) | |
(goto-char compilation-filter-start) | |
(cl-loop do (truncate-line (point)) | |
(forward-line 1) | |
(end-of-line) | |
(when (= (point) (point-max)) | |
(return))))) | |
;;;###autoload | |
(define-minor-mode truncated-compilation-mode | |
"Limit the length of lines in compilation buffers" | |
:global t | |
(cond | |
(truncated-compilation-mode | |
(add-hook 'compilation-filter-hook 'truncate-compilation-long-lines)) | |
(t | |
(remove-hook 'compilation-filter-hook 'truncate-compilation-long-lines)))) | |
(provide 'truncated-compilation-mode) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment