From 7bfe66552453da53644efb65cf06a2f796b46c91 Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Wed, 1 May 2013 01:51:36 +0300 Subject: [PATCH 1/3] More secure chunk decode adjustment and minor fixes. --- vlfi.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/vlfi.el b/vlfi.el index b157ea3..19a3017 100644 --- a/vlfi.el +++ b/vlfi.el @@ -47,8 +47,7 @@ ;;; Keep track of file position. (defvar vlfi-start-pos 0 "Absolute position of the visible chunk start.") -(defvar vlfi-end-pos vlfi-batch-size - "Absolute position of the visible chunk end.") +(defvar vlfi-end-pos 0 "Absolute position of the visible chunk end.") (defvar vlfi-file-size 0 "Total size of presented file.") (defvar vlfi-mode-map @@ -97,10 +96,10 @@ buffer. You can customize number of bytes displayed by customizing `vlfi-batch-size'." (interactive "fFile to open: ") (with-current-buffer (generate-new-buffer "*vlfi*") + (vlfi-mode) (setq buffer-file-name file vlfi-file-size (vlfi-get-file-size file)) (vlfi-insert-file) - (vlfi-mode) (switch-to-buffer (current-buffer)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -350,15 +349,17 @@ When given MINIMAL flag, skip non important operations." (defun vlfi-adjust-chunk () "Adjust chunk beginning until content can be properly decoded. Return number of bytes moved back for this to happen." - (let ((shift 0)) + (let ((shift 0) + (chunk-size (- vlfi-end-pos vlfi-start-pos))) (while (and (not (zerop vlfi-start-pos)) - (< shift 3) - (/= (- vlfi-end-pos vlfi-start-pos) + (< shift 4) + (/= chunk-size (length (encode-coding-region (point-min) (point-max) buffer-file-coding-system t)))) (setq shift (1+ shift) - vlfi-start-pos (1- vlfi-start-pos)) + vlfi-start-pos (1- vlfi-start-pos) + chunk-size (1+ chunk-size)) (let ((inhibit-read-only t)) (erase-buffer) (insert-file-contents buffer-file-name nil From 3d652fe71dfc07cbac86e0d9eb9e24b58baf3604 Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Wed, 1 May 2013 02:02:28 +0300 Subject: [PATCH 2/3] Minor documentation fixes. --- README.org | 31 ++++++++++++++++++------------- vlfi.el | 4 ++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.org b/README.org index 034ca4e..a59d7a7 100644 --- a/README.org +++ b/README.org @@ -33,10 +33,11 @@ Emacs' Unicode support is leveraged so you'll not see bare bytes but characters decoded as if file is normally opened. This holds for editing, search and indexing. -** Bignums +** 32-bit GNU/Emacs -Regular Emacs integers are used, so if you have really huge file and -Emacs doesn't have bignum support, VLFI will probably not quite work. +Regular Emacs integers are used, so if you use 32-bit Emacs without +bignum support and have really huge file (with size beyond the maximum +integer value), VLFI will probably not quite work. ** Memory control @@ -49,8 +50,9 @@ example you can directly press digits to enter prefix arguments. ** Changing major mode -You can temporarily change major mode to whatever you like. Saving -will insert contents as intended. You can return to *vlfi-mode* too. +You can (temporarily) change major mode to whatever you like (for +example hexl-mode). Saving will insert contents as intended. You can +return to *vlfi-mode* too. * Detail usage @@ -82,17 +84,20 @@ you'd better set somewhat bigger batch size beforehand. *l* jumps to given line in file. This is done by searching from the beginning, so again the bigger current batch size, the quicker. -** Edit - -*e* enters VLFI in edit mode. If editing doesn't change size of -the chunk, only this chunk is saved. Otherwise the remaining part of -the file is adjusted chunk by chunk, so again you'd better have bigger -current batch size. If chunk has been expanded the memory used is -(batch size + difference to the original chunk size) x 2. - ** Occur over whole file *o* builds index for given regular expression just like occur-mode. It does this chunk by chunk over the whole file. Note that even if you prematurely stop it with *C-g*, it will still show index of what's found so far. + +** Edit + +*e* enters VLFI in edit mode. If editing doesn't change size of +the chunk, only this chunk is saved. Otherwise the remaining part of +the file is adjusted chunk by chunk, so again you'd better have bigger +current batch size. If chunk has been expanded the memory used is + +#+BEGIN_EXAMPLE +(batch size + difference to the original chunk size) x 2 +#+END_EXAMPLE diff --git a/vlfi.el b/vlfi.el index 19a3017..63f4684 100644 --- a/vlfi.el +++ b/vlfi.el @@ -26,9 +26,9 @@ ;;; Commentary: ;; This package provides the M-x vlfi command, which visits part of a -;; large file in a read-only buffer without visiting the entire file. +;; large file without loading the entire file. ;; The buffer uses VLFI mode, which defines several commands for -;; moving around, searching and editing selected chunk of file. +;; moving around, searching and editing selected part of file. ;; This package is upgraded version of the vlf.el package. From 67732485d842c946e1b40f8b9c1a6901ee98419a Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Wed, 1 May 2013 02:18:37 +0300 Subject: [PATCH 3/3] Optimize a bit goto line. --- vlfi.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vlfi.el b/vlfi.el index 63f4684..70cc6b3 100644 --- a/vlfi.el +++ b/vlfi.el @@ -370,8 +370,9 @@ Return number of bytes moved back for this to happen." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; search -(defun vlfi-re-search (regexp count backward) - "Search for REGEXP COUNT number of times forward or BACKWARD." +(defun vlfi-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." (let* ((match-chunk-start vlfi-start-pos) (match-chunk-end vlfi-end-pos) (match-start-pos (+ vlfi-start-pos (position-bytes (point)))) @@ -382,8 +383,7 @@ Return number of bytes moved back for this to happen." (if backward (- vlfi-file-size vlfi-end-pos) vlfi-start-pos) - vlfi-file-size)) - (batch-step (/ vlfi-batch-size 8))) ; amount of chunk overlap + vlfi-file-size))) (unwind-protect (catch 'end-of-file (if backward @@ -494,7 +494,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." (if regexp-history (car regexp-history))) (or current-prefix-arg 1))) - (vlfi-re-search regexp count nil)) + (vlfi-re-search regexp count nil (/ vlfi-batch-size 8))) (defun vlfi-re-search-backward (regexp count) "Search backward for REGEXP prefix COUNT number of times. @@ -503,7 +503,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." (if regexp-history (car regexp-history))) (or current-prefix-arg 1))) - (vlfi-re-search regexp count t)) + (vlfi-re-search regexp count t (/ vlfi-batch-size 8))) (defun vlfi-goto-line (n) "Go to line N." @@ -515,8 +515,8 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." (unwind-protect (progn (vlfi-beginning-of-file) (goto-char (point-min)) - (setq success (vlfi-re-search-forward "[\n\C-m]" - (1- n)))) + (setq success (vlfi-re-search "[\n\C-m]" (1- n) + nil 0))) (unless success (vlfi-move-to-chunk start-pos end-pos) (goto-char pos)))))