]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/vlf/vlf.el
[vlf] bump version
[gnu-emacs-elpa] / packages / vlf / vlf.el
index 2e3c9a1b8eef4ff515a33b3b1e5403cfda66c635..07554faf82a649e8224412a83e121a37692bfe5e 100644 (file)
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2006, 2012-2014 Free Software Foundation, Inc.
 
-;; Version: 1.5
+;; Version: 1.6
 ;; Keywords: large files, utilities
 ;; Maintainer: Andrey Kotlarski <m00naticus@gmail.com>
 ;; Authors: 2006 Mathias Dahl <mathias.dahl@gmail.com>
@@ -39,8 +39,7 @@
 
 ;;; Code:
 
-(defgroup vlf nil "View Large Files in Emacs."
-  :prefix "vlf-" :group 'files)
+(require 'vlf-base)
 
 (defcustom vlf-before-batch-functions nil
   "Hook that runs before multiple batch operations.
@@ -54,8 +53,6 @@ One argument is supplied that specifies current action.  Possible
 values are: `write', `ediff', `occur', `search', `goto-line'."
   :group 'vlf :type 'hook)
 
-(require 'vlf-base)
-
 (autoload 'vlf-write "vlf-write" "Write current chunk to file." t)
 (autoload 'vlf-re-search-forward "vlf-search"
   "Search forward for REGEXP prefix COUNT number of times." t)
@@ -145,17 +142,22 @@ values are: `write', `ediff', `occur', `search', `goto-line'."
   (setq vlf-mode t))
 
 ;;;###autoload
-(defun vlf (file)
-  "View Large FILE in batches.
+(defun vlf (file &optional minimal)
+  "View Large FILE in batches.  When MINIMAL load just a few bytes.
 You can customize number of bytes displayed by customizing
 `vlf-batch-size'.
 Return newly created buffer."
-  (interactive "fFile to open: ")
+  (interactive (list (read-file-name "File to open: ") nil))
   (let ((vlf-buffer (generate-new-buffer "*vlf*")))
     (set-buffer vlf-buffer)
     (set-visited-file-name file)
     (set-buffer-modified-p nil)
+    (if (or minimal (file-remote-p file))
+        (set (make-local-variable 'vlf-batch-size) 1024))
     (vlf-mode 1)
+    (when minimal                 ;restore batch size to default value
+      (kill-local-variable 'vlf-batch-size)
+      (make-local-variable 'vlf-batch-size))
     (switch-to-buffer vlf-buffer)
     vlf-buffer))
 
@@ -167,6 +169,9 @@ When prefix argument is negative
  append next APPEND number of batches to the existing buffer."
   (interactive "p")
   (vlf-verify-size)
+  (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+                     '(:hexl :dehexlify :insert :encode)
+                   '(:insert :encode)))
   (let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append)))
                    vlf-file-size))
          (start (if (< append 0)
@@ -183,6 +188,9 @@ When prefix argument is negative
   (interactive "p")
   (if (zerop vlf-start-pos)
       (error "Already at BOF"))
+  (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+                     '(:hexl :dehexlify :insert :encode)
+                   '(:insert :encode)))
   (let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend)))))
          (end (if (< prepend 0)
                   vlf-end-pos
@@ -206,24 +214,8 @@ When prefix argument is negative
              (goto-char (point-max)))
     ad-do-it))
 
-;; hexl mode integration
-(defun vlf-hexl-before (&optional operation)
-  "Temporarily disable `hexl-mode' for OPERATION."
-  (when (derived-mode-p 'hexl-mode)
-    (hexl-mode-exit)
-    (set (make-local-variable 'vlf-restore-hexl-mode) operation)))
-
-(defun vlf-hexl-after (&optional operation)
-  "Re-enable `hexl-mode' if active before OPERATION."
-  (when (and (boundp 'vlf-restore-hexl-mode)
-             (eq vlf-restore-hexl-mode operation))
-    (hexl-mode)
-    (kill-local-variable 'vlf-restore-hexl-mode)))
-
-(add-hook 'vlf-before-batch-functions 'vlf-hexl-before)
-(add-hook 'vlf-after-batch-functions 'vlf-hexl-after)
-(add-hook 'vlf-before-chunk-update 'vlf-hexl-before)
-(add-hook 'vlf-after-chunk-update 'vlf-hexl-after)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; hexl mode integration
 
 (eval-after-load "hexl"
   '(progn
@@ -264,23 +256,34 @@ with the prefix argument DECREASE it is halved."
 
 (defun vlf-set-batch-size (size)
   "Set batch to SIZE bytes and update chunk."
-  (interactive (list (read-number "Size in bytes: " vlf-batch-size)))
+  (interactive
+   (list (read-number "Size in bytes: "
+                      (vlf-tune-optimal-load
+                       (if (derived-mode-p 'hexl-mode)
+                           '(:hexl :dehexlify :insert :encode)
+                         '(:insert :encode))))))
   (setq vlf-batch-size size)
   (vlf-move-to-batch vlf-start-pos))
 
 (defun vlf-beginning-of-file ()
   "Jump to beginning of file content."
   (interactive)
+  (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+                     '(:hexl :dehexlify :insert :encode)
+                   '(:insert :encode)))
   (vlf-move-to-batch 0))
 
 (defun vlf-end-of-file ()
   "Jump to end of file content."
   (interactive)
   (vlf-verify-size)
+  (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+                     '(:hexl :dehexlify :insert :encode)
+                   '(:insert :encode)))
   (vlf-move-to-batch vlf-file-size))
 
-(defun vlf-revert (&optional _ignore-auto noconfirm)
-  "Revert current chunk.  Ignore _IGNORE-AUTO.
+(defun vlf-revert (&optional _auto noconfirm)
+  "Revert current chunk.  Ignore _AUTO.
 Ask for confirmation if NOCONFIRM is nil."
   (interactive)
   (when (or noconfirm
@@ -292,6 +295,9 @@ Ask for confirmation if NOCONFIRM is nil."
 (defun vlf-jump-to-chunk (n)
   "Go to to chunk N."
   (interactive "nGoto to chunk: ")
+  (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+                     '(:hexl :dehexlify :insert :encode)
+                   '(:insert :encode)))
   (vlf-move-to-batch (* (1- n) vlf-batch-size)))
 
 (defun vlf-no-modifications ()