mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 12:05:31 +00:00
Merge branch 'master' into chunk-opt2
Conflicts: vlfi.el
This commit is contained in:
commit
bbda9abc7d
31
README.org
31
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
|
||||
|
23
vlfi.el
23
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.
|
||||
|
||||
@ -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 0
|
||||
"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
|
||||
@ -426,8 +425,9 @@ Return cons \(success-status . number-of-bytes-moved-back\)."
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; 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))))
|
||||
@ -438,8 +438,7 @@ Return cons \(success-status . number-of-bytes-moved-back\)."
|
||||
(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
|
||||
@ -550,7 +549,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.
|
||||
@ -559,7 +558,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."
|
||||
@ -571,8 +570,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)))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user