emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] 03/04: * packages/vlf: Version 1.3.


From: Andrey Kotlarski
Subject: [elpa] 03/04: * packages/vlf: Version 1.3.
Date: Sat, 01 Feb 2014 20:08:38 +0000

m00natic pushed a commit to branch master
in repository elpa.

commit 5563ab5ca817336895c0d8f5f815f5e8bccfb271
Author: Andrey Kotlarski <address@hidden>
Date:   Sat Feb 1 21:37:27 2014 +0200

        * packages/vlf: Version 1.3.
    
        * vlf.el: Update comment section.  Decouple integration code from
        the rest.
        (vlf-stop-follow): Add autoload definition.
        (vlf-mode): Simplify code.
        (vlf): Return newly created buffer.
        (vlf-next-batch, vlf-prev-batch): Move functions before first
        usage.
        (vlf-beginning-of-file, vlf-end-of-file): Use
        `vlf-move-to-batch'.
        (vlf-revert): Remove needless modtime update.
    
        * vlf-base.el (vlf-min-chunk-size): Rename to `vlf-sample-size'.
        (vlf-move-to-chunk-1): Widen before measuring chunk length.
        Detect change of file.  Remove ignoring of small chunk moves.
        Update modification time.
        (vlf-move-to-chunk-2): Update file size besides modtime.
        (vlf-insert-file-contents, vlf-adjust-start, vlf-adjust-end): Add
        buffer bytes to beginning/end of requested chunk when adjusting.
        (vlf-insert-file-contents-safe): Insert content literally and then
        decode.
    
        * vlf-write.el (vlf-write): Widen before writing.  No need to
        verify size.
        (vlf-file-shift-back, vlf-shift-batch, vlf-shift-batches): Update
        modtime.
    
        * vlf-integrate.el (vlf-disable-for-function): New macro.  Use it
        to disable VLF activation for some TAGS functions.
    
        * vlf-follow.el (vlf-follow-timer): Declare buffer local.
        (vlf-stop-follow): Check if `vlf-follow-timer' is set.
---
 packages/vlf/vlf-base.el      |  264 ++++++++++++++++++++++++-----------------
 packages/vlf/vlf-follow.el    |    8 +-
 packages/vlf/vlf-integrate.el |   33 +++--
 packages/vlf/vlf-occur.el     |    2 +
 packages/vlf/vlf-search.el    |    2 +
 packages/vlf/vlf-write.el     |   12 +-
 packages/vlf/vlf.el           |  153 ++++++++----------------
 7 files changed, 239 insertions(+), 235 deletions(-)

diff --git a/packages/vlf/vlf-base.el b/packages/vlf/vlf-base.el
index fbc27ba..a2ad0e0 100644
--- a/packages/vlf/vlf-base.el
+++ b/packages/vlf/vlf-base.el
@@ -22,22 +22,74 @@
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
-;; This package provides basic chunk operations for VLF
+;; This package provides basic chunk operations for VLF,
+;; most notable being the `vlf-move-to-chunk' function.
 
 ;;; Code:
 
