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.

share|improve this question
    
You've anwered your own question. font-lock is slow. Also, find-file-literally is good since it puts you in fundamental mode. – abo-abo Aug 19 '13 at 14:52
    
@abo-abo Then your recommendation is to disable font-lock-mode? – goofansu Aug 19 '13 at 15:08
    
@abo-abo My large file is about 8000 lines. I think it is normal. – goofansu Aug 19 '13 at 15:09
2  
I usually use find-file-literally. It disables not only font-lock, but also the major-mode. I can call it from dired when I see that the file size is large. – abo-abo Aug 19 '13 at 15:13
    
The speed can be influenced by so many things it's hard to tell. But 8000 lines is not "too large", so you can consider this problem as a bug and report it accordingly. – Stefan Aug 21 '13 at 16:24
up vote 25 down vote accepted

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.

share|improve this answer
1  
Thank you. But I also want to edit this file. You can see my above description of a "large" file. – goofansu Aug 19 '13 at 15:13
    
The adjust is good, I'll make a try. Thank you. – goofansu Aug 19 '13 at 15:13
    
@goofansu Sure, just take out the setting of buffer-read-only... glad it works for you – Trey Jackson Aug 19 '13 at 16:44
1  
Just using (linum-mode -1) after the checking size is enough, if not, adding (font-lock-mode -1) would be. – CodyChan Oct 14 '14 at 0:26

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 requireing the package open large files with M-x vlfi.

share|improve this answer
    
Thank you, I'll try it. – goofansu Aug 20 '13 at 0:06

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.

share|improve this answer
1  
this answer helped, but for me disabling bidi-display-reordering was enough – packet0 Sep 25 '16 at 5:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.