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))
|
(let* ((modified (buffer-modified-p))
|
||||||
(start (max 0 start))
|
(start (max 0 start))
|
||||||
(end (min end vlf-file-size))
|
(end (min end vlf-file-size))
|
||||||
|
(hexl (derived-mode-p 'hexl-mode))
|
||||||
|
(restore-hexl nil)
|
||||||
(edit-end (if modified
|
(edit-end (if modified
|
||||||
|
(progn
|
||||||
|
(when hexl
|
||||||
|
(hexl-mode-exit)
|
||||||
|
(setq restore-hexl t))
|
||||||
(+ vlf-start-pos
|
(+ vlf-start-pos
|
||||||
(length (encode-coding-region
|
(length (encode-coding-region
|
||||||
(point-min) (point-max)
|
(point-min) (point-max)
|
||||||
buffer-file-coding-system t)))
|
buffer-file-coding-system t))))
|
||||||
vlf-end-pos)))
|
vlf-end-pos)))
|
||||||
(cond
|
(cond
|
||||||
((or (< edit-end start) (< end vlf-start-pos)
|
((or (< edit-end start) (< end vlf-start-pos)
|
||||||
@ -137,13 +143,22 @@ bytes added to the end."
|
|||||||
(when (or (not modified)
|
(when (or (not modified)
|
||||||
(y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal
|
(y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal
|
||||||
(set-buffer-modified-p nil)
|
(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))
|
((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))
|
((or (and (<= start vlf-start-pos) (<= edit-end end))
|
||||||
(not modified)
|
(not modified)
|
||||||
(y-or-n-p "Chunk modified, are you sure? "))
|
(y-or-n-p "Chunk modified, are you sure? "))
|
||||||
(run-hooks 'vlf-before-chunk-update)
|
(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)
|
(let ((shift-start 0)
|
||||||
(shift-end 0))
|
(shift-end 0))
|
||||||
(let ((pos (+ (position-bytes (point)) vlf-start-pos))
|
(let ((pos (+ (position-bytes (point)) vlf-start-pos))
|
||||||
@ -202,8 +217,11 @@ bytes added to the end."
|
|||||||
(setq vlf-start-pos start))
|
(setq vlf-start-pos start))
|
||||||
(set-buffer-modified-p modified)
|
(set-buffer-modified-p modified)
|
||||||
(set-visited-file-modtime)
|
(set-visited-file-modtime)
|
||||||
|
(if hexl (hexl-mode))
|
||||||
(run-hooks 'vlf-after-chunk-update)
|
(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)
|
(defun vlf-move-to-chunk-2 (start end)
|
||||||
"Unconditionally move to chunk enclosed by START END bytes.
|
"Unconditionally move to chunk enclosed by START END bytes.
|
||||||
@ -217,11 +235,14 @@ bytes added to the end."
|
|||||||
(let ((inhibit-read-only t)
|
(let ((inhibit-read-only t)
|
||||||
(pos (position-bytes (point))))
|
(pos (position-bytes (point))))
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
|
(let ((hexl (derived-mode-p 'hexl-mode)))
|
||||||
|
(if hexl (hexl-mode-exit t))
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(setq shifts (vlf-insert-file-contents vlf-start-pos
|
(setq shifts (vlf-insert-file-contents vlf-start-pos
|
||||||
vlf-end-pos t t)
|
vlf-end-pos t t)
|
||||||
vlf-start-pos (- vlf-start-pos (car shifts))
|
vlf-start-pos (- vlf-start-pos (car shifts))
|
||||||
vlf-end-pos (+ vlf-end-pos (cdr shifts)))
|
vlf-end-pos (+ vlf-end-pos (cdr shifts)))
|
||||||
|
(if hexl (hexl-mode)))
|
||||||
(goto-char (or (byte-to-position (+ pos (car shifts)))
|
(goto-char (or (byte-to-position (+ pos (car shifts)))
|
||||||
(point-max)))))
|
(point-max)))))
|
||||||
(set-buffer-modified-p nil)
|
(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
|
(if (buffer-modified-p) ;use temporary buffer not to interfere with modifications
|
||||||
(let ((vlf-buffer (current-buffer))
|
(let ((vlf-buffer (current-buffer))
|
||||||
(file buffer-file-name)
|
(file buffer-file-name)
|
||||||
(batch-size vlf-batch-size))
|
(batch-size vlf-batch-size)
|
||||||
|
(is-hexl (derived-mode-p 'hexl-mode)))
|
||||||
(with-temp-buffer
|
(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-buffer-modified-p nil)
|
||||||
(set (make-local-variable 'vlf-batch-size) batch-size)
|
(set (make-local-variable 'vlf-batch-size) batch-size)
|
||||||
(vlf-mode 1)
|
(vlf-mode 1)
|
||||||
(goto-char (point-min))
|
(if is-hexl
|
||||||
|
(hexl-mode))
|
||||||
(run-hook-with-args 'vlf-before-batch-functions 'occur)
|
(run-hook-with-args 'vlf-before-batch-functions 'occur)
|
||||||
|
(goto-char (point-min))
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
(vlf-build-occur regexp vlf-buffer))
|
(vlf-build-occur regexp vlf-buffer))
|
||||||
(run-hook-with-args 'vlf-after-batch-functions 'occur)))
|
(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
|
(reporter (make-progress-reporter
|
||||||
(concat "Building index for " regexp "...")
|
(concat "Building index for " regexp "...")
|
||||||
vlf-start-pos vlf-file-size)))
|
vlf-start-pos vlf-file-size)))
|
||||||
|
(with-current-buffer occur-buffer
|
||||||
|
(setq buffer-undo-list t))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(progn
|
(progn
|
||||||
(while (not end-of-file)
|
(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))
|
(or (verify-visited-file-modtime (current-buffer))
|
||||||
(y-or-n-p "File has changed since visited or saved.\
|
(y-or-n-p "File has changed since visited or saved.\
|
||||||
Save anyway? ")))
|
Save anyway? ")))
|
||||||
|
(widen)
|
||||||
(run-hook-with-args 'vlf-before-batch-functions 'write)
|
(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
|
(if (zerop vlf-file-size) ;new file
|
||||||
(progn (write-region nil nil buffer-file-name vlf-start-pos t)
|
(progn (write-region nil nil buffer-file-name vlf-start-pos t)
|
||||||
(setq vlf-file-size (vlf-get-file-size
|
(setq vlf-file-size (vlf-get-file-size
|
||||||
buffer-file-truename)
|
buffer-file-truename)
|
||||||
vlf-end-pos vlf-file-size)
|
vlf-end-pos vlf-file-size)
|
||||||
(vlf-update-buffer-name))
|
(vlf-update-buffer-name))
|
||||||
(widen)
|
|
||||||
(let* ((region-length (length (encode-coding-region
|
(let* ((region-length (length (encode-coding-region
|
||||||
(point-min) (point-max)
|
(point-min) (point-max)
|
||||||
buffer-file-coding-system t)))
|
buffer-file-coding-system t)))
|
||||||
@ -68,6 +73,7 @@ If changing size of chunk, shift remaining file content."
|
|||||||
vlf-end-pos))
|
vlf-end-pos))
|
||||||
(vlf-update-buffer-name)
|
(vlf-update-buffer-name)
|
||||||
(goto-char pos)))))
|
(goto-char pos)))))
|
||||||
|
(if hexl (hexl-mode)))
|
||||||
(run-hook-with-args 'vlf-after-batch-functions 'write))
|
(run-hook-with-args 'vlf-after-batch-functions 'write))
|
||||||
t)
|
t)
|
||||||
|
|
||||||
|
23
vlf.el
23
vlf.el
@ -206,27 +206,8 @@ When prefix argument is negative
|
|||||||
(goto-char (point-max)))
|
(goto-char (point-max)))
|
||||||
ad-do-it))
|
ad-do-it))
|
||||||
|
|
||||||
;; hexl mode integration
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(defun vlf-hexl-disable (&optional operation)
|
;;; hexl mode integration
|
||||||
"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)
|
|
||||||
|
|
||||||
(eval-after-load "hexl"
|
(eval-after-load "hexl"
|
||||||
'(progn
|
'(progn
|
||||||
|
Loading…
x
Reference in New Issue
Block a user