-(defconst vlf-min-chunk-size 16
+(defgroup vlf nil
+  "View Large Files in Emacs."
+  :prefix "vlf-"
+  :group 'files)
+
+(defcustom vlf-batch-size 1024
+  "Defines how large each batch of file data is (in bytes)."
+  :group 'vlf
+  :type 'integer)
+(put 'vlf-batch-size 'permanent-local t)
+
+;;; Keep track of file position.
+(defvar vlf-start-pos 0
+  "Absolute position of the visible chunk start.")
+(make-variable-buffer-local 'vlf-start-pos)
+(put 'vlf-start-pos 'permanent-local t)
+
+(defvar vlf-end-pos 0 "Absolute position of the visible chunk end.")
+(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.")
 
-(defconst vlf-partial-decode-shown
-  (cond ((< emacs-major-version 24) t)
-        ((< 24 emacs-major-version) nil)
-        (t ;; TODO: use (< emacs-minor-version 4) after 24.4 release
-         (string-lessp emacs-version "24.3.5")))
-  "Indicates whether partial decode codes are displayed.")
+(defun vlf-get-file-size (file)
+  "Get size in bytes of FILE."
+  (or (nth 7 (file-attributes file)) 0))
+
+(defun vlf-verify-size (&optional update-visited-time)
+  "Update file size information if necessary and visited file time.
+If non-nil, UPDATE-VISITED-TIME."
+  (unless (verify-visited-file-modtime (current-buffer))
+    (setq vlf-file-size (vlf-get-file-size buffer-file-truename))
+    (if update-visited-time
+        (set-visited-file-modtime))))
+
+(unless (fboundp 'file-size-human-readable)
+  (defun file-size-human-readable (file-size)
+    "Print FILE-SIZE in MB."
+    (format "%.3fMB" (/ file-size 1048576.0))))
+
+(defun vlf-update-buffer-name ()
+  "Update the current buffer name."
+  (rename-buffer (format "%s(%d/%d)[%s]"
+                         (file-name-nondirectory buffer-file-name)
+                         (/ vlf-end-pos vlf-batch-size)
+                         (/ vlf-file-size vlf-batch-size)
+                         (file-size-human-readable vlf-batch-size))
+                 t))
+
+(defmacro vlf-with-undo-disabled (&rest body)
+  "Execute BODY with temporarily disabled undo."
+  `(let ((undo-list buffer-undo-list))
+     (setq buffer-undo-list t)
+     (unwind-protect (progn ,@body)
+       (setq buffer-undo-list undo-list))))
 
 (defun vlf-move-to-chunk (start end &optional minimal)
-  "Move to chunk determined by START END.
+  "Move to chunk enclosed by START END bytes.
 When given MINIMAL flag, skip non important operations.
 If same as current chunk is requested, do nothing.
 Return number of bytes moved back for proper decoding and number of
@@ -51,9 +103,10 @@ bytes added to the end."
       shifts)))
 
 (defun vlf-move-to-chunk-1 (start end)
-  "Move to chunk determined by START END keeping as much edits if any.
+  "Move to chunk enclosed by START END keeping as much edits if any.
 Return number of bytes moved back for proper decoding and number of
 bytes added to the end."
+  (widen)
   (let* ((modified (buffer-modified-p))
          (start (max 0 start))
          (end (min end vlf-file-size))
@@ -64,13 +117,14 @@ bytes added to the end."
                                    buffer-file-coding-system t)))
                      vlf-end-pos)))
     (cond
-     ((and (= start vlf-start-pos) (= end edit-end))
-      (or modified (vlf-move-to-chunk-2 start end)))
-     ((or (<= edit-end start) (<= end vlf-start-pos))
+     ((or (< edit-end start) (< end vlf-start-pos)
+          (not (verify-visited-file-modtime (current-buffer))))
       (when (or (not modified)
                 (y-or-n-p "Chunk modified, are you sure? ")) ;full chunk 
renewal
         (set-buffer-modified-p nil)
         (vlf-move-to-chunk-2 start end)))
+     ((and (= start vlf-start-pos) (= end edit-end))
+      (or modified (vlf-move-to-chunk-2 start end)))
      ((or (and (<= start vlf-start-pos) (<= edit-end end))
           (not modified)
           (y-or-n-p "Chunk modified, are you sure? "))
@@ -79,8 +133,9 @@ bytes added to the end."
         (let ((pos (+ (position-bytes (point)) vlf-start-pos))
               (inhibit-read-only t))
           (cond ((< end edit-end)
-                 (let* ((del-pos (1+ (byte-to-position
-                                      (- end vlf-start-pos))))
+                 (let* ((del-pos (1+ (or (byte-to-position
+                                          (- end vlf-start-pos))
+                                         0)))
                         (del-len (length (encode-coding-region
                                           del-pos (point-max)
                                           buffer-file-coding-system
@@ -92,13 +147,11 @@ bytes added to the end."
                    (vlf-with-undo-disabled
                     (delete-region del-pos (point-max)))))
                 ((< edit-end end)
-                 (if (and (not vlf-partial-decode-shown)
-                          (< (- end vlf-end-pos) 4))
-                     (setq end vlf-end-pos)
-                   (vlf-with-undo-disabled
-                    (setq shift-end (cdr (vlf-insert-file-contents
-                                          vlf-end-pos end nil t
-                                          (point-max))))))))
+                 (vlf-with-undo-disabled
+                  (setq shift-end (cdr (vlf-insert-file-contents
+                                        vlf-end-pos end
+                                        (/= start vlf-end-pos) t
+                                        (point-max)))))))
           (cond ((< vlf-start-pos start)
                  (let* ((del-pos (1+ (byte-to-position
                                       (- start vlf-start-pos))))
@@ -109,20 +162,18 @@ bytes added to the end."
                    (setq start (+ vlf-start-pos del-len))
                    (vlf-with-undo-disabled
                     (delete-region (point-min) del-pos))
-                   (vlf-shift-undo-list (- 1 del-pos))))
+                   (vlf-shift-undo-list (- (point-min) del-pos))))
                 ((< start vlf-start-pos)
-                 (if (and (not vlf-partial-decode-shown)
-                          (< (- vlf-start-pos start) 4))
-                     (setq start vlf-start-pos)
-                   (let ((edit-end-pos (point-max)))
-                     (vlf-with-undo-disabled
-                      (setq shift-start (car (vlf-insert-file-contents
-                                              start vlf-start-pos
-                                              t nil edit-end-pos)))
-                      (goto-char (point-min))
-                      (insert (delete-and-extract-region
-                               edit-end-pos (point-max))))
-                     (vlf-shift-undo-list (- (point-max) edit-end-pos))))))
+                 (let ((edit-end-pos (point-max)))
+                   (vlf-with-undo-disabled
+                    (setq shift-start (car (vlf-insert-file-contents
+                                            start vlf-start-pos t
+                                            (/= end vlf-start-pos)
+                                            edit-end-pos)))
+                    (goto-char (point-min))
+                    (insert (delete-and-extract-region
+                             edit-end-pos (point-max))))
+                   (vlf-shift-undo-list (- (point-max) edit-end-pos)))))
           (setq start (- start shift-start))
           (goto-char (or (byte-to-position (- pos start))
                          (byte-to-position (- pos vlf-start-pos))
@@ -130,12 +181,14 @@ bytes added to the end."
           (setq vlf-start-pos start
                 vlf-end-pos (+ end shift-end)))
         (set-buffer-modified-p modified)
+        (set-visited-file-modtime)
         (cons shift-start shift-end))))))
 
 (defun vlf-move-to-chunk-2 (start end)
-  "Unconditionally move to chunk determined by START END.
+  "Unconditionally move to chunk enclosed by START END bytes.
 Return number of bytes moved back for proper decoding and number of
 bytes added to the end."
+  (vlf-verify-size t)
   (setq vlf-start-pos (max 0 start)
         vlf-end-pos (min end vlf-file-size))
   (let (shifts)
@@ -151,7 +204,6 @@ bytes added to the end."
                       (point-max)))))
     (set-buffer-modified-p nil)
     (setq buffer-undo-list nil)
-    (set-visited-file-modtime)
     shifts))
 
 (defun vlf-insert-file-contents (start end adjust-start adjust-end
@@ -165,17 +217,19 @@ bytes added to the end."
   (setq adjust-start (and adjust-start (not (zerop start)))
         adjust-end (and adjust-end (< end vlf-file-size))
         position (or position (point-min)))
+  (goto-char position)
   (let ((shift-start 0)
-        (shift-end 0))
+        (shift-end 0)
+        (safe-end (if adjust-end
+                      (min vlf-file-size (+ end 4))
+                    end)))
     (if adjust-start
-        (setq shift-start (vlf-adjust-start start end position
+        (setq shift-start (vlf-adjust-start start safe-end position
                                             adjust-end)
               start (- start shift-start))
-      (setq shift-end (vlf-insert-content-safe start end position)
-            end (+ end shift-end)))
+      (vlf-insert-file-contents-safe start safe-end position))
     (if adjust-end
-        (setq shift-end (+ shift-end
-                           (vlf-adjust-end start end position))))
+        (setq shift-end (vlf-adjust-end start end position)))
     (cons shift-start shift-end)))
 
 (defun vlf-adjust-start (start end position adjust-end)
@@ -183,83 +237,75 @@ bytes added to the end."
 be properly decoded.  Use buffer POSITION as start.
 ADJUST-END is non-nil if end would be adjusted later.
 Return number of bytes moved back for proper decoding."
-  (let* ((min-end (min end (+ start vlf-min-chunk-size)))
-         (chunk-size (- min-end start))
-         (strict (and (not adjust-end) (= min-end end)))
-         (shift (vlf-insert-content-safe start min-end position t)))
-    (setq start (- start shift))
-    (while (and (not (zerop start))
+  (let* ((safe-start (max 0 (- start 4)))
+         (sample-end (min end (+ safe-start vlf-sample-size)))
+         (chunk-size (- sample-end safe-start))
+         (strict (or (= sample-end vlf-file-size)
+                     (and (not adjust-end) (= sample-end end))))
+         (shift 0))
+    (while (and (progn (vlf-insert-file-contents-safe
+                        safe-start sample-end position)
+                       (not (zerop safe-start)))
                 (< shift 3)
                 (let ((diff (- chunk-size
                                (length
                                 (encode-coding-region
                                  position (point-max)
                                  buffer-file-coding-system t)))))
-                  (cond (strict (not (zerop diff)))
-                        (vlf-partial-decode-shown
-                         (or (< diff -3) (< 0 diff)))
-                        (t (or (< diff 0) (< 3 diff))))))
+                  (if strict
+                      (not (zerop diff))
+                    (or (< diff -3) (< 0 diff)))))
       (setq shift (1+ shift)
-            start (1- start)
+            safe-start (1- safe-start)
             chunk-size (1+ chunk-size))
-      (delete-region position (point-max))
-      (insert-file-contents buffer-file-name nil start min-end))
-    (unless (= min-end end)
-      (delete-region position (point-max))
-      (insert-file-contents buffer-file-name nil start end))
-    shift))
+      (delete-region position (point-max)))
+    (let ((cut-pos position)
+          (cut-len 0))
+      (while (< safe-start start)
+        (setq cut-len (length (encode-coding-region
+                               cut-pos (1+ cut-pos)
+                               buffer-file-coding-system t))
+              cut-pos (1+ cut-pos)
+              safe-start (+ safe-start cut-len)))
+      (if (< start safe-start)
+          (setq safe-start (- safe-start cut-len)
+                cut-pos (1- cut-pos)))
+      (if (= sample-end end)
+          (delete-region position cut-pos)
+        (delete-region position (point-max))
+        (vlf-insert-file-contents-safe safe-start end position)))
+    (- start safe-start)))
 
 (defun vlf-adjust-end (start end position)
-  "Adjust chunk end at absolute START to END till content can be\
-properly decoded starting at POSITION.
-Return number of bytes added for proper decoding."
-  (let ((shift 0))
-    (if vlf-partial-decode-shown
-        (let ((new-pos (max position
-                            (- (point-max) vlf-min-chunk-size))))
-          (if (< position new-pos)
-              (setq start (+ start (length (encode-coding-region
-                                            position new-pos
-                                            buffer-file-coding-system
-                                            t)))
-                    position new-pos))))
-    (let ((chunk-size (- end start)))
-      (goto-char (point-max))
-      (while (and (< shift 3)
-                  (< end vlf-file-size)
-                  (or (eq (char-charset (preceding-char)) 'eight-bit)
-                      (/= chunk-size
-                          (length (encode-coding-region
-                                   position (point-max)
-                                   buffer-file-coding-system t)))))
-        (setq shift (1+ shift)
-              end (1+ end)
-              chunk-size (1+ chunk-size))
-        (delete-region position (point-max))
-        (insert-file-contents buffer-file-name nil start end)
-        (goto-char (point-max))))
-    shift))
+  "Adjust chunk end at absolute START to END starting at POSITION.
+Remove characters from the end until length is closest to expected.
+Return number of bytes added over expected."
+  (let ((expected-size (- end start))
+        (current-size (length (encode-coding-region
+                               position (point-max)
+                               buffer-file-coding-system t)))
+        (cut-point (point-max))
+        (cut-len 0))
+    (while (< expected-size current-size)
+      (setq cut-len (length (encode-coding-region
+                             (1- cut-point) cut-point
+                             buffer-file-coding-system t))
+            cut-point (1- cut-point)
+            current-size (- current-size cut-len)))
+    (if (< current-size expected-size)
+        (setq cut-point (1+ cut-point)
+              current-size (+ current-size cut-len)))
+    (delete-region cut-point (point-max))
+    (- current-size expected-size)))
 
-(defun vlf-insert-content-safe (start end position &optional shift-start)
-  "Insert file content from absolute START to END of file at\
-POSITION.  Adjust start if SHIFT-START is non nil, end otherwise.
-Clean up if no characters are inserted."
-  (goto-char position)
-  (let ((shift 0))
-    (while (and (< shift 3)
-                (zerop (cadr (insert-file-contents buffer-file-name
-                                                   nil start end)))
-                (if shift-start
-                    (not (zerop start))
-                  (< end vlf-file-size)))
-      ;; TODO: this seems like regression after Emacs 24.3
-      (message "Buffer content may be broken")
-      (setq shift (1+ shift))
-      (if shift-start
-          (setq start (1- start))
-        (setq end (1+ end)))
-      (delete-region position (point-max)))
-    shift))
+(defun vlf-insert-file-contents-safe (start end position)
+  "Extract decoded file bytes START to END at POSITION."
+  (let ((coding buffer-file-coding-system))
+    (insert-file-contents-literally buffer-file-name nil start end)
+    (let ((coding-system-for-read coding))
+      (decode-coding-inserted-region position (point-max)
+                                     buffer-file-name nil start end)))
+  (setq buffer-file-coding-system last-coding-system-used))
 
 (defun vlf-shift-undo-list (n)
   "Shift undo list element regions by N."
diff --git a/packages/vlf/vlf-follow.el b/packages/vlf/vlf-follow.el
index 2ff522a..2b825da 100644
--- a/packages/vlf/vlf-follow.el
+++ b/packages/vlf/vlf-follow.el
@@ -27,8 +27,11 @@
 
 ;;; Code:
 
+(require 'vlf)
+
 (defvar vlf-follow-timer nil
   "Contains timer if vlf buffer is set to continuously recenter.")
+(make-variable-buffer-local 'vlf-follow-timer)
 (put 'vlf-follow-timer 'permanent-local t)
 
 (defun vlf-recenter (vlf-buffer)
@@ -57,8 +60,9 @@
 
 (defun vlf-stop-follow ()
   "Stop continuous recenter."
-  (cancel-timer vlf-follow-timer)
-  (setq vlf-follow-timer nil))
+  (when vlf-follow-timer
+    (cancel-timer vlf-follow-timer)
+    (setq vlf-follow-timer nil)))
 
 (defun vlf-start-follow (interval)
   "Continuously recenter chunk around point every INTERVAL seconds."
diff --git a/packages/vlf/vlf-integrate.el b/packages/vlf/vlf-integrate.el
index 6ba8aa1..c072398 100644
--- a/packages/vlf/vlf-integrate.el
+++ b/packages/vlf/vlf-integrate.el
@@ -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', \
@@ -124,20 +126,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)
diff --git a/packages/vlf/vlf-occur.el b/packages/vlf/vlf-occur.el
index 64a35d0..10f8d6a 100644
--- a/packages/vlf/vlf-occur.el
+++ b/packages/vlf/vlf-occur.el
@@ -27,6 +27,8 @@
 
 ;;; Code:
 
+(require 'vlf)
+
 (defvar vlf-occur-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "n" 'vlf-occur-next-match)
diff --git a/packages/vlf/vlf-search.el b/packages/vlf/vlf-search.el
index 25063c1..0db5ba5 100644
--- a/packages/vlf/vlf-search.el
+++ b/packages/vlf/vlf-search.el
@@ -27,6 +27,8 @@
 
 ;;; Code:
 
+(require 'vlf)
+
 (defun vlf-re-search (regexp count backward batch-step)
   "Search for REGEXP COUNT number of times forward or BACKWARD.
 BATCH-STEP is amount of overlap between successive chunks."
diff --git a/packages/vlf/vlf-write.el b/packages/vlf/vlf-write.el
index 9e45b9c..7e9d069 100644
--- a/packages/vlf/vlf-write.el
+++ b/packages/vlf/vlf-write.el
@@ -27,6 +27,8 @@
 
 ;;; Code:
 
+(require 'vlf-base)
+
 (defun vlf-write ()
   "Write current chunk to file.  Always return true to disable save.
 If changing size of chunk, shift remaining file content."
@@ -42,6 +44,7 @@ Save anyway? "))
                                   buffer-file-truename)
                    vlf-end-pos vlf-file-size)
              (vlf-update-buffer-name))
+         (widen)
          (let* ((region-length (length (encode-coding-region
                                         (point-min) (point-max)
                                         buffer-file-coding-system t)))
@@ -52,8 +55,7 @@ Save anyway? "))
              (let ((pos (point)))
                (if (< 0 size-change)
                    (vlf-file-shift-back size-change)
-                 (vlf-file-shift-forward (- size-change))
-                 (vlf-verify-size))
+                 (vlf-file-shift-forward (- size-change)))
                (vlf-move-to-chunk-2 vlf-start-pos
                                     (if (< (- vlf-end-pos vlf-start-pos)
                                            vlf-batch-size)
@@ -78,7 +80,7 @@ Save anyway? "))
        (progress-reporter-update reporter read-start-pos))
      ;; pad end with space
      (erase-buffer)
-     (vlf-verify-size)
+     (vlf-verify-size t)
      (insert-char 32 size-change))
     (write-region nil nil buffer-file-name (- vlf-file-size
                                               size-change) t)
@@ -88,7 +90,7 @@ Save anyway? "))
   "Read `vlf-batch-size' bytes from READ-POS and write them \
 back at WRITE-POS.  Return nil if EOF is reached, t otherwise."
   (erase-buffer)
-  (vlf-verify-size)
+  (vlf-verify-size t)
   (let ((read-end (+ read-pos vlf-batch-size)))
     (insert-file-contents-literally buffer-file-name nil
                                     read-pos
@@ -122,7 +124,7 @@ Done by saving content up front and then writing previous 
batch."
 Then write initial buffer content to file at WRITE-POS.
 If HIDE-READ is non nil, temporarily hide literal read content.
 Return nil if EOF is reached, t otherwise."
-  (vlf-verify-size)
+  (vlf-verify-size t)
   (let ((read-more (< read-pos vlf-file-size))
         (start-write-pos (point-min))
         (end-write-pos (point-max)))
diff --git a/packages/vlf/vlf.el b/packages/vlf/vlf.el
index 9181d0f..c567854 100644
--- a/packages/vlf/vlf.el
+++ b/packages/vlf/vlf.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2006, 2012-2014 Free Software Foundation, Inc.
 
-;; Version: 1.2
+;; Version: 1.3
 ;; Keywords: large files, utilities
 ;; Maintainer: Andrey Kotlarski <address@hidden>
 ;; Authors: 2006 Mathias Dahl <address@hidden>
@@ -26,10 +26,12 @@
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
-;; This package provides the M-x vlf command, which visits part of a
-;; large file without loading the entire file.
-;; The buffer uses VLF mode, which defines several commands for
+;; This package provides the M-x vlf command, which visits part of
+;; large file without loading it entirely.
+;; The buffer uses VLF mode, which provides several commands for
 ;; moving around, searching and editing selected part of file.
+;; To have it offered when opening large files:
+;; (require 'vlf-integrate)
 
 ;; This package was inspired by a snippet posted by Kevin Rodgers,
 ;; showing how to use `insert-file-contents' to extract part of a
@@ -37,28 +39,8 @@
 
 ;;; Code:
 
-;;;###autoload
-(require 'vlf-integrate)
-
 (require 'vlf-base)
 
-(defcustom vlf-batch-size 1024
-  "Defines how large each batch of file data is (in bytes)."
-  :group 'vlf
-  :type 'integer)
-(put 'vlf-batch-size 'permanent-local t)
-
-;;; Keep track of file position.
-(defvar vlf-start-pos 0
-  "Absolute position of the visible chunk start.")
-(put 'vlf-start-pos 'permanent-local t)
-
-(defvar vlf-end-pos 0 "Absolute position of the visible chunk end.")
-(put 'vlf-end-pos 'permanent-local t)
-
-(defvar vlf-file-size 0 "Total size of presented file.")
-(put 'vlf-file-size 'permanent-local t)
-
 (autoload 'vlf-write "vlf-write" "Write current chunk to file.")
 (autoload 'vlf-re-search-forward "vlf-search"
   "Search forward for REGEXP prefix COUNT number of times.")
@@ -69,6 +51,8 @@
   "Make whole file occur style index for REGEXP.")
 (autoload 'vlf-toggle-follow "vlf-follow"
   "Toggle continuous chunk recenter around current point.")
+(autoload 'vlf-stop-follow "vlf-follow"
+  "Stop continuous recenter.")
 
 (defvar vlf-mode-map
   (let ((map (make-sparse-keymap)))
@@ -98,13 +82,6 @@
     map)
   "Prefixed keymap for `vlf-mode'.")
 
-(defmacro vlf-with-undo-disabled (&rest body)
-  "Execute BODY with temporarily disabled undo."
-  `(let ((undo-list buffer-undo-list))
-     (setq buffer-undo-list t)
-     (unwind-protect (progn ,@body)
-       (setq buffer-undo-list undo-list))))
-
 (define-minor-mode vlf-mode
   "Mode to browse large files in."
   :lighter " VLF"
@@ -117,17 +94,15 @@
         (set (make-local-variable 'revert-buffer-function)
              'vlf-revert)
         (make-local-variable 'vlf-batch-size)
-        (set (make-local-variable 'vlf-file-size)
-             (vlf-get-file-size buffer-file-truename))
-        (set (make-local-variable 'vlf-start-pos) 0)
-        (set (make-local-variable 'vlf-end-pos) 0)
-        (set (make-local-variable 'vlf-follow-timer) nil)
+        (setq vlf-file-size (vlf-get-file-size buffer-file-truename)
+              vlf-start-pos 0
+              vlf-end-pos 0)
         (let* ((pos (position-bytes (point)))
                (start (* (/ pos vlf-batch-size) vlf-batch-size)))
           (goto-char (byte-to-position (- pos start)))
           (vlf-move-to-batch start)))
     (kill-local-variable 'revert-buffer-function)
-    (vlf-stop-following)
+    (vlf-stop-follow)
     (when (or (not large-file-warning-threshold)
               (< vlf-file-size large-file-warning-threshold)
               (y-or-n-p (format "Load whole file (%s)? "
@@ -147,11 +122,43 @@
 You can customize number of bytes displayed by customizing
 `vlf-batch-size'."
   (interactive "fFile to open: ")
-  (with-current-buffer (generate-new-buffer "*vlf*")
+  (let ((vlf-buffer (generate-new-buffer "*vlf*")))
+    (set-buffer vlf-buffer)
     (set-visited-file-name file)
     (set-buffer-modified-p nil)
     (vlf-mode 1)
-    (switch-to-buffer (current-buffer))))
+    (switch-to-buffer vlf-buffer)
+    vlf-buffer))
+
+(defun vlf-next-batch (append)
+  "Display the next batch of file data.
+When prefix argument is supplied and positive
+ jump over APPEND number of batches.
+When prefix argument is negative
+ append next APPEND number of batches to the existing buffer."
+  (interactive "p")
+  (vlf-verify-size)
+  (let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append)))
+                   vlf-file-size))
+         (start (if (< append 0)
+                    vlf-start-pos
+                  (- end vlf-batch-size))))
+    (vlf-move-to-chunk start end)))
+
+(defun vlf-prev-batch (prepend)
+  "Display the previous batch of file data.
+When prefix argument is supplied and positive
+ jump over PREPEND number of batches.
+When prefix argument is negative
+ append previous PREPEND number of batches to the existing buffer."
+  (interactive "p")
+  (if (zerop vlf-start-pos)
+      (error "Already at BOF"))
+  (let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend)))))
+         (end (if (< prepend 0)
+                  vlf-end-pos
+                (+ start vlf-batch-size))))
+    (vlf-move-to-chunk start end)))
 
 ;; scroll auto batching
 (defadvice scroll-up (around vlf-scroll-up
@@ -183,45 +190,15 @@ with the prefix argument DECREASE it is halved."
                          (* vlf-batch-size 2)))
   (vlf-move-to-batch vlf-start-pos))
 
