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.

  • visual-line-mode? – stsquad Nov 9 '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 9 '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? elpa.gnu.org/packages/nlinum.html – lawlist Nov 9 '14 at 18:26
  • 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
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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