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

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

[elpa] externals/vlf 86223ed 234/310: Fixes to hexl-mode integration.


From: Stefan Monnier
Subject: [elpa] externals/vlf 86223ed 234/310: Fixes to hexl-mode integration.
Date: Sat, 28 Nov 2020 00:33:22 -0500 (EST)

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

    Fixes to hexl-mode integration.
---
 vlf-base.el  | 45 ++++++++++++++++++++++++++++++-----------
 vlf-occur.el | 13 +++++++++---
 vlf-write.el | 66 +++++++++++++++++++++++++++++++++---------------------------
 vlf.el       | 23 ++-------------------
 4 files changed, 81 insertions(+), 66 deletions(-)

diff --git a/vlf-base.el b/vlf-base.el
index e9a11bc..1e9a1a0 100644
--- a/vlf-base.el
+++ b/vlf-base.el
@@ -125,11 +125,17 @@ bytes added to the end."
   (let* ((modified (buffer-modified-p))
          (start (max 0 start))
          (end (min end vlf-file-size))
+         (hexl (derived-mode-p 'hexl-mode))
+         (restore-hexl nil)
          (edit-end (if modified
-                       (+ vlf-start-pos
-                          (length (encode-coding-region
-                                   (point-min) (point-max)
-                                   buffer-file-coding-system t)))
+                       (progn
+                         (when hexl
+                           (hexl-mode-exit)
+                           (setq restore-hexl t))
+                         (+ vlf-start-pos
+                            (length (encode-coding-region
+                                     (point-min) (point-max)
+                                     buffer-file-coding-system t))))
                      vlf-end-pos)))
     (cond
      ((or (< edit-end start) (< end vlf-start-pos)
@@ -137,13 +143,22 @@ bytes added to the end."
       (when (or (not modified)
                 (y-or-n-p "Chunk modified, are you sure? ")) ;full chunk 
renewal
         (set-buffer-modified-p nil)
-        (vlf-move-to-chunk-2 start end)))
+        (let ((shifts (vlf-move-to-chunk-2 start end)))
+          (if restore-hexl (hexl-mode))
+          shifts)))
      ((and (= start vlf-start-pos) (= end edit-end))
-      (or modified (vlf-move-to-chunk-2 start end)))
+      (unless modified
+        (let ((shifts (vlf-move-to-chunk-2 start end)))
+          (if restore-hexl (hexl-mode))
+          shifts)))
      ((or (and (<= start vlf-start-pos) (<= edit-end end))
           (not modified)
           (y-or-n-p "Chunk modified, are you sure? "))
       (run-hooks 'vlf-before-chunk-update)
+      (when (and hexl (not restore-hexl))
+        (if (consp buffer-undo-list)
+            (setq buffer-undo-list nil))
+        (hexl-mode-exit))
       (let ((shift-start 0)
             (shift-end 0))
         (let ((pos (+ (position-bytes (point)) vlf-start-pos))
@@ -202,8 +217,11 @@ bytes added to the end."
           (setq vlf-start-pos start))
         (set-buffer-modified-p modified)
         (set-visited-file-modtime)
+        (if hexl (hexl-mode))
         (run-hooks 'vlf-after-chunk-update)
-        (cons shift-start shift-end))))))
+        (cons shift-start shift-end)))
+     (restore-hexl (hexl-mode)
+                   nil))))
 
 (defun vlf-move-to-chunk-2 (start end)
   "Unconditionally move to chunk enclosed by START END bytes.
@@ -217,11 +235,14 @@ bytes added to the end."
     (let ((inhibit-read-only t)
           (pos (position-bytes (point))))
       (vlf-with-undo-disabled
-       (erase-buffer)
-       (setq shifts (vlf-insert-file-contents vlf-start-pos
-                                              vlf-end-pos t t)
-             vlf-start-pos (- vlf-start-pos (car shifts))
-             vlf-end-pos (+ vlf-end-pos (cdr shifts)))
+       (let ((hexl (derived-mode-p 'hexl-mode)))
+         (if hexl (hexl-mode-exit t))
+         (erase-buffer)
+         (setq shifts (vlf-insert-file-contents vlf-start-pos
+                                                vlf-end-pos t t)
+               vlf-start-pos (- vlf-start-pos (car shifts))
+               vlf-end-pos (+ vlf-end-pos (cdr shifts)))
+         (if hexl (hexl-mode)))
        (goto-char (or (byte-to-position (+ pos (car shifts)))
                       (point-max)))))
     (set-buffer-modified-p nil)
diff --git a/vlf-occur.el b/vlf-occur.el
index 977267a..6adc7d0 100644
--- a/vlf-occur.el
+++ b/vlf-occur.el
@@ -124,14 +124,19 @@ Prematurely ending indexing will still show what's found 
so far."
   (if (buffer-modified-p) ;use temporary buffer not to interfere with 
modifications
       (let ((vlf-buffer (current-buffer))
             (file buffer-file-name)
-            (batch-size vlf-batch-size))
+            (batch-size vlf-batch-size)
+            (is-hexl (derived-mode-p 'hexl-mode)))
         (with-temp-buffer
-          (setq buffer-file-name file)
+          (setq buffer-file-name file
+                buffer-file-truename file
+                buffer-undo-list t)
           (set-buffer-modified-p nil)
           (set (make-local-variable 'vlf-batch-size) batch-size)
           (vlf-mode 1)
-          (goto-char (point-min))
+          (if is-hexl
+              (hexl-mode))
           (run-hook-with-args 'vlf-before-batch-functions 'occur)
+          (goto-char (point-min))
           (vlf-with-undo-disabled
            (vlf-build-occur regexp vlf-buffer))
           (run-hook-with-args 'vlf-after-batch-functions 'occur)))
@@ -170,6 +175,8 @@ Prematurely ending indexing will still show what's found so 
far."
         (reporter (make-progress-reporter
                    (concat "Building index for " regexp "...")
                    vlf-start-pos vlf-file-size)))
+    (with-current-buffer occur-buffer
+      (setq buffer-undo-list t))
     (unwind-protect
         (progn
           (while (not end-of-file)
diff --git a/vlf-write.el b/vlf-write.el
index 1c5db49..5c94113 100644
--- a/vlf-write.el
+++ b/vlf-write.el
@@ -37,37 +37,43 @@ If changing size of chunk, shift remaining file content."
              (or (verify-visited-file-modtime (current-buffer))
                  (y-or-n-p "File has changed since visited or saved.\
   Save anyway? ")))
+    (widen)
     (run-hook-with-args 'vlf-before-batch-functions 'write)
-    (if (zerop vlf-file-size)           ;new file
-        (progn (write-region nil nil buffer-file-name vlf-start-pos t)
-               (setq vlf-file-size (vlf-get-file-size
-                                    buffer-file-truename)
-                     vlf-end-pos vlf-file-size)
-               (vlf-update-buffer-name))
-      (widen)
-      (let* ((region-length (length (encode-coding-region
-                                     (point-min) (point-max)
-                                     buffer-file-coding-system t)))
-             (size-change (- vlf-end-pos vlf-start-pos
-                             region-length)))
-        (if (zerop size-change)
-            (write-region nil nil buffer-file-name vlf-start-pos t)
-          (let ((tramp-verbose (if (boundp 'tramp-verbose)
-                                   (min tramp-verbose 2)))
-                (pos (point))
-                (font-lock font-lock-mode))
-            (font-lock-mode 0)
-            (if (< 0 size-change)
-                (vlf-file-shift-back size-change)
-              (vlf-file-shift-forward (- size-change)))
-            (if font-lock (font-lock-mode 1))
-            (vlf-move-to-chunk-2 vlf-start-pos
-                                 (if (< (- vlf-end-pos vlf-start-pos)
-                                        vlf-batch-size)
-                                     (+ vlf-start-pos vlf-batch-size)
-                                   vlf-end-pos))
-            (vlf-update-buffer-name)
-            (goto-char pos)))))
+    (let ((hexl (derived-mode-p 'hexl-mode)))
+      (when hexl
+        (if (consp buffer-undo-list)
+            (setq buffer-undo-list nil))
+        (hexl-mode-exit))
+      (if (zerop vlf-file-size)           ;new file
+          (progn (write-region nil nil buffer-file-name vlf-start-pos t)
+                 (setq vlf-file-size (vlf-get-file-size
+                                      buffer-file-truename)
+                       vlf-end-pos vlf-file-size)
+                 (vlf-update-buffer-name))
+        (let* ((region-length (length (encode-coding-region
+                                       (point-min) (point-max)
+                                       buffer-file-coding-system t)))
+               (size-change (- vlf-end-pos vlf-start-pos
+                               region-length)))
+          (if (zerop size-change)
+              (write-region nil nil buffer-file-name vlf-start-pos t)
+            (let ((tramp-verbose (if (boundp 'tramp-verbose)
+                                     (min tramp-verbose 2)))
+                  (pos (point))
+                  (font-lock font-lock-mode))
+              (font-lock-mode 0)
+              (if (< 0 size-change)
+                  (vlf-file-shift-back size-change)
+                (vlf-file-shift-forward (- size-change)))
+              (if font-lock (font-lock-mode 1))
+              (vlf-move-to-chunk-2 vlf-start-pos
+                                   (if (< (- vlf-end-pos vlf-start-pos)
+                                          vlf-batch-size)
+                                       (+ vlf-start-pos vlf-batch-size)
+                                     vlf-end-pos))
+              (vlf-update-buffer-name)
+              (goto-char pos)))))
+      (if hexl (hexl-mode)))
     (run-hook-with-args 'vlf-after-batch-functions 'write))
   t)
 
diff --git a/vlf.el b/vlf.el
index da837a5..8a9fde3 100644
--- a/vlf.el
+++ b/vlf.el
@@ -206,27 +206,8 @@ When prefix argument is negative
              (goto-char (point-max)))
     ad-do-it))
 
-;; hexl mode integration
-(defun vlf-hexl-disable (&optional operation)
-  "Temporarily disable `hexl-mode' for OPERATION."
-  (when (and (derived-mode-p 'hexl-mode)
-             (or (not operation)
-                 (eq operation 'write)))
-    (if (consp buffer-undo-list)
-        (setq buffer-undo-list nil))
-    (hexl-mode-exit)
-    (set (make-local-variable 'vlf-restore-hexl-mode) operation)))
-
-(defun vlf-hexl-enable (&optional _operation)
-  "Re-enable `hexl-mode' if active before _OPERATION."
-  (when (boundp 'vlf-restore-hexl-mode)
-    (hexl-mode)
-    (kill-local-variable 'vlf-restore-hexl-mode)))
-
-(add-hook 'vlf-before-batch-functions 'vlf-hexl-disable)
-(add-hook 'vlf-after-batch-functions 'vlf-hexl-enable)
-(add-hook 'vlf-before-chunk-update 'vlf-hexl-disable)
-(add-hook 'vlf-after-chunk-update 'vlf-hexl-enable)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; hexl mode integration
 
 (eval-after-load "hexl"
   '(progn



reply via email to

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