[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 074f9e9 221/310: Play nicely with hexl-mode.
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 074f9e9 221/310: Play nicely with hexl-mode. |
Date: |
Sat, 28 Nov 2020 00:33:19 -0500 (EST) |
branch: externals/vlf
commit 074f9e960dcf72f56b2ab6f9ab689f1f66e89f83
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Play nicely with hexl-mode.
---
vlf.el | 110 ++++++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 78 insertions(+), 32 deletions(-)
diff --git a/vlf.el b/vlf.el
index 2469011..79b88e4 100644
--- a/vlf.el
+++ b/vlf.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2006, 2012-2014 Free Software Foundation, Inc.
-;; Version: 1.4
+;; Version: 1.5
;; Keywords: large files, utilities
;; Maintainer: Andrey Kotlarski <m00naticus@gmail.com>
;; Authors: 2006 Mathias Dahl <mathias.dahl@gmail.com>
@@ -98,37 +98,48 @@ values are: `write', `ediff', `occur', `search',
`goto-line'."
(define-minor-mode vlf-mode
"Mode to browse large files in."
- :lighter " VLF"
- :group 'vlf
- :keymap vlf-prefix-map
- (if vlf-mode
- (progn
- (set (make-local-variable 'require-final-newline) nil)
- (add-hook 'write-file-functions 'vlf-write nil t)
- (set (make-local-variable 'revert-buffer-function)
- 'vlf-revert)
- (make-local-variable 'vlf-batch-size)
- (setq vlf-file-size (vlf-get-file-size buffer-file-truename)
- vlf-start-pos 0
- vlf-end-pos 0)
- (let* ((pos (position-bytes (point)))
- (start (* (/ pos vlf-batch-size) vlf-batch-size)))
- (goto-char (byte-to-position (- pos start)))
- (vlf-move-to-batch start)))
- (kill-local-variable 'revert-buffer-function)
- (vlf-stop-follow)
- (when (or (not large-file-warning-threshold)
- (< vlf-file-size large-file-warning-threshold)
- (y-or-n-p (format "Load whole file (%s)? "
- (file-size-human-readable
- vlf-file-size))))
- (kill-local-variable 'require-final-newline)
- (remove-hook 'write-file-functions 'vlf-write t)
- (let ((pos (+ vlf-start-pos (position-bytes (point)))))
- (vlf-with-undo-disabled
- (insert-file-contents buffer-file-name t nil nil t))
- (goto-char (byte-to-position pos)))
- (rename-buffer (file-name-nondirectory buffer-file-name) t))))
+ :lighter " VLF" :group 'vlf :keymap vlf-prefix-map
+ (cond (vlf-mode
+ (set (make-local-variable 'require-final-newline) nil)
+ (add-hook 'write-file-functions 'vlf-write nil t)
+ (set (make-local-variable 'revert-buffer-function)
+ 'vlf-revert)
+ (make-local-variable 'vlf-batch-size)
+ (setq vlf-file-size (vlf-get-file-size buffer-file-truename)
+ vlf-start-pos 0
+ vlf-end-pos 0)
+ (let* ((pos (position-bytes (point)))
+ (start (* (/ pos vlf-batch-size) vlf-batch-size)))
+ (goto-char (byte-to-position (- pos start)))
+ (vlf-move-to-batch start))
+ (add-hook 'after-change-major-mode-hook 'vlf-keep-alive t t)
+ (vlf-keep-alive))
+ ((or (not large-file-warning-threshold)
+ (< vlf-file-size large-file-warning-threshold)
+ (y-or-n-p (format "Load whole file (%s)? "
+ (file-size-human-readable
+ vlf-file-size))))
+ (kill-local-variable 'revert-buffer-function)
+ (vlf-stop-follow)
+ (kill-local-variable 'require-final-newline)
+ (remove-hook 'write-file-functions 'vlf-write t)
+ (remove-hook 'after-change-major-mode-hook
+ 'vlf-keep-alive t)
+ (let ((hexl (eq major-mode 'hexl-mode)))
+ (if hexl (hexl-mode-exit))
+ (let ((pos (+ vlf-start-pos (position-bytes (point)))))
+ (vlf-with-undo-disabled
+ (insert-file-contents buffer-file-name t nil nil t))
+ (goto-char (byte-to-position pos)))
+ (if hexl (hexl-mode)))
+ (rename-buffer (file-name-nondirectory buffer-file-name) t))
+ (t (setq vlf-mode t))))
+
+(defun vlf-keep-alive ()
+ "Keep `vlf-mode' on major mode change."
+ (if (eq major-mode 'hexl-mode)
+ (remove-hook 'write-contents-functions 'hexl-save-buffer t))
+ (setq vlf-mode t))
;;;###autoload
(defun vlf (file)
@@ -192,6 +203,41 @@ When prefix argument is negative
(goto-char (point-max)))
ad-do-it))
+;; hexl mode integration
+(defun vlf-hexl-before (&optional operation)
+ "Temporarily disable `hexl-mode' for OPERATION."
+ (when (eq major-mode 'hexl-mode)
+ (hexl-mode-exit)
+ (set (make-local-variable 'vlf-restore-hexl-mode) operation)))
+
+(defun vlf-hexl-after (&optional operation)
+ "Re-enable `hexl-mode' if active before OPERATION."
+ (when (and (boundp 'vlf-restore-hexl-mode)
+ (eq vlf-restore-hexl-mode operation))
+ (hexl-mode)
+ (kill-local-variable 'vlf-restore-hexl-mode)))
+
+(add-hook 'vlf-before-batch-functions 'vlf-hexl-before)
+(add-hook 'vlf-after-batch-functions 'vlf-hexl-after)
+(add-hook 'vlf-before-chunk-update 'vlf-hexl-before)
+(add-hook 'vlf-after-chunk-update 'vlf-hexl-after)
+
+(defadvice hexl-scroll-up (around vlf-scroll-up
+ activate compile)
+ "Slide to next batch if at end of buffer in `vlf-mode'."
+ (if (and vlf-mode (pos-visible-in-window-p (point-max)))
+ (progn (vlf-next-batch 1)
+ (goto-char (point-min)))
+ ad-do-it))
+
+(defadvice hexl-scroll-down (around vlf-scroll-down
+ activate compile)
+ "Slide to previous batch if at beginning of buffer in `vlf-mode'."
+ (if (and vlf-mode (pos-visible-in-window-p (point-min)))
+ (progn (vlf-prev-batch 1)
+ (goto-char (point-max)))
+ ad-do-it))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; utilities
- [elpa] externals/vlf 27e3bbb 201/310: Reuse initial ediff session for all chunks., (continued)
- [elpa] externals/vlf 27e3bbb 201/310: Reuse initial ediff session for all chunks., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9343095 193/310: Fix installation interfile dependencies and fix setting of local, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 88dba8b 195/310: Remove unnecessary addition to load-path on compile., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf dd43af5 192/310: Manually decode and use several bytes buffer when loading chunk., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 98ddc3a 198/310: Add by batch Ediff functionality., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9646b00 202/310: Adjust chunk borders to minimize shift differences and optimize, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d5d9cd7 205/310: Improve refining of differences and readjustment., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0fa8e8d 210/310: Update buffer name on user interruption during ediff., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 30d2bb0 208/310: VLF buffer ediff now starts from the current chunks., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f83a212 213/310: Temporarily disable font-lock during multiple batch operations., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 074f9e9 221/310: Play nicely with hexl-mode.,
Stefan Monnier <=
- [elpa] externals/vlf 8c61b77 222/310: Fix when batch hooks are run for occur and save., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 6476c1b 227/310: Update README, wording, add links and information on hooks., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 8ba5bea 229/310: Don't run vlf-after-batch-functions hook in vlf-build-occur., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 569e4b2 237/310: Don't ask needles questions on changing helm batch and restore undo, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 1f9ba7c 230/310: Use derived-mode-p., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 32ff2cb 239/310: Add bookkeeping module., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5379943 242/310: Save times instead of speeds, compare on cumulative speed when tuning., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0d9cc8e 245/310: Don't measure encoding of too small region when adjusting chunk start, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e8bb4a9 248/310: Apply batch size tuning on adjacent moves, search, save adjusting and, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d526ea8 257/310: Apply and restore batch size in more cases., Stefan Monnier, 2020/11/28