1
0
mirror of https://github.com/m00natic/vlfi.git synced 2024-10-05 18:30:51 +01:00

Restore batch size and hexl mode in case of failed search or occur.

This commit is contained in:
Andrey Kotlarski 2014-09-07 18:04:17 +03:00
parent d526ea8ef8
commit 0d2c096ed6
2 changed files with 26 additions and 14 deletions

View File

@ -200,7 +200,8 @@ Prematurely ending indexing will still show what's found so far."
(let ((start-pos vlf-start-pos) (let ((start-pos vlf-start-pos)
(end-pos vlf-end-pos) (end-pos vlf-end-pos)
(pos (point)) (pos (point))
(batch-size vlf-batch-size)) (batch-size vlf-batch-size)
(is-hexl (derived-mode-p 'hexl-mode)))
(vlf-tune-batch (if (derived-mode-p 'hexl-mode) (vlf-tune-batch (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode) '(:hexl :dehexlify :insert :encode)
'(:insert :encode))) '(:insert :encode)))
@ -209,8 +210,9 @@ Prematurely ending indexing will still show what's found so far."
(goto-char (point-min)) (goto-char (point-min))
(unwind-protect (vlf-build-occur regexp (current-buffer)) (unwind-protect (vlf-build-occur regexp (current-buffer))
(vlf-move-to-chunk start-pos end-pos) (vlf-move-to-chunk start-pos end-pos)
(goto-char pos))) (if is-hexl (vlf-tune-hexlify))
(setq vlf-batch-size batch-size))) (goto-char pos)
(setq vlf-batch-size batch-size)))))
(run-hook-with-args 'vlf-after-batch-functions 'occur)) (run-hook-with-args 'vlf-after-batch-functions 'occur))
(defun vlf-build-occur (regexp vlf-buffer) (defun vlf-build-occur (regexp vlf-buffer)

View File

@ -33,7 +33,8 @@
&optional reporter time) &optional reporter time)
"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. BATCH-STEP is amount of overlap between successive chunks.
Use existing REPORTER and start TIME if given." Use existing REPORTER and start TIME if given.
Return t if search has been at least partially successful."
(if (<= count 0) (if (<= count 0)
(error "Count must be positive")) (error "Count must be positive"))
(run-hook-with-args 'vlf-before-batch-functions 'search) (run-hook-with-args 'vlf-before-batch-functions 'search)
@ -125,15 +126,18 @@ Use existing REPORTER and start TIME if given."
vlf-end-pos))))) vlf-end-pos)))))
(progress-reporter-done reporter)) (progress-reporter-done reporter))
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(if is-hexl (vlf-tune-hexlify))
(if font-lock (font-lock-mode 1)) (if font-lock (font-lock-mode 1))
(if backward (let ((result
(vlf-goto-match match-chunk-start match-chunk-end (if backward
match-end-pos match-start-pos (vlf-goto-match match-chunk-start match-chunk-end
count to-find time) match-end-pos match-start-pos
(vlf-goto-match match-chunk-start match-chunk-end count to-find time)
match-start-pos match-end-pos (vlf-goto-match match-chunk-start match-chunk-end
count to-find time)) match-start-pos match-end-pos
(run-hook-with-args 'vlf-after-batch-functions 'search))))) count to-find time))))
(run-hook-with-args 'vlf-after-batch-functions 'search)
result)))))
(defun vlf-goto-match (match-chunk-start match-chunk-end (defun vlf-goto-match (match-chunk-start match-chunk-end
match-pos-start match-pos-end match-pos-start match-pos-end
@ -179,7 +183,9 @@ Search is performed chunk by chunk in `vlf-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))))
(vlf-re-search regexp count nil (min 1024 (/ vlf-batch-size 8)))) (let ((batch-size vlf-batch-size))
(or (vlf-re-search regexp count nil (min 1024 (/ vlf-batch-size 8)))
(setq vlf-batch-size batch-size))))
(defun vlf-re-search-backward (regexp count) (defun vlf-re-search-backward (regexp count)
"Search backward for REGEXP prefix COUNT number of times. "Search backward for REGEXP prefix COUNT number of times.
@ -189,7 +195,9 @@ Search is performed chunk by chunk in `vlf-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))))
(vlf-re-search regexp count t (min 1024 (/ vlf-batch-size 8)))) (let ((batch-size vlf-batch-size))
(or (vlf-re-search regexp count t (min 1024 (/ vlf-batch-size 8)))
(setq vlf-batch-size batch-size))))
(defun vlf-goto-line (n) (defun vlf-goto-line (n)
"Go to line N. If N is negative, count from the end of file." "Go to line N. If N is negative, count from the end of file."
@ -201,6 +209,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(min tramp-verbose 2))) (min tramp-verbose 2)))
(start-pos vlf-start-pos) (start-pos vlf-start-pos)
(end-pos vlf-end-pos) (end-pos vlf-end-pos)
(batch-size vlf-batch-size)
(pos (point)) (pos (point))
(is-hexl (derived-mode-p 'hexl-mode)) (is-hexl (derived-mode-p 'hexl-mode))
(font-lock font-lock-mode) (font-lock font-lock-mode)
@ -276,6 +285,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(vlf-move-to-chunk-2 start-pos end-pos)) (vlf-move-to-chunk-2 start-pos end-pos))
(vlf-update-buffer-name) (vlf-update-buffer-name)
(goto-char pos) (goto-char pos)
(setq vlf-batch-size batch-size)
(message "Unable to find line")) (message "Unable to find line"))
(run-hook-with-args 'vlf-after-batch-functions 'goto-line)))) (run-hook-with-args 'vlf-after-batch-functions 'goto-line))))