[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
- [elpa] externals/vlf f3212ec 251/310: Fix measure approximation and allow tuning to just over half file, (continued)
- [elpa] externals/vlf f3212ec 251/310: Fix measure approximation and allow tuning to just over half file, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 11c7af4 253/310: Change handling of measurement values to support approximations., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 35ede94 255/310: Restore batch size after save with adjustment., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ff06509 261/310: Document tune functionality., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 1c961f4 285/310: Fix whole file reload in read-only buffer on vlf-mode exit., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f4526a1 287/310: Forbid short-cutting in line search., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fd90b3a 295/310: Use xdigit regex class in vlf-hexl-adjust-addresses., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf df677c1 302/310: Issue 35: make mode-line batch indicators more accurate, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a568d2d 307/310: packages/vlf: Update copyright dates and bump version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0ecb40a 124/310: Keep as much editing as possible when moving to intersecting chunk., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 86223ed 234/310: Fixes to hexl-mode integration.,
Stefan Monnier <=
- [elpa] externals/vlf 9271f68 256/310: Add function to linearly search best batch size according to existing, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0d2c096 258/310: Restore batch size and hexl mode in case of failed search or occur., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b918791 265/310: Improve vlf performance with hexl-mode. Align batches to hexl-bits, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2e9ff70 238/310: Enlarge default batch size but keep is small on initial load of remote, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d85f3d4 246/310: Fix access to uninitialized measurements when tuning., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ca56498 259/310: Change vlf-tune-get-optimal to optimize on total time of primitive, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 51d95ec 152/310: Add command to display batch starting from point., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 46e39a0 153/310: Version 1.0., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d1af56d 167/310: Fix opening of files for GNU Emacs 23., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 8ab1c6a 136/310: Disable undo and mark buffer as not modified when invoking search or, Stefan Monnier, 2020/11/28