Reputation: 2277
Emacs sometimes hangs when viewing large file. But it is fast with (global-font-lock-mode -1)
.
I'm using a fork of Prelude.
Emacs version: 24.3 cocoa System: OS X 10.8.4
Update: I found (setq jit-lock-defer-time 0.05)
is a method to improve the scrolling speed.
Upvotes: 28
Views: 16464
Reputation: 251
it may be trick workaround
M-x shell
then
less your_large_file.txt
and you can proceed
Upvotes: -2
Reputation: 74480
To help with large files, I've installed my own find-file-hook
which turns on fundamental mode (avoids font-lock), turns off undo, and makes the buffer read-only just to avoid any accidental changes (making unnecessary backups of large files).
(defun my-find-file-check-make-large-file-read-only-hook ()
"If a file is over a given size, make the buffer read only."
(when (> (buffer-size) (* 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)))
(add-hook 'find-file-hook 'my-find-file-check-make-large-file-read-only-hook)
Obviously adjust the threshold value as you see fit.
Upvotes: 32
Reputation: 48893
I usually unroll long lines and indent by tags (like HTML, XML, JSON).
In order to make such operation possible I add:
(setq line-number-display-limit large-file-warning-threshold)
(setq line-number-display-limit-width 200)
(defun my--is-file-large ()
"If buffer too large and my cause performance issue."
(< large-file-warning-threshold (buffer-size)))
(define-derived-mode my-large-file-mode fundamental-mode "LargeFile"
"Fixes performance issues in Emacs for large files."
;; (setq buffer-read-only t)
(setq bidi-display-reordering nil)
(jit-lock-mode nil)
(buffer-disable-undo)
(set (make-variable-buffer-local 'global-hl-line-mode) nil)
(set (make-variable-buffer-local 'line-number-mode) nil)
(set (make-variable-buffer-local 'column-number-mode) nil) )
(add-to-list 'magic-mode-alist (cons #'my--is-file-large #'my-large-file-mode))
Note that I don't use find-file-hooks
as magic-mode-alist
usually empty and have priority. If I add find-file-hooks
it first validate XML file by nxml-mode
and then switch to fundamental-mode
.
I split line by regex, for XML it: C-M-% >< RET >NL< RET !
.
After Emacs split long lines - it is possible to enable many *-modes
and re-indent code.
Upvotes: 4
Reputation: 4359
If you need to work with really large files, you can use the View Large Files package which allows "viewing, editing and searching in large files in chunks." After require
ing the package open large files with M-x vlfi.
Upvotes: 18