help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Intelligently opening large files in emacs


From: Felix Dietrich
Subject: Re: Intelligently opening large files in emacs
Date: Tue, 18 Mar 2014 17:45:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Dushyant Juneja <juneja.dushyant@gmail.com> writes:

> My question hence is, is there a way to integrate find-file-literally in a
> way that emacs automatically opens large files using this function, and the
> smaller files using the usual find-file. Please help me if such is possible.

Here is my take on the problem:


(defvar file-size-literal-threshold large-file-warning-threshold
  "Maximum size of a file above which it will get opened literally")

(defadvice find-file-noselect (before open-large-files-literally)
  (when (file-exists-p filename)
        (let ((filesize (nth 7 (file-attributes filename))))
           (when (and (not rawfile)
                                  (> filesize file-size-literal-threshold)
                                  (abort-if-file-too-large filesize "open 
literally" filename))
                 (setq rawfile t) ;; open file literally
                 (setq nowarn t)  ;; get rid of the question whether to open a 
large file
                 ))))

(ad-activate 'find-file-noselect)


For testing you can simply drop that code into your *scratch* buffer and
do M-x eval-buffer .  If you want to disable this advise eval:


(ad-disable-advice 'find-file-noselect 'before 'open-large-files-literally)


--
Felix Dietrich


reply via email to

[Prev in Thread] Current Thread [Next in Thread]