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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/vlf ac8d400 276/310: Fixes to hexl-mode activation.


From: Stefan Monnier
Subject: [elpa] externals/vlf ac8d400 276/310: Fixes to hexl-mode activation.
Date: Sat, 28 Nov 2020 00:33:31 -0500 (EST)

branch: externals/vlf
commit ac8d4008bd2231ed2f7326fab0391e017daa6a19
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>

    Fixes to hexl-mode activation.
---
 vlf-occur.el  |  8 +++-----
 vlf-search.el | 23 ++++++++++++++---------
 vlf-write.el  | 13 ++++++-------
 3 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/vlf-occur.el b/vlf-occur.el
index 4694655..066709b 100644
--- a/vlf-occur.el
+++ b/vlf-occur.el
@@ -124,7 +124,7 @@ EVENT may hold details of the invocation."
                             pos-relative)))
           (cond (current-prefix-arg
                  (setq vlf-buffer (vlf file t))
-                 (or not-hexl (vlf-tune-hexlify))
+                 (or not-hexl (hexl-mode))
                  (switch-to-buffer occur-buffer))
                 ((not (buffer-live-p vlf-buffer))
                  (unless (catch 'found
@@ -137,7 +137,7 @@ EVENT may hold details of the invocation."
                                   (setq vlf-buffer buf)
                                   (throw 'found t))))
                    (setq vlf-buffer (vlf file t))
-                   (or not-hexl (vlf-tune-hexlify)))
+                   (or not-hexl (hexl-mode)))
                  (switch-to-buffer occur-buffer)
                  (setq vlf-occur-vlf-buffer vlf-buffer)))
           (pop-to-buffer vlf-buffer)
@@ -201,8 +201,7 @@ Prematurely ending indexing will still show what's found so 
far."
     (let ((start-pos vlf-start-pos)
           (end-pos vlf-end-pos)
           (pos (point))
-          (batch-size vlf-batch-size)
-          (is-hexl (derived-mode-p 'hexl-mode)))
+          (batch-size vlf-batch-size))
       (vlf-tune-batch (if (derived-mode-p 'hexl-mode)
                           '(:hexl :raw)
                         '(:insert :encode)) t)
@@ -211,7 +210,6 @@ Prematurely ending indexing will still show what's found so 
far."
        (goto-char (point-min))
        (unwind-protect (vlf-build-occur regexp (current-buffer))
          (vlf-move-to-chunk start-pos end-pos)
-         (if is-hexl (vlf-tune-hexlify))
          (goto-char pos)
          (setq vlf-batch-size batch-size)))))
   (run-hook-with-args 'vlf-after-batch-functions 'occur))
diff --git a/vlf-search.el b/vlf-search.el
index c60e631..7875b6c 100644
--- a/vlf-search.el
+++ b/vlf-search.el
@@ -135,7 +135,6 @@ Return t if search has been at least partially successful."
                                                   vlf-end-pos)))))
            (progress-reporter-done reporter))
        (set-buffer-modified-p nil)
-       (if is-hexl (vlf-tune-hexlify))
        (if font-lock (font-lock-mode 1))
        (let ((result
               (if backward
@@ -202,10 +201,13 @@ Search is performed chunk by chunk in `vlf-batch-size' 
memory."
                                       (if regexp-history
                                           (car regexp-history)))
                          (or current-prefix-arg 1))))
-  (let ((batch-size vlf-batch-size))
-    (or (vlf-re-search regexp count nil (min 1024 (/ vlf-batch-size 8))
-                       nil nil t)
-        (setq vlf-batch-size batch-size))))
+  (let ((batch-size vlf-batch-size)
+        success)
+    (unwind-protect
+        (setq success (vlf-re-search regexp count nil
+                                     (min 1024 (/ vlf-batch-size 8))
+                                     nil nil t))
+      (or success (setq vlf-batch-size batch-size)))))
 
 (defun vlf-re-search-backward (regexp count)
   "Search backward for REGEXP prefix COUNT number of times.
@@ -215,10 +217,13 @@ Search is performed chunk by chunk in `vlf-batch-size' 
memory."
                                       (if regexp-history
                                           (car regexp-history)))
                          (or current-prefix-arg 1))))
-  (let ((batch-size vlf-batch-size))
-    (or (vlf-re-search regexp count t (min 1024 (/ vlf-batch-size 8))
-                       nil nil t)
-        (setq vlf-batch-size batch-size))))
+  (let ((batch-size vlf-batch-size)
+        success)
+    (unwind-protect
+        (setq success (vlf-re-search regexp count t
+                                     (min 1024 (/ vlf-batch-size 8))
+                                     nil nil t))
+      (or success (setq vlf-batch-size batch-size)))))
 
 (defun vlf-goto-line (n)
   "Go to line N.  If N is negative, count from the end of file."
diff --git a/vlf-write.el b/vlf-write.el
index 5a656f7..d495b7f 100644
--- a/vlf-write.el
+++ b/vlf-write.el
@@ -55,6 +55,7 @@ If changing size of chunk, shift remaining file content."
           (progn (vlf-tune-write nil nil vlf-start-pos t
                                  (vlf-tune-encode-length (point-min)
                                                          (point-max)))
+                 (if hexl (vlf-tune-hexlify))
                  (setq vlf-file-size (vlf-get-file-size
                                       buffer-file-truename)
                        vlf-end-pos vlf-file-size)
@@ -64,8 +65,9 @@ If changing size of chunk, shift remaining file content."
                (size-change (- vlf-end-pos vlf-start-pos
                                region-length)))
           (if (zerop size-change)
-              (vlf-tune-write nil nil vlf-start-pos t
-                              (- vlf-end-pos vlf-start-pos))
+              (progn (vlf-tune-write nil nil vlf-start-pos t
+                                     (- vlf-end-pos vlf-start-pos))
+                     (if hexl (vlf-tune-hexlify)))
             (let ((pos (point))
                   (font-lock font-lock-mode)
                   (batch-size vlf-batch-size)
@@ -76,9 +78,7 @@ If changing size of chunk, shift remaining file content."
                           (y-or-n-p "File content needs be adjusted\
  till end.  Use temporary copy of the whole file (slower but safer)? ")
                         (not vlf-save-in-place)))
-                  (let ((file-tmp (make-temp-file
-                                   (file-name-nondirectory
-                                    buffer-file-name))))
+                  (let ((file-tmp (make-temp-file "vlf")))
                     (setq time (float-time))
                     (copy-file buffer-file-name file-tmp t t t t)
                     (if (< 0 size-change)
@@ -101,8 +101,7 @@ If changing size of chunk, shift remaining file content."
                                      vlf-end-pos))
               (vlf-update-buffer-name)
               (goto-char pos)
-              (message "Save took %f seconds" (- (float-time) time))))))
-      (if hexl (vlf-tune-hexlify)))
+              (message "Save took %f seconds" (- (float-time) time)))))))
     (run-hook-with-args 'vlf-after-batch-functions 'write))
   t)
 



reply via email to

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