]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/vlf/vlf-integrate.el
Merge commit '3abcd90ddc2f446ddf0fb874dd79ba870c26ad2d' from js2-mode
[gnu-emacs-elpa] / packages / vlf / vlf-integrate.el
index 6ba8aa1a7a6d00176dad7eb0b3e834e8f1739bfd..7bc8f94752e75f57ae3195c5a36254f6e99f78fb 100644 (file)
 
 ;;; Code:
 
-(defgroup vlf nil
-  "View Large Files in Emacs."
-  :prefix "vlf-"
-  :group 'files)
+(defgroup vlf nil "View Large Files in Emacs."
+  :prefix "vlf-" :group 'files)
+
+(defcustom vlf-batch-size 1000000
+  "Defines how large each batch of file data initially is (in bytes)."
+  :group 'vlf :type 'integer)
 
 (defcustom vlf-application 'ask
   "Determines when `vlf' will be offered on opening files.
@@ -37,18 +39,16 @@ Possible values are: nil to never use it;
 `ask' offer `vlf' when file size is beyond `large-file-warning-threshold';
 `dont-ask' automatically use `vlf' for large files;
 `always' use `vlf' for all files."
-  :group 'vlf
-  :type '(radio (const :format "%v " nil)
-                (const :format "%v " ask)
-                (const :format "%v " dont-ask)
-                (const :format "%v" always)))
+  :group 'vlf :type '(radio (const :format "%v " nil)
+                            (const :format "%v " ask)
+                            (const :format "%v " dont-ask)
+                            (const :format "%v" always)))
 
 (defcustom vlf-forbidden-modes-list
   '(archive-mode tar-mode jka-compr git-commit-mode image-mode
                  doc-view-mode doc-view-mode-maybe ebrowse-tree-mode)
   "Major modes which VLF will not be automatically applied to."
-  :group 'vlf
-  :type '(list symbol))
+  :group 'vlf :type '(list symbol))
 
 (unless (fboundp 'file-size-human-readable)
   (defun file-size-human-readable (file-size)
@@ -84,6 +84,8 @@ Possible values are: nil to never use it;
         (cadr mode)
       mode)))
 
+(autoload 'vlf "vlf" "View Large FILE in batches." t)
+
 (defadvice abort-if-file-too-large (around vlf-if-file-too-large
                                            compile activate)
   "If file SIZE larger than `large-file-warning-threshold', \
@@ -100,7 +102,8 @@ OP-TYPE specifies the file operation being performed over FILENAME."
     (vlf filename)
     (error ""))
    ((and large-file-warning-threshold
-         (< large-file-warning-threshold size))
+         (< large-file-warning-threshold size)
+         (< vlf-batch-size size))
     (if (eq vlf-application 'dont-ask)
         (progn (vlf filename)
                (error ""))
@@ -124,20 +127,23 @@ OP-TYPE specifies the file operation being performed over FILENAME."
               ((memq char '(?a ?A))
                (error "Aborted"))))))))
 
-(eval-after-load "etags"
-  '(progn
-     (defadvice tags-verify-table (around vlf-tags-verify-table
-                                          compile activate)
-       "Temporarily disable `vlf-mode'."
-       (let ((vlf-application nil))
-         ad-do-it))
-
-     (defadvice tag-find-file-of-tag-noselect
-         (around vlf-tag-find-file-of-tag compile activate)
-       "Temporarily disable `vlf-mode'."
-       (let ((vlf-application nil))
-         ad-do-it))))
-
+;; disable for some functions
+(defmacro vlf-disable-for-function (func file)
+  "Build advice to disable VLF during execution of FUNC\
+defined in FILE."
+  `(eval-after-load ,file
+     '(defadvice ,func (around ,(intern (concat "vlf-"
+                                                (symbol-name func)))
+                               compile activate)
+        "Temporarily disable `vlf-mode'."
+        (let ((vlf-application nil))
+          ad-do-it))))
+
+(vlf-disable-for-function tags-verify-table "etags")
+(vlf-disable-for-function tag-find-file-of-tag-noselect "etags")
+(vlf-disable-for-function helm-etags-create-buffer "helm-tags")
+
+;; dired
 (defun dired-vlf ()
   "In Dired, visit the file on this line in VLF mode."
   (interactive)