-(defun vlf-update-buffer-name ()
-  "Update the current buffer name."
-  (rename-buffer (format "%s(%d/%d)[%s]"
-                         (file-name-nondirectory buffer-file-name)
-                         (/ vlf-end-pos vlf-batch-size)
-                         (/ vlf-file-size vlf-batch-size)
-                         (file-size-human-readable vlf-batch-size))
-                 t))
-
-(defun vlf-get-file-size (file)
-  "Get size in bytes of FILE."
-  (or (nth 7 (file-attributes file)) 0))
-
-(defun vlf-verify-size ()
-  "Update file size information if necessary and visited file time."
-  (unless (verify-visited-file-modtime (current-buffer))
-    (setq vlf-file-size (vlf-get-file-size buffer-file-truename))
-    (set-visited-file-modtime)))
-
-(defun vlf-insert-file (&optional from-end)
-  "Insert first chunk of current file contents in current buffer.
-With FROM-END prefix, start from the back."
-  (let ((start 0)
-        (end vlf-batch-size))
-    (if from-end
-        (setq start (- vlf-file-size vlf-batch-size)
-              end vlf-file-size)
-      (setq end (min vlf-batch-size vlf-file-size)))
-    (vlf-move-to-chunk start end)))
-
 (defun vlf-beginning-of-file ()
   "Jump to beginning of file content."
   (interactive)
-  (vlf-insert-file))
+  (vlf-move-to-batch 0))
 
 (defun vlf-end-of-file ()
   "Jump to end of file content."
   (interactive)
-  (vlf-insert-file t))
+  (vlf-move-to-batch vlf-file-size))
 
 (defun vlf-revert (&optional _ignore-auto noconfirm)
   "Revert current chunk.  Ignore _IGNORE-AUTO.
@@ -231,7 +208,6 @@ Ask for confirmation if NOCONFIRM is nil."
             (yes-or-no-p (format "Revert buffer from file %s? "
                                  buffer-file-name)))
     (set-buffer-modified-p nil)
