1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-04-19 01:00:19 +01:00

Ensure there are no modifications when executing searches.

This commit is contained in:
Andrey Kotlarski 2013-12-03 02:37:13 +02:00
parent 2dba838015
commit 452b7eb42d

24
vlf.el
View File

@ -277,6 +277,12 @@ Ask for confirmation if NOCONFIRM is nil."
(unwind-protect (progn ,@body) (unwind-protect (progn ,@body)
(buffer-enable-undo)))) (buffer-enable-undo))))
(defmacro vlf-no-modifications (&rest body)
"Ensure there are no modifications and execute BODY."
`(if (buffer-modified-p)
(error "Save or discard your changes first")
,@body))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; batch movement ;;; batch movement
@ -342,7 +348,6 @@ If same as current chunk is requested, do nothing."
(defun vlf-move-to-chunk-1 (start end) (defun vlf-move-to-chunk-1 (start end)
"Move to chunk determined by START END keeping as much edits if any. "Move to chunk determined by START END keeping as much edits if any.
Return t if move hasn't been canceled." Return t if move hasn't been canceled."
(vlf-with-undo-disabled
(let ((modified (buffer-modified-p)) (let ((modified (buffer-modified-p))
(start (max 0 start)) (start (max 0 start))
(end (min end vlf-file-size)) (end (min end vlf-file-size))
@ -354,12 +359,12 @@ Return t if move hasn't been canceled."
t)) t))
((or (<= edit-end start) (<= end vlf-start-pos)) ((or (<= edit-end start) (<= end vlf-start-pos))
(when (or (not modified) (when (or (not modified)
(y-or-n-p "Buffer modified, are you sure? ")) ;full chunk renewal (y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal
(vlf-move-to-chunk-2 start end) (vlf-move-to-chunk-2 start end)
t)) t))
((or (and (<= start vlf-start-pos) (<= edit-end end)) ((or (and (<= start vlf-start-pos) (<= edit-end end))
(not modified) (not modified)
(y-or-n-p "Buffer modified, are you sure? ")) (y-or-n-p "Chunk modified, are you sure? "))
(let ((pos (+ (position-bytes (point)) vlf-start-pos)) (let ((pos (+ (position-bytes (point)) vlf-start-pos))
(shift-start 0) (shift-start 0)
(shift-end 0) (shift-end 0)
@ -398,7 +403,7 @@ Return t if move hasn't been canceled."
(goto-char (or (byte-to-position (- pos vlf-start-pos)) (goto-char (or (byte-to-position (- pos vlf-start-pos))
(point-max)))) (point-max))))
(set-buffer-modified-p modified) (set-buffer-modified-p modified)
t))))) t))))
(defun vlf-move-to-chunk-2 (start end) (defun vlf-move-to-chunk-2 (start end)
"Unconditionally move to chunk determined by START END." "Unconditionally move to chunk determined by START END."
@ -484,7 +489,6 @@ BATCH-STEP is amount of overlap between successive chunks."
(- vlf-file-size vlf-end-pos) (- vlf-file-size vlf-end-pos)
vlf-start-pos) vlf-start-pos)
vlf-file-size))) vlf-file-size)))
(set-buffer-modified-p nil)
(vlf-with-undo-disabled (vlf-with-undo-disabled
(unwind-protect (unwind-protect
(catch 'end-of-file (catch 'end-of-file
@ -546,7 +550,6 @@ BATCH-STEP is amount of overlap between successive chunks."
(progress-reporter-update reporter (progress-reporter-update reporter
vlf-end-pos))))) vlf-end-pos)))))
(progress-reporter-done reporter)) (progress-reporter-done reporter))
(set-buffer-modified-p nil)
(if backward (if backward
(vlf-goto-match match-chunk-start match-chunk-end (vlf-goto-match match-chunk-start match-chunk-end
match-end-pos match-start-pos match-end-pos match-start-pos
@ -597,7 +600,8 @@ 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 (/ vlf-batch-size 8))) (vlf-no-modifications
(vlf-re-search regexp count nil (/ vlf-batch-size 8))))
(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.
@ -606,11 +610,13 @@ 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 (/ vlf-batch-size 8))) (vlf-no-modifications
(vlf-re-search regexp count t (/ vlf-batch-size 8))))
(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."
(interactive "nGo to line: ") (interactive "nGo to line: ")
(vlf-no-modifications
(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))
@ -627,7 +633,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(if success (if success
(message "Onto line %s" n) (message "Onto line %s" n)
(vlf-move-to-chunk start-pos end-pos) (vlf-move-to-chunk start-pos end-pos)
(goto-char pos))))) (goto-char pos))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; occur ;;; occur