]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/vlf/vlf-base.el
Merge commit '3abcd90ddc2f446ddf0fb874dd79ba870c26ad2d' from js2-mode
[gnu-emacs-elpa] / packages / vlf / vlf-base.el
index 30e9b274b00013cbba8f3d4d720ccc49a4161e3b..f5682023180c40188af665e259e54bca920ad7fa 100644 (file)
 
 ;;; Code:
 
-(defcustom vlf-batch-size 1000000
-  "Defines how large each batch of file data initially is (in bytes)."
-  :group 'vlf :type 'integer)
-(put 'vlf-batch-size 'permanent-local t)
+(require 'vlf-tune)
 
 (defcustom vlf-before-chunk-update nil
   "Hook that runs before chunk update."
 (make-variable-buffer-local 'vlf-end-pos)
 (put 'vlf-end-pos 'permanent-local t)
 
-(defvar vlf-file-size 0 "Total size of presented file.")
-(make-variable-buffer-local 'vlf-file-size)
-(put 'vlf-file-size 'permanent-local t)
-
 (defconst vlf-sample-size 24
   "Minimal number of bytes that can be properly decoded.")
 
@@ -133,11 +126,10 @@ bytes added to the end."
                            (setq restore-hexl t
                                  hexl-undo-list buffer-undo-list
                                  buffer-undo-list t)
-                           (hexl-mode-exit))
+                           (vlf-tune-dehexlify))
                          (+ vlf-start-pos
-                            (length (encode-coding-region
-                                     (point-min) (point-max)
-                                     buffer-file-coding-system t))))
+                            (vlf-tune-encode-length (point-min)
+                                                    (point-max))))
                      vlf-end-pos))
          (shifts
           (cond
@@ -161,7 +153,7 @@ bytes added to the end."
             (when (and hexl (not restore-hexl))
               (if (consp buffer-undo-list)
                   (setq buffer-undo-list nil))
-              (hexl-mode-exit))
+              (vlf-tune-dehexlify))
             (let ((shift-start 0)
                   (shift-end 0))
               (let ((pos (+ (position-bytes (point)) vlf-start-pos))
@@ -224,12 +216,12 @@ bytes added to the end."
               (set-buffer-modified-p modified)
               (set-visited-file-modtime)
               (when hexl
-                (hexl-mode)
+                (vlf-tune-hexlify)
                 (setq restore-hexl nil))
               (run-hooks 'vlf-after-chunk-update)
               (cons shift-start shift-end))))))
     (when restore-hexl
-      (hexl-mode)
+      (vlf-tune-hexlify)
       (setq buffer-undo-list hexl-undo-list))
     shifts))
 
@@ -252,7 +244,7 @@ bytes added to the end."
                                                 vlf-end-pos t t)
                vlf-start-pos (- vlf-start-pos (car shifts))
                vlf-end-pos (+ vlf-end-pos (cdr shifts)))
-         (if hexl (hexl-mode)))
+         (if hexl (vlf-tune-hexlify)))
        (goto-char (or (byte-to-position (+ pos (car shifts)))
                       (point-max)))))
     (set-buffer-modified-p nil)
@@ -293,7 +285,7 @@ bytes added to the end."
 
 (defun vlf-insert-file-contents-1 (start end)
   "Extract decoded file bytes START to END."
-  (insert-file-contents buffer-file-name nil start end))
+  (vlf-tune-insert-file-contents start end))
 
 (defun vlf-adjust-start (start end position adjust-end)
   "Adjust chunk beginning at absolute START to END till content can\
@@ -345,12 +337,10 @@ which deletion was performed."
                               (eq encode-direction 'end)
                             (< (- end border) (- border start))))
          (dist (if encode-from-end
-                   (- end (length (encode-coding-region
-                                   cut-point (point-max)
-                                   buffer-file-coding-system t)))
-                 (+ start (length (encode-coding-region
-                                   position cut-point
-                                   buffer-file-coding-system t)))))
+                   (- end (vlf-tune-encode-length cut-point
+                                                  (point-max)))
+                 (+ start (vlf-tune-encode-length position
+                                                  cut-point))))
          (len 0))
     (if (< border dist)
         (while (< border dist)
@@ -378,7 +368,7 @@ which deletion was performed."
 
 (defun vlf-shift-undo-list (n)
   "Shift undo list element regions by N."
-  (or (eq buffer-undo-list t)
+  (or (null buffer-undo-list) (eq buffer-undo-list t)
       (setq buffer-undo-list
             (nreverse
              (let ((min (point-min))