-    (set-visited-file-modtime)
     (vlf-move-to-chunk-2 vlf-start-pos vlf-end-pos)))
 
 (defun vlf-jump-to-chunk (n)
@@ -245,39 +221,6 @@ Ask for confirmation if NOCONFIRM is nil."
       (error "Save or discard your changes first")
     t))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; batch movement
-
-(defun vlf-next-batch (append)
-  "Display the next batch of file data.
-When prefix argument is supplied and positive
- jump over APPEND number of batches.
-When prefix argument is negative
- append next APPEND number of batches to the existing buffer."
-  (interactive "p")
-  (vlf-verify-size)
-  (let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append)))
-                   vlf-file-size))
-         (start (if (< append 0)
-                    vlf-start-pos
-                  (- end vlf-batch-size))))
-    (vlf-move-to-chunk start end)))
-
-(defun vlf-prev-batch (prepend)
-  "Display the previous batch of file data.
-When prefix argument is supplied and positive
- jump over PREPEND number of batches.
-When prefix argument is negative
- append previous PREPEND number of batches to the existing buffer."
-  (interactive "p")
-  (if (zerop vlf-start-pos)
-      (error "Already at BOF"))
-  (let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend)))))
-         (end (if (< prepend 0)
-                  vlf-end-pos
-                (+ start vlf-batch-size))))
-    (vlf-move-to-chunk start end)))
-
 (defun vlf-move-to-batch (start &optional minimal)
   "Move to batch determined by START.
 Adjust according to file start/end and show `vlf-batch-size' bytes.



reply via email to

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