Emacs “stucks” at editing long line files. It does but that’s not Emacs’s fault. Emacs has excellent
gap buffer
for large file editing. It’s due to the mode you apply to the file. These modes might freeze your Emacs when editing
large file or minified files.
So here is a simple trick, I just check the first 30 line of the opened file. If first line is over 1000 in width, then
it just enable fundamental-mode which works perfectly for these files.
;; if the first line is too long, enable fundamental by default (defun get-nth-line-length (n) "Length of the Nth line." (save-excursion (goto-char (point-min)) (if (zerop (forward-line (1- n))) (- (line-end-position) (line-beginning-position)))))
(defun +my/check-minified-file () (and (not (member (file-name-extension (buffer-file-name)) '("org" "md" "markdown" "txt" "rtf"))) (cl-loop for i from 1 to (min 30 (count-lines (point-min) (point-max))) if (> (get-nth-line-length i) 1000) return t finally return nil)))