[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 452b7eb 141/310: Ensure there are no modifications
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 452b7eb 141/310: Ensure there are no modifications when executing searches. |
Date: |
Sat, 28 Nov 2020 00:33:03 -0500 (EST) |
branch: externals/vlf
commit 452b7eb42d303c4720a3c9f045bb8a10a5d7288e
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Ensure there are no modifications when executing searches.
---
vlf.el | 162 ++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 84 insertions(+), 78 deletions(-)
diff --git a/vlf.el b/vlf.el
index ea2248a..a224bd3 100644
--- a/vlf.el
+++ b/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,63 +348,62 @@ 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))
- (edit-end (+ (position-bytes (point-max)) vlf-start-pos)))
- (cond
- ((and (= start vlf-start-pos) (= end edit-end))
- (unless modified
- (vlf-move-to-chunk-2 start end)
- 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
- (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? "))
- (let ((pos (+ (position-bytes (point)) vlf-start-pos))
- (shift-start 0)
- (shift-end 0)
- (inhibit-read-only t))
- (cond ((< end edit-end)
- (delete-region (byte-to-position (1+
- (- end
- vlf-start-pos)))
- (point-max)))
- ((< edit-end end)
- (let ((edit-end-pos (point-max)))
- (goto-char edit-end-pos)
- (insert-file-contents buffer-file-name nil
- vlf-end-pos end)
- (setq shift-end (cdr (vlf-adjust-chunk
- vlf-end-pos end nil t
- edit-end-pos))))))
- (cond ((< vlf-start-pos start)
- (delete-region (point-min) (byte-to-position
- (- start vlf-start-pos))))
- ((< start vlf-start-pos)
- (let ((edit-end-pos (point-max)))
- (goto-char edit-end-pos)
- (insert-file-contents buffer-file-name nil
- start vlf-start-pos)
- (setq shift-start (car
- (vlf-adjust-chunk start
- vlf-start-pos
- t nil
- edit-end-pos)))
- (goto-char (point-min))
- (insert (delete-and-extract-region edit-end-pos
- (point-max))))))
- (setq vlf-start-pos (- start shift-start)
- vlf-end-pos (+ end shift-end))
- (goto-char (or (byte-to-position (- pos vlf-start-pos))
- (point-max))))
- (set-buffer-modified-p modified)
- t)))))
+ (let ((modified (buffer-modified-p))
+ (start (max 0 start))
+ (end (min end vlf-file-size))
+ (edit-end (+ (position-bytes (point-max)) vlf-start-pos)))
+ (cond
+ ((and (= start vlf-start-pos) (= end edit-end))
+ (unless modified
+ (vlf-move-to-chunk-2 start end)
+ t))
+ ((or (<= edit-end start) (<= end vlf-start-pos))
+ (when (or (not modified)
+ (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 "Chunk modified, are you sure? "))
+ (let ((pos (+ (position-bytes (point)) vlf-start-pos))
+ (shift-start 0)
+ (shift-end 0)
+ (inhibit-read-only t))
+ (cond ((< end edit-end)
+ (delete-region (byte-to-position (1+
+ (- end
+ vlf-start-pos)))
+ (point-max)))
+ ((< edit-end end)
+ (let ((edit-end-pos (point-max)))
+ (goto-char edit-end-pos)
+ (insert-file-contents buffer-file-name nil
+ vlf-end-pos end)
+ (setq shift-end (cdr (vlf-adjust-chunk
+ vlf-end-pos end nil t
+ edit-end-pos))))))
+ (cond ((< vlf-start-pos start)
+ (delete-region (point-min) (byte-to-position
+ (- start vlf-start-pos))))
+ ((< start vlf-start-pos)
+ (let ((edit-end-pos (point-max)))
+ (goto-char edit-end-pos)
+ (insert-file-contents buffer-file-name nil
+ start vlf-start-pos)
+ (setq shift-start (car
+ (vlf-adjust-chunk start
+ vlf-start-pos
+ t nil
+ edit-end-pos)))
+ (goto-char (point-min))
+ (insert (delete-and-extract-region edit-end-pos
+ (point-max))))))
+ (setq vlf-start-pos (- start shift-start)
+ vlf-end-pos (+ end shift-end))
+ (goto-char (or (byte-to-position (- pos vlf-start-pos))
+ (point-max))))
+ (set-buffer-modified-p modified)
+ 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,28 +610,30 @@ 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: ")
- (let ((start-pos vlf-start-pos)
- (end-pos vlf-end-pos)
- (pos (point))
- (success nil))
- (unwind-protect
- (if (< 0 n)
- (progn (vlf-beginning-of-file)
- (goto-char (point-min))
- (setq success (vlf-re-search "[\n\C-m]" (1- n)
- nil 0)))
- (vlf-end-of-file)
- (goto-char (point-max))
- (setq success (vlf-re-search "[\n\C-m]" (- n) t 0)))
- (if success
- (message "Onto line %s" n)
- (vlf-move-to-chunk start-pos end-pos)
- (goto-char pos)))))
+ (vlf-no-modifications
+ (let ((start-pos vlf-start-pos)
+ (end-pos vlf-end-pos)
+ (pos (point))
+ (success nil))
+ (unwind-protect
+ (if (< 0 n)
+ (progn (vlf-beginning-of-file)
+ (goto-char (point-min))
+ (setq success (vlf-re-search "[\n\C-m]" (1- n)
+ nil 0)))
+ (vlf-end-of-file)
+ (goto-char (point-max))
+ (setq success (vlf-re-search "[\n\C-m]" (- n) t 0)))
+ (if success
+ (message "Onto line %s" n)
+ (vlf-move-to-chunk start-pos end-pos)
+ (goto-char pos))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; occur
- [elpa] externals/vlf 8f6299c 056/310: Simplify detection of buffer size change., (continued)
- [elpa] externals/vlf 8f6299c 056/310: Simplify detection of buffer size change., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f23262e 057/310: Add shift back of file contents when edited chunk shrinks in size., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2f201c5 061/310: Add jump to chunk command., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d5f2a36 060/310: Rearrange code in sections., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 705f9ce 064/310: Add issue section to the README., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9fad430 066/310: Fix positioning after save., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e545769 128/310: Fix adjusting of end chunk bytes., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ae2237d 135/310: Minor adjustments:, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf cb47e19 139/310: Use temporary buffer for occur in case of modifications., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 7a14109 137/310: Fix search for GNU Emacs 23 (no assert)., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 452b7eb 141/310: Ensure there are no modifications when executing searches.,
Stefan Monnier <=
- [elpa] externals/vlf a42247c 150/310: Automatically scroll to adjacent batch when start or end of chunk is, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 959bbc7 155/310: Disable undo in cases of partial chunk move., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a65f3a4 143/310: Check for unsaved changes before search query and don't enable undo if, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 42e581d 144/310: Add command to unconditionally open fresh VLF buffer to visit occur, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 3e8098a 149/310: Rename vlf-discard-edit -> vlf-refresh., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c0a85cd 159/310: Fix position when moving to overlapping chunk., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2aea17a 163/310: Fix behaviour when size is missing (creating file) in, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 88924f9 164/310: Fix vlf-write behaviour for newly created file., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9c50487 165/310: Introduce list of major modes where VLF will not activate., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 152462a 166/310: Fix autoloads in last commit., Stefan Monnier, 2020/11/28