emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]