[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf a65f3a4 143/310: Check for unsaved changes before s
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf a65f3a4 143/310: Check for unsaved changes before search query and don't enable undo if |
Date: |
Sat, 28 Nov 2020 00:33:03 -0500 (EST) |
branch: externals/vlf
commit a65f3a431deecb017c631133bd877235680430b7
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Check for unsaved changes before search query and don't enable undo if
it was previously disabled.
---
vlf.el | 84 ++++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 43 insertions(+), 41 deletions(-)
diff --git a/vlf.el b/vlf.el
index a224bd3..daad2e5 100644
--- a/vlf.el
+++ b/vlf.el
@@ -272,16 +272,18 @@ Ask for confirmation if NOCONFIRM is nil."
(defmacro vlf-with-undo-disabled (&rest body)
"Execute BODY with temporarily disabled undo."
- (declare (indent defun))
- `(progn (buffer-disable-undo)
- (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))
+ `(let ((undo-enabled (not (eq buffer-undo-list t))))
+ (if undo-enabled
+ (buffer-disable-undo))
+ (unwind-protect (progn ,@body)
+ (if undo-enabled
+ (buffer-enable-undo)))))
+
+(defun vlf-no-modifications ()
+ "Ensure there are no buffer modifications."
+ (if (buffer-modified-p)
+ (error "Save or discard your changes first")
+ t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; batch movement
@@ -596,44 +598,44 @@ successful. Return nil if nothing found."
(defun vlf-re-search-forward (regexp count)
"Search forward for REGEXP prefix COUNT number of times.
Search is performed chunk by chunk in `vlf-batch-size' memory."
- (interactive (list (read-regexp "Search whole file"
- (if regexp-history
- (car regexp-history)))
- (or current-prefix-arg 1)))
- (vlf-no-modifications
- (vlf-re-search regexp count nil (/ vlf-batch-size 8))))
+ (interactive (if (vlf-no-modifications)
+ (list (read-regexp "Search whole file"
+ (if regexp-history
+ (car regexp-history)))
+ (or current-prefix-arg 1))))
+ (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.
Search is performed chunk by chunk in `vlf-batch-size' memory."
- (interactive (list (read-regexp "Search whole file backward"
- (if regexp-history
- (car regexp-history)))
- (or current-prefix-arg 1)))
- (vlf-no-modifications
- (vlf-re-search regexp count t (/ vlf-batch-size 8))))
+ (interactive (if (vlf-no-modifications)
+ (list (read-regexp "Search whole file backward"
+ (if regexp-history
+ (car regexp-history)))
+ (or current-prefix-arg 1))))
+ (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))
- (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))))))
+ (interactive (if (vlf-no-modifications)
+ (list (read-number "Go 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)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; occur
- [elpa] externals/vlf d5f2a36 060/310: Rearrange code in sections., (continued)
- [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, 2020/11/28
- [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 <=
- [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
- [elpa] externals/vlf e67895a 068/310: Optionally strip superfluous operations when inserting batches., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 6773248 104/310: Optimize a bit goto line., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4134de0 177/310: Add intelligent recenter chunk around point functionality., Stefan Monnier, 2020/11/28