mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 20:10:47 +00:00
Fixes to hexl-mode integration.
This commit is contained in:
parent
274c5ab903
commit
86223ed46c
29
vlf-base.el
29
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
|
||||
(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)))
|
||||
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
|
||||
(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)
|
||||
|
13
vlf-occur.el
13
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)
|
||||
|
@ -37,14 +37,19 @@ 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)
|
||||
(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))
|
||||
(widen)
|
||||
(let* ((region-length (length (encode-coding-region
|
||||
(point-min) (point-max)
|
||||
buffer-file-coding-system t)))
|
||||
@ -68,6 +73,7 @@ If changing size of chunk, shift remaining file content."
|
||||
vlf-end-pos))
|
||||
(vlf-update-buffer-name)
|
||||
(goto-char pos)))))
|
||||
(if hexl (hexl-mode)))
|
||||
(run-hook-with-args 'vlf-after-batch-functions 'write))
|
||||
t)
|
||||
|
||||
|
23
vlf.el
23
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user