3

I got a file(for instance, ~/.mozilla/firefox/xxx.default/sessionstore-backups/recovery.bak) that its content is one whole line and size of over 1MB, if I open it in Emacs, Emacs will become very laggy, so I put some configuration in Emacs: if a buffer you are going to open is over 1MB, use fundamental-mode and disables some other minor modes such as font-lock-mode and linum-mode and other configs for high performance, but this configuration is only working for buffers that size is over 1MB AND contents is not very long lines(for example, /var/log/messages), IF the content of the file is long lines, the configuration is totally not working.

My configuration:

(defun check-large-file-hook ()
  "If a file is over a given size, turn off minor modes"
  (when (> (buffer-size) (* 1024 1024)) ;; 1 MB
    (fundamental-mode)
    (font-lock-mode -1)
    (linum-mode -1)
    (setq buffer-read-only t)
    (buffer-disable-undo)
    ))
(add-hook 'find-file-hooks 'check-large-file-hook)

Is there any solution for this kind of problem?

NOTE:

Viewing long lines buffer is laggy is not my problem, so the VLF package would not be the solution to my post, my problem is configuration for lone lines buffer is not working.

CodyChan
  • 2,599
  • 1
  • 19
  • 33
  • visual-line-mode? – stsquad Nov 09 '14 at 17:47
  • 2
    I read the last two lines of your first paragraph a few times but still don't exactly understand what you are asking. How about some periods instead of one huge run-on sentence and a little better clarification? I.e., clarify please: *but this configuration is totally not working for buffers that its content is long lines(but works fine for big size file like /var/log/messages, size of over 3MB, but many separated lines).* – lawlist Nov 09 '14 at 18:22
  • `linum-mode` has a bad reputation for a variety of reasons, including slow-down issues. How about trying Stefan's `nlinum-mode` instead? http://elpa.gnu.org/packages/nlinum.html – lawlist Nov 09 '14 at 18:26
  • Some people have had some good results using `longlines-mode` in those cases. – Stefan Nov 09 '14 at 23:13
  • @lawlist My problem is not about how to improve performance when viewing long lines buffer, check my post again. – CodyChan Nov 10 '14 at 05:24
  • Would `(setq truncate-lines t)` be an option to at least get the file loaded without a problem? Also, `find-file-hooks` is obsolete and is an alias for `find-file-hook`. – lawlist Nov 10 '14 at 05:58
  • NO, I set my default mode to org-mode, but (in the snippet in my post)use fundamental-mode to open a file when the buffer-size is over 1MB, when a file that is is long lines, it will open it with default org-mode not the expected fundamental-mode, weird... – CodyChan Nov 10 '14 at 06:21
  • `(let ((auto-mode-alist nil)) . . .)` The `auto-mode-alist` generally controls what mode a particular file extension will open in (e.g., `*.org`) -- by setting it to `nil` with a let-bound variable, you bypass the `auto-mode-alist` regardless of the file extension. – lawlist Nov 10 '14 at 06:57
  • 3
    Though the question is quite confusing, it's really *not* a duplicate. He's asking why his hook doesn't work. – Malabarba Nov 10 '14 at 15:26
  • 1
    Use `find-file-hook`, not `find-file-hooks` (won't solve your problem, but that's the newer name - since Emacs 22.1). – Drew Nov 10 '14 at 17:09
  • Add a call to `(debug)` in your hook function, then step through the debugger to see what is going on. – Drew Nov 10 '14 at 17:11

1 Answers1

1

The question is confusing, but the comments seem to clarify that your code isn't working with a combination of an .org file > 1MB with a very long line.

I can replicate this with a .org file in which the first line of the file is very long (I used 1MB of dots).

(edit: In fact the failure begins -- for me, at least -- at an aesthetically-pleasing 33333 characters :)

In that instance I see:

Debugger entered--Lisp error: (error "Stack overflow in regexp matcher")
  looking-at(".*:ARCHIVE:")
  org-cycle-hide-archived-subtrees(all)
  org-set-startup-visibility()
  org-mode()
  set-auto-mode-0(org-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer foo.org> "~/foo.org" nil nil "~/foo.org" (3151235 2051))
  find-file-noselect("~/foo.org" nil nil t)
  find-file("~/foo.org" t)
  call-interactively(find-file nil nil)
  command-execute(find-file)

So you could M-x report-emacs-bug. I think your org-mode file must be slightly bizarre to have triggered this, though (assuming this is indeed the same issue).

You can work around this by starting with a blank line (or indeed pretty much anything that's of a sane length).

phils
  • 48,657
  • 3
  • 76
  • 115