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

Perform search, occur and ediff operations over hexl content instead

over raw data when hexl-mode is active.
This commit is contained in:
Andrey Kotlarski 2014-08-12 03:19:33 +03:00
parent a1ca1e3428
commit 274c5ab903
4 changed files with 85 additions and 66 deletions

View File

@ -161,12 +161,14 @@ logical chunks in case there is no difference at the current ones."
(point-max-A (point-max))
(font-lock-A font-lock-mode)
(min-file-size vlf-file-size)
(forward-p (eq next-func 'vlf-next-chunk)))
(forward-p (eq next-func 'vlf-next-chunk))
(is-hexl (derived-mode-p 'hexl-mode)))
(font-lock-mode 0)
(set-buffer buffer-B)
(run-hook-with-args 'vlf-before-batch-functions 'ediff)
(setq buffer-B (current-buffer)
min-file-size (min min-file-size vlf-file-size))
min-file-size (min min-file-size vlf-file-size)
is-hexl (or is-hexl (derived-mode-p 'hexl-mode)))
(let ((tramp-verbose (if (boundp 'tramp-verbose)
(min tramp-verbose 2)))
(end-B (= vlf-start-pos vlf-end-pos))
@ -187,7 +189,7 @@ logical chunks in case there is no difference at the current ones."
buffer-B (point-min) (point-max)))
(with-current-buffer ediff-buffer
(ediff-update-diffs)
(and (not end-A) (not end-B)
(and (not end-A) (not end-B) (not is-hexl)
(vlf-ediff-refine buffer-A
buffer-B))
(zerop ediff-number-of-differences))))
@ -221,9 +223,10 @@ logical chunks in case there is no difference at the current ones."
(vlf-beginning-of-file))
(set-buffer ediff-buffer)
(ediff-update-diffs)
(if (or (not forward-p)
(and (not end-A) (not end-B)))
(vlf-ediff-refine buffer-A buffer-B)))
(or is-hexl
(if (or (not forward-p)
(and (not end-A) (not end-B)))
(vlf-ediff-refine buffer-A buffer-B))))
(setq done t))
(unless done
(set-buffer buffer-A)
@ -234,7 +237,8 @@ logical chunks in case there is no difference at the current ones."
(vlf-move-to-chunk (car chunk-B) (cdr chunk-B))
(set-buffer ediff-buffer)
(ediff-update-diffs)
(vlf-ediff-refine buffer-A buffer-B))
(or is-hexl
(vlf-ediff-refine buffer-A buffer-B)))
(set-buffer buffer-A)
(if font-lock-A (font-lock-mode 1))
(run-hook-with-args 'vlf-after-batch-functions 'ediff)

View File

@ -165,6 +165,7 @@ Prematurely ending indexing will still show what's found so far."
(line-regexp (concat "\\(?5:[\n\C-m]\\)\\|\\(?10:"
regexp "\\)"))
(batch-step (/ vlf-batch-size 8))
(is-hexl (derived-mode-p 'hexl-mode))
(end-of-file nil)
(reporter (make-progress-reporter
(concat "Building index for " regexp "...")
@ -222,14 +223,17 @@ Prematurely ending indexing will still show what's found so far."
(setq end-of-file (= vlf-end-pos vlf-file-size))
(unless end-of-file
(let ((batch-move (- vlf-end-pos batch-step)))
(vlf-move-to-batch (if (< batch-move match-end-pos)
match-end-pos
batch-move) t))
(goto-char (if (< vlf-start-pos match-end-pos)
(or (byte-to-position (- match-end-pos
vlf-start-pos))
(point-min))
(point-min)))
(vlf-move-to-batch (if (or is-hexl
(< match-end-pos
batch-move))
batch-move
match-end-pos) t))
(goto-char (if (or is-hexl
(<= match-end-pos vlf-start-pos))
(point-min)
(or (byte-to-position (- match-end-pos
vlf-start-pos))
(point-min))))
(setq last-match-line 0
last-line-pos (line-beginning-position))
(progress-reporter-update reporter vlf-end-pos))))
@ -243,7 +247,7 @@ Prematurely ending indexing will still show what's found so far."
(with-current-buffer occur-buffer
(goto-char (point-min))
(insert (propertize
(format "%d matches in %d lines for \"%s\" \
(format "%d matches from %d lines for \"%s\" \
in file: %s" total-matches line regexp file)
'face 'underline))
(set-buffer-modified-p nil)

View File

@ -43,6 +43,7 @@ BATCH-STEP is amount of overlap between successive chunks."
(match-start-pos (+ vlf-start-pos (position-bytes (point))))
(match-end-pos match-start-pos)
(to-find count)
(is-hexl (derived-mode-p 'hexl-mode))
(font-lock font-lock-mode)
(reporter (make-progress-reporter
(concat "Searching for " regexp "...")
@ -72,16 +73,18 @@ BATCH-STEP is amount of overlap between successive chunks."
(- vlf-batch-size
batch-step))))
(vlf-move-to-batch
(if (< match-start-pos batch-move)
(- match-start-pos vlf-batch-size)
batch-move) t))
(goto-char (if (< match-start-pos
vlf-end-pos)
(or (byte-to-position
(if (or is-hexl
(<= batch-move match-start-pos))
batch-move
(- match-start-pos vlf-batch-size)) t))
(goto-char (if (or is-hexl
(<= vlf-end-pos
match-start-pos))
(point-max)
(or (byte-to-position
(- match-start-pos
vlf-start-pos))
(point-max))
(point-max)))
(point-max))))
(progress-reporter-update
reporter (- vlf-file-size
vlf-start-pos)))))
@ -100,15 +103,17 @@ BATCH-STEP is amount of overlap between successive chunks."
(throw 'end-of-file nil))
(t (let ((batch-move (- vlf-end-pos batch-step)))
(vlf-move-to-batch
(if (< batch-move match-end-pos)
match-end-pos
batch-move) t))
(goto-char (if (< vlf-start-pos match-end-pos)
(or (byte-to-position
(if (or is-hexl
(< match-end-pos batch-move))
batch-move
match-end-pos) t))
(goto-char (if (or is-hexl
(<= match-end-pos vlf-start-pos))
(point-min)
(or (byte-to-position
(- match-end-pos
vlf-start-pos))
(point-min))
(point-min)))
(point-min))))
(progress-reporter-update reporter
vlf-end-pos)))))
(progress-reporter-done reporter))
@ -189,6 +194,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(start-pos vlf-start-pos)
(end-pos vlf-end-pos)
(pos (point))
(is-hexl (derived-mode-p 'hexl-mode))
(font-lock font-lock-mode)
(success nil))
(font-lock-mode 0)
@ -203,19 +209,20 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(inhibit-read-only t))
(setq n (1- n))
(vlf-with-undo-disabled
(while (and (< (- end start) n)
(< n (- vlf-file-size start)))
(erase-buffer)
(insert-file-contents-literally buffer-file-name
nil start end)
(goto-char (point-min))
(while (re-search-forward "[\n\C-m]" nil t)
(setq n (1- n)))
(vlf-verify-size)
(setq start end
end (min vlf-file-size
(+ start vlf-batch-size)))
(progress-reporter-update reporter start))
(or is-hexl
(while (and (< (- end start) n)
(< n (- vlf-file-size start)))
(erase-buffer)
(insert-file-contents-literally buffer-file-name
nil start end)
(goto-char (point-min))
(while (re-search-forward "[\n\C-m]" nil t)
(setq n (1- n)))
(vlf-verify-size)
(setq start end
end (min vlf-file-size
(+ start vlf-batch-size)))
(progress-reporter-update reporter start)))
(when (< n (- vlf-file-size end))
(vlf-move-to-chunk-2 start end)
(goto-char (point-min))
@ -229,17 +236,18 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(inhibit-read-only t))
(setq n (- n))
(vlf-with-undo-disabled
(while (and (< (- end start) n) (< n end))
(erase-buffer)
(insert-file-contents-literally buffer-file-name nil
start end)
(goto-char (point-max))
(while (re-search-backward "[\n\C-m]" nil t)
(setq n (1- n)))
(setq end start
start (max 0 (- end vlf-batch-size)))
(progress-reporter-update reporter
(- vlf-file-size end)))
(or is-hexl
(while (and (< (- end start) n) (< n end))
(erase-buffer)
(insert-file-contents-literally buffer-file-name
nil start end)
(goto-char (point-max))
(while (re-search-backward "[\n\C-m]" nil t)
(setq n (1- n)))
(setq end start
start (max 0 (- end vlf-batch-size)))
(progress-reporter-update reporter
(- vlf-file-size end))))
(when (< n end)
(vlf-move-to-chunk-2 start end)
(goto-char (point-max))

25
vlf.el
View 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>
@ -207,23 +207,26 @@ When prefix argument is negative
ad-do-it))
;; hexl mode integration
(defun vlf-hexl-before (&optional operation)
(defun vlf-hexl-disable (&optional operation)
"Temporarily disable `hexl-mode' for OPERATION."
(when (derived-mode-p 'hexl-mode)
(when (and (derived-mode-p 'hexl-mode)
(or (not operation)
(eq operation 'write)))
(if (consp buffer-undo-list)
(setq buffer-undo-list nil))
(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))
(defun vlf-hexl-enable (&optional _operation)
"Re-enable `hexl-mode' if active before _OPERATION."
(when (boundp 'vlf-restore-hexl-mode)
(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)
(add-hook 'vlf-before-batch-functions 'vlf-hexl-disable)
(add-hook 'vlf-after-batch-functions 'vlf-hexl-enable)
(add-hook 'vlf-before-chunk-update 'vlf-hexl-disable)
(add-hook 'vlf-after-chunk-update 'vlf-hexl-enable)
(eval-after-load "hexl"
'(progn