diff --git a/vlf-base.el b/vlf-base.el index 124ee56..d06d03f 100644 --- a/vlf-base.el +++ b/vlf-base.el @@ -27,6 +27,31 @@ ;;; Code: +(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.") diff --git a/vlf-follow.el b/vlf-follow.el index 1716faa..e6740f2 100644 --- a/vlf-follow.el +++ b/vlf-follow.el @@ -27,6 +27,11 @@ ;;; Code: +(eval-when-compile + (add-to-list 'load-path default-directory)) + +(require 'vlf) + (defvar vlf-follow-timer nil "Contains timer if vlf buffer is set to continuously recenter.") (make-variable-buffer-local 'vlf-follow-timer) diff --git a/vlf-integrate.el b/vlf-integrate.el index cf21898..8ead400 100644 --- a/vlf-integrate.el +++ b/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.") + (defadvice abort-if-file-too-large (around vlf-if-file-too-large compile activate) "If file SIZE larger than `large-file-warning-threshold', \ diff --git a/vlf-occur.el b/vlf-occur.el index b8e96e1..71a2fc5 100644 --- a/vlf-occur.el +++ b/vlf-occur.el @@ -27,6 +27,11 @@ ;;; Code: +(eval-when-compile + (add-to-list 'load-path default-directory)) + +(require 'vlf) + (defvar vlf-occur-mode-map (let ((map (make-sparse-keymap))) (define-key map "n" 'vlf-occur-next-match) @@ -126,7 +131,7 @@ Prematurely ending indexing will still show what's found so far." (with-temp-buffer (setq buffer-file-name file) (set-buffer-modified-p nil) - (setq-local vlf-batch-size batch-size) + (set (make-local-variable 'vlf-batch-size) batch-size) (vlf-mode 1) (goto-char (point-min)) (vlf-with-undo-disabled diff --git a/vlf-search.el b/vlf-search.el index 25063c1..26ca0d0 100644 --- a/vlf-search.el +++ b/vlf-search.el @@ -27,6 +27,11 @@ ;;; Code: +(eval-when-compile + (add-to-list 'load-path default-directory)) + +(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/vlf-write.el b/vlf-write.el index f473742..25e9419 100644 --- a/vlf-write.el +++ b/vlf-write.el @@ -27,6 +27,11 @@ ;;; Code: +(eval-when-compile + (add-to-list 'load-path default-directory)) + +(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." diff --git a/vlf.el b/vlf.el index cfa06ae..f3dc76c 100644 --- a/vlf.el +++ b/vlf.el @@ -39,33 +39,11 @@ ;;; Code: +(eval-when-compile + (add-to-list 'load-path default-directory)) + (require 'vlf-base) -(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) - (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.") @@ -114,9 +92,10 @@ :keymap vlf-prefix-map (if vlf-mode (progn - (setq-local require-final-newline nil) + (set (make-local-variable 'require-final-newline) nil) (add-hook 'write-file-functions 'vlf-write nil t) - (setq-local revert-buffer-function 'vlf-revert) + (set (make-local-variable 'revert-buffer-function) + 'vlf-revert) (make-local-variable 'vlf-batch-size) (setq vlf-file-size (vlf-get-file-size buffer-file-truename) vlf-start-pos 0 @@ -153,6 +132,36 @@ You can customize number of bytes displayed by customizing (vlf-mode 1) (switch-to-buffer (current-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 activate compile) @@ -225,39 +234,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.