1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-18 20:10:47 +00:00

Merge branch 'master' into chunk-opt2

Conflicts:
	vlfi.el
This commit is contained in:
Andrey Kotlarski 2013-05-01 02:25:39 +03:00
commit bbda9abc7d
2 changed files with 29 additions and 25 deletions

View File

@ -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 characters decoded as if file is normally opened. This holds for
editing, search and indexing. editing, search and indexing.
** Bignums ** 32-bit GNU/Emacs
Regular Emacs integers are used, so if you have really huge file and Regular Emacs integers are used, so if you use 32-bit Emacs without
Emacs doesn't have bignum support, VLFI will probably not quite work. bignum support and have really huge file (with size beyond the maximum
integer value), VLFI will probably not quite work.
** Memory control ** Memory control
@ -49,8 +50,9 @@ example you can directly press digits to enter prefix arguments.
** Changing major mode ** Changing major mode
You can temporarily change major mode to whatever you like. Saving You can (temporarily) change major mode to whatever you like (for
will insert contents as intended. You can return to *vlfi-mode* too. example hexl-mode). Saving will insert contents as intended. You can
return to *vlfi-mode* too.
* Detail usage * 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 *l* jumps to given line in file. This is done by searching from the
beginning, so again the bigger current batch size, the quicker. 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 ** Occur over whole file
*o* builds index for given regular expression just like occur-mode. *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 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 you prematurely stop it with *C-g*, it will still show index of what's
found so far. 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

23
vlfi.el
View File

@ -26,9 +26,9 @@
;;; Commentary: ;;; Commentary:
;; This package provides the M-x vlfi command, which visits part of a ;; 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 ;; 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. ;; This package is upgraded version of the vlf.el package.
@ -47,8 +47,7 @@
;;; Keep track of file position. ;;; Keep track of file position.
(defvar vlfi-start-pos 0 (defvar vlfi-start-pos 0
"Absolute position of the visible chunk start.") "Absolute position of the visible chunk start.")
(defvar vlfi-end-pos 0 (defvar vlfi-end-pos 0 "Absolute position of the visible chunk end.")
"Absolute position of the visible chunk end.")
(defvar vlfi-file-size 0 "Total size of presented file.") (defvar vlfi-file-size 0 "Total size of presented file.")
(defvar vlfi-mode-map (defvar vlfi-mode-map
@ -426,8 +425,9 @@ Return cons \(success-status . number-of-bytes-moved-back\)."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; search ;;; search
(defun vlfi-re-search (regexp count backward) (defun vlfi-re-search (regexp count backward batch-step)
"Search for REGEXP COUNT number of times forward or BACKWARD." "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) (let* ((match-chunk-start vlfi-start-pos)
(match-chunk-end vlfi-end-pos) (match-chunk-end vlfi-end-pos)
(match-start-pos (+ vlfi-start-pos (position-bytes (point)))) (match-start-pos (+ vlfi-start-pos (position-bytes (point))))
@ -438,8 +438,7 @@ Return cons \(success-status . number-of-bytes-moved-back\)."
(if backward (if backward
(- vlfi-file-size vlfi-end-pos) (- vlfi-file-size vlfi-end-pos)
vlfi-start-pos) vlfi-start-pos)
vlfi-file-size)) vlfi-file-size)))
(batch-step (/ vlfi-batch-size 8))) ; amount of chunk overlap
(unwind-protect (unwind-protect
(catch 'end-of-file (catch 'end-of-file
(if backward (if backward
@ -550,7 +549,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(if regexp-history (if regexp-history
(car regexp-history))) (car regexp-history)))
(or current-prefix-arg 1))) (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) (defun vlfi-re-search-backward (regexp count)
"Search backward for REGEXP prefix COUNT number of times. "Search backward for REGEXP prefix COUNT number of times.
@ -559,7 +558,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(if regexp-history (if regexp-history
(car regexp-history))) (car regexp-history)))
(or current-prefix-arg 1))) (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) (defun vlfi-goto-line (n)
"Go to line N." "Go to line N."
@ -571,8 +570,8 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(unwind-protect (unwind-protect
(progn (vlfi-beginning-of-file) (progn (vlfi-beginning-of-file)
(goto-char (point-min)) (goto-char (point-min))
(setq success (vlfi-re-search-forward "[\n\C-m]" (setq success (vlfi-re-search "[\n\C-m]" (1- n)
(1- n)))) nil 0)))
(unless success (unless success
(vlfi-move-to-chunk start-pos end-pos) (vlfi-move-to-chunk start-pos end-pos)
(goto-char pos))))) (goto-char pos)))))