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.

> Check 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)))

(add-to-list 'magic-mode-alist (cons #'+my/check-minified-file 'fundamental-mode))

> Check Large File

This piece of code is from spacemacs, we have to set a couple variables. But you could have your own version.

(setq spacemacs-large-file-modes-list '(archive-mode tar-mode jka-compr git-commit-mode image-mode
doc-view-mode doc-view-mode-maybe ebrowse-tree-mode
pdf-view-mode))

(setq dotspacemacs-large-file-size 1)

;; check when opening large files - literal file open
(defun spacemacs/check-large-file ()
(let* ((filename (buffer-file-name))
(size (nth 7 (file-attributes filename))))
(when (and
(not (memq major-mode spacemacs-large-file-modes-list))
size (> size (* 1024 1024 dotspacemacs-large-file-size))
(y-or-n-p (format (concat "%s is a large file, open literally to "
"avoid performance issues?")
filename)))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode))))

;; Prompt to open file literally if large file.
(add-hook 'find-file-hook 'spacemacs/check-large-file)