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:
parent
a1ca1e3428
commit
274c5ab903
18
vlf-ediff.el
18
vlf-ediff.el
@ -161,12 +161,14 @@ logical chunks in case there is no difference at the current ones."
|
|||||||
(point-max-A (point-max))
|
(point-max-A (point-max))
|
||||||
(font-lock-A font-lock-mode)
|
(font-lock-A font-lock-mode)
|
||||||
(min-file-size vlf-file-size)
|
(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)
|
(font-lock-mode 0)
|
||||||
(set-buffer buffer-B)
|
(set-buffer buffer-B)
|
||||||
(run-hook-with-args 'vlf-before-batch-functions 'ediff)
|
(run-hook-with-args 'vlf-before-batch-functions 'ediff)
|
||||||
(setq buffer-B (current-buffer)
|
(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)
|
(let ((tramp-verbose (if (boundp 'tramp-verbose)
|
||||||
(min tramp-verbose 2)))
|
(min tramp-verbose 2)))
|
||||||
(end-B (= vlf-start-pos vlf-end-pos))
|
(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)))
|
buffer-B (point-min) (point-max)))
|
||||||
(with-current-buffer ediff-buffer
|
(with-current-buffer ediff-buffer
|
||||||
(ediff-update-diffs)
|
(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
|
(vlf-ediff-refine buffer-A
|
||||||
buffer-B))
|
buffer-B))
|
||||||
(zerop ediff-number-of-differences))))
|
(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))
|
(vlf-beginning-of-file))
|
||||||
(set-buffer ediff-buffer)
|
(set-buffer ediff-buffer)
|
||||||
(ediff-update-diffs)
|
(ediff-update-diffs)
|
||||||
(if (or (not forward-p)
|
(or is-hexl
|
||||||
(and (not end-A) (not end-B)))
|
(if (or (not forward-p)
|
||||||
(vlf-ediff-refine buffer-A buffer-B)))
|
(and (not end-A) (not end-B)))
|
||||||
|
(vlf-ediff-refine buffer-A buffer-B))))
|
||||||
(setq done t))
|
(setq done t))
|
||||||
(unless done
|
(unless done
|
||||||
(set-buffer buffer-A)
|
(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))
|
(vlf-move-to-chunk (car chunk-B) (cdr chunk-B))
|
||||||
(set-buffer ediff-buffer)
|
(set-buffer ediff-buffer)
|
||||||
(ediff-update-diffs)
|
(ediff-update-diffs)
|
||||||
(vlf-ediff-refine buffer-A buffer-B))
|
(or is-hexl
|
||||||
|
(vlf-ediff-refine buffer-A buffer-B)))
|
||||||
(set-buffer buffer-A)
|
(set-buffer buffer-A)
|
||||||
(if font-lock-A (font-lock-mode 1))
|
(if font-lock-A (font-lock-mode 1))
|
||||||
(run-hook-with-args 'vlf-after-batch-functions 'ediff)
|
(run-hook-with-args 'vlf-after-batch-functions 'ediff)
|
||||||
|
22
vlf-occur.el
22
vlf-occur.el
@ -165,6 +165,7 @@ Prematurely ending indexing will still show what's found so far."
|
|||||||
(line-regexp (concat "\\(?5:[\n\C-m]\\)\\|\\(?10:"
|
(line-regexp (concat "\\(?5:[\n\C-m]\\)\\|\\(?10:"
|
||||||
regexp "\\)"))
|
regexp "\\)"))
|
||||||
(batch-step (/ vlf-batch-size 8))
|
(batch-step (/ vlf-batch-size 8))
|
||||||
|
(is-hexl (derived-mode-p 'hexl-mode))
|
||||||
(end-of-file nil)
|
(end-of-file nil)
|
||||||
(reporter (make-progress-reporter
|
(reporter (make-progress-reporter
|
||||||
(concat "Building index for " regexp "...")
|
(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))
|
(setq end-of-file (= vlf-end-pos vlf-file-size))
|
||||||
(unless end-of-file
|
(unless end-of-file
|
||||||
(let ((batch-move (- vlf-end-pos batch-step)))
|
(let ((batch-move (- vlf-end-pos batch-step)))
|
||||||
(vlf-move-to-batch (if (< batch-move match-end-pos)
|
(vlf-move-to-batch (if (or is-hexl
|
||||||
match-end-pos
|
(< match-end-pos
|
||||||
batch-move) t))
|
batch-move))
|
||||||
(goto-char (if (< vlf-start-pos match-end-pos)
|
batch-move
|
||||||
(or (byte-to-position (- match-end-pos
|
match-end-pos) t))
|
||||||
vlf-start-pos))
|
(goto-char (if (or is-hexl
|
||||||
(point-min))
|
(<= match-end-pos vlf-start-pos))
|
||||||
(point-min)))
|
(point-min)
|
||||||
|
(or (byte-to-position (- match-end-pos
|
||||||
|
vlf-start-pos))
|
||||||
|
(point-min))))
|
||||||
(setq last-match-line 0
|
(setq last-match-line 0
|
||||||
last-line-pos (line-beginning-position))
|
last-line-pos (line-beginning-position))
|
||||||
(progress-reporter-update reporter vlf-end-pos))))
|
(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
|
(with-current-buffer occur-buffer
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(insert (propertize
|
(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)
|
in file: %s" total-matches line regexp file)
|
||||||
'face 'underline))
|
'face 'underline))
|
||||||
(set-buffer-modified-p nil)
|
(set-buffer-modified-p nil)
|
||||||
|
@ -43,6 +43,7 @@ BATCH-STEP is amount of overlap between successive chunks."
|
|||||||
(match-start-pos (+ vlf-start-pos (position-bytes (point))))
|
(match-start-pos (+ vlf-start-pos (position-bytes (point))))
|
||||||
(match-end-pos match-start-pos)
|
(match-end-pos match-start-pos)
|
||||||
(to-find count)
|
(to-find count)
|
||||||
|
(is-hexl (derived-mode-p 'hexl-mode))
|
||||||
(font-lock font-lock-mode)
|
(font-lock font-lock-mode)
|
||||||
(reporter (make-progress-reporter
|
(reporter (make-progress-reporter
|
||||||
(concat "Searching for " regexp "...")
|
(concat "Searching for " regexp "...")
|
||||||
@ -72,16 +73,18 @@ BATCH-STEP is amount of overlap between successive chunks."
|
|||||||
(- vlf-batch-size
|
(- vlf-batch-size
|
||||||
batch-step))))
|
batch-step))))
|
||||||
(vlf-move-to-batch
|
(vlf-move-to-batch
|
||||||
(if (< match-start-pos batch-move)
|
(if (or is-hexl
|
||||||
(- match-start-pos vlf-batch-size)
|
(<= batch-move match-start-pos))
|
||||||
batch-move) t))
|
batch-move
|
||||||
(goto-char (if (< match-start-pos
|
(- match-start-pos vlf-batch-size)) t))
|
||||||
vlf-end-pos)
|
(goto-char (if (or is-hexl
|
||||||
(or (byte-to-position
|
(<= vlf-end-pos
|
||||||
|
match-start-pos))
|
||||||
|
(point-max)
|
||||||
|
(or (byte-to-position
|
||||||
(- match-start-pos
|
(- match-start-pos
|
||||||
vlf-start-pos))
|
vlf-start-pos))
|
||||||
(point-max))
|
(point-max))))
|
||||||
(point-max)))
|
|
||||||
(progress-reporter-update
|
(progress-reporter-update
|
||||||
reporter (- vlf-file-size
|
reporter (- vlf-file-size
|
||||||
vlf-start-pos)))))
|
vlf-start-pos)))))
|
||||||
@ -100,15 +103,17 @@ BATCH-STEP is amount of overlap between successive chunks."
|
|||||||
(throw 'end-of-file nil))
|
(throw 'end-of-file nil))
|
||||||
(t (let ((batch-move (- vlf-end-pos batch-step)))
|
(t (let ((batch-move (- vlf-end-pos batch-step)))
|
||||||
(vlf-move-to-batch
|
(vlf-move-to-batch
|
||||||
(if (< batch-move match-end-pos)
|
(if (or is-hexl
|
||||||
match-end-pos
|
(< match-end-pos batch-move))
|
||||||
batch-move) t))
|
batch-move
|
||||||
(goto-char (if (< vlf-start-pos match-end-pos)
|
match-end-pos) t))
|
||||||
(or (byte-to-position
|
(goto-char (if (or is-hexl
|
||||||
|
(<= match-end-pos vlf-start-pos))
|
||||||
|
(point-min)
|
||||||
|
(or (byte-to-position
|
||||||
(- match-end-pos
|
(- match-end-pos
|
||||||
vlf-start-pos))
|
vlf-start-pos))
|
||||||
(point-min))
|
(point-min))))
|
||||||
(point-min)))
|
|
||||||
(progress-reporter-update reporter
|
(progress-reporter-update reporter
|
||||||
vlf-end-pos)))))
|
vlf-end-pos)))))
|
||||||
(progress-reporter-done reporter))
|
(progress-reporter-done reporter))
|
||||||
@ -189,6 +194,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
|||||||
(start-pos vlf-start-pos)
|
(start-pos vlf-start-pos)
|
||||||
(end-pos vlf-end-pos)
|
(end-pos vlf-end-pos)
|
||||||
(pos (point))
|
(pos (point))
|
||||||
|
(is-hexl (derived-mode-p 'hexl-mode))
|
||||||
(font-lock font-lock-mode)
|
(font-lock font-lock-mode)
|
||||||
(success nil))
|
(success nil))
|
||||||
(font-lock-mode 0)
|
(font-lock-mode 0)
|
||||||
@ -203,19 +209,20 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
|||||||
(inhibit-read-only t))
|
(inhibit-read-only t))
|
||||||
(setq n (1- n))
|
(setq n (1- n))
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
(while (and (< (- end start) n)
|
(or is-hexl
|
||||||
(< n (- vlf-file-size start)))
|
(while (and (< (- end start) n)
|
||||||
(erase-buffer)
|
(< n (- vlf-file-size start)))
|
||||||
(insert-file-contents-literally buffer-file-name
|
(erase-buffer)
|
||||||
nil start end)
|
(insert-file-contents-literally buffer-file-name
|
||||||
(goto-char (point-min))
|
nil start end)
|
||||||
(while (re-search-forward "[\n\C-m]" nil t)
|
(goto-char (point-min))
|
||||||
(setq n (1- n)))
|
(while (re-search-forward "[\n\C-m]" nil t)
|
||||||
(vlf-verify-size)
|
(setq n (1- n)))
|
||||||
(setq start end
|
(vlf-verify-size)
|
||||||
end (min vlf-file-size
|
(setq start end
|
||||||
(+ start vlf-batch-size)))
|
end (min vlf-file-size
|
||||||
(progress-reporter-update reporter start))
|
(+ start vlf-batch-size)))
|
||||||
|
(progress-reporter-update reporter start)))
|
||||||
(when (< n (- vlf-file-size end))
|
(when (< n (- vlf-file-size end))
|
||||||
(vlf-move-to-chunk-2 start end)
|
(vlf-move-to-chunk-2 start end)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
@ -229,17 +236,18 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
|||||||
(inhibit-read-only t))
|
(inhibit-read-only t))
|
||||||
(setq n (- n))
|
(setq n (- n))
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
(while (and (< (- end start) n) (< n end))
|
(or is-hexl
|
||||||
(erase-buffer)
|
(while (and (< (- end start) n) (< n end))
|
||||||
(insert-file-contents-literally buffer-file-name nil
|
(erase-buffer)
|
||||||
start end)
|
(insert-file-contents-literally buffer-file-name
|
||||||
(goto-char (point-max))
|
nil start end)
|
||||||
(while (re-search-backward "[\n\C-m]" nil t)
|
(goto-char (point-max))
|
||||||
(setq n (1- n)))
|
(while (re-search-backward "[\n\C-m]" nil t)
|
||||||
(setq end start
|
(setq n (1- n)))
|
||||||
start (max 0 (- end vlf-batch-size)))
|
(setq end start
|
||||||
(progress-reporter-update reporter
|
start (max 0 (- end vlf-batch-size)))
|
||||||
(- vlf-file-size end)))
|
(progress-reporter-update reporter
|
||||||
|
(- vlf-file-size end))))
|
||||||
(when (< n end)
|
(when (< n end)
|
||||||
(vlf-move-to-chunk-2 start end)
|
(vlf-move-to-chunk-2 start end)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
|
25
vlf.el
25
vlf.el
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
;; Copyright (C) 2006, 2012-2014 Free Software Foundation, Inc.
|
;; Copyright (C) 2006, 2012-2014 Free Software Foundation, Inc.
|
||||||
|
|
||||||
;; Version: 1.5
|
;; Version: 1.6
|
||||||
;; Keywords: large files, utilities
|
;; Keywords: large files, utilities
|
||||||
;; Maintainer: Andrey Kotlarski <m00naticus@gmail.com>
|
;; Maintainer: Andrey Kotlarski <m00naticus@gmail.com>
|
||||||
;; Authors: 2006 Mathias Dahl <mathias.dahl@gmail.com>
|
;; Authors: 2006 Mathias Dahl <mathias.dahl@gmail.com>
|
||||||
@ -207,23 +207,26 @@ When prefix argument is negative
|
|||||||
ad-do-it))
|
ad-do-it))
|
||||||
|
|
||||||
;; hexl mode integration
|
;; hexl mode integration
|
||||||
(defun vlf-hexl-before (&optional operation)
|
(defun vlf-hexl-disable (&optional operation)
|
||||||
"Temporarily disable `hexl-mode' for 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)
|
(hexl-mode-exit)
|
||||||
(set (make-local-variable 'vlf-restore-hexl-mode) operation)))
|
(set (make-local-variable 'vlf-restore-hexl-mode) operation)))
|
||||||
|
|
||||||
(defun vlf-hexl-after (&optional operation)
|
(defun vlf-hexl-enable (&optional _operation)
|
||||||
"Re-enable `hexl-mode' if active before OPERATION."
|
"Re-enable `hexl-mode' if active before _OPERATION."
|
||||||
(when (and (boundp 'vlf-restore-hexl-mode)
|
(when (boundp 'vlf-restore-hexl-mode)
|
||||||
(eq vlf-restore-hexl-mode operation))
|
|
||||||
(hexl-mode)
|
(hexl-mode)
|
||||||
(kill-local-variable 'vlf-restore-hexl-mode)))
|
(kill-local-variable 'vlf-restore-hexl-mode)))
|
||||||
|
|
||||||
(add-hook 'vlf-before-batch-functions 'vlf-hexl-before)
|
(add-hook 'vlf-before-batch-functions 'vlf-hexl-disable)
|
||||||
(add-hook 'vlf-after-batch-functions 'vlf-hexl-after)
|
(add-hook 'vlf-after-batch-functions 'vlf-hexl-enable)
|
||||||
(add-hook 'vlf-before-chunk-update 'vlf-hexl-before)
|
(add-hook 'vlf-before-chunk-update 'vlf-hexl-disable)
|
||||||
(add-hook 'vlf-after-chunk-update 'vlf-hexl-after)
|
(add-hook 'vlf-after-chunk-update 'vlf-hexl-enable)
|
||||||
|
|
||||||
(eval-after-load "hexl"
|
(eval-after-load "hexl"
|
||||||
'(progn
|
'(progn
|
||||||
|
Loading…
x
Reference in New Issue
Block a user