mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 20:10:47 +00:00
Ensure there are no modifications when executing searches.
This commit is contained in:
parent
2dba838015
commit
452b7eb42d
24
vlf.el
24
vlf.el
@ -277,6 +277,12 @@ Ask for confirmation if NOCONFIRM is nil."
|
||||
(unwind-protect (progn ,@body)
|
||||
(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
|
||||
|
||||
@ -342,7 +348,6 @@ If same as current chunk is requested, do nothing."
|
||||
(defun vlf-move-to-chunk-1 (start end)
|
||||
"Move to chunk determined by START END keeping as much edits if any.
|
||||
Return t if move hasn't been canceled."
|
||||
(vlf-with-undo-disabled
|
||||
(let ((modified (buffer-modified-p))
|
||||
(start (max 0 start))
|
||||
(end (min end vlf-file-size))
|
||||
@ -354,12 +359,12 @@ Return t if move hasn't been canceled."
|
||||
t))
|
||||
((or (<= edit-end start) (<= end vlf-start-pos))
|
||||
(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)
|
||||
t))
|
||||
((or (and (<= start vlf-start-pos) (<= edit-end end))
|
||||
(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))
|
||||
(shift-start 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))
|
||||
(point-max))))
|
||||
(set-buffer-modified-p modified)
|
||||
t)))))
|
||||
t))))
|
||||
|
||||
(defun vlf-move-to-chunk-2 (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-start-pos)
|
||||
vlf-file-size)))
|
||||
(set-buffer-modified-p nil)
|
||||
(vlf-with-undo-disabled
|
||||
(unwind-protect
|
||||
(catch 'end-of-file
|
||||
@ -546,7 +550,6 @@ BATCH-STEP is amount of overlap between successive chunks."
|
||||
(progress-reporter-update reporter
|
||||
vlf-end-pos)))))
|
||||
(progress-reporter-done reporter))
|
||||
(set-buffer-modified-p nil)
|
||||
(if backward
|
||||
(vlf-goto-match match-chunk-start match-chunk-end
|
||||
match-end-pos match-start-pos
|
||||
@ -597,7 +600,8 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
||||
(if regexp-history
|
||||
(car regexp-history)))
|
||||
(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)
|
||||
"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
|
||||
(car regexp-history)))
|
||||
(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)
|
||||
"Go to line N. If N is negative, count from the end of file."
|
||||
(interactive "nGo to line: ")
|
||||
(vlf-no-modifications
|
||||
(let ((start-pos vlf-start-pos)
|
||||
(end-pos vlf-end-pos)
|
||||
(pos (point))
|
||||
@ -627,7 +633,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
||||
(if success
|
||||
(message "Onto line %s" n)
|
||||
(vlf-move-to-chunk start-pos end-pos)
|
||||
(goto-char pos)))))
|
||||
(goto-char pos))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; occur
|
||||
|
Loading…
x
Reference in New Issue
Block a user