[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf b05255b 220/310: Add hooks to run around chunk move
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf b05255b 220/310: Add hooks to run around chunk moves and batch operations. Don't err |
Date: |
Sat, 28 Nov 2020 00:33:19 -0500 (EST) |
branch: externals/vlf
commit b05255b225dd5779f358528ba9690f15660e94a0
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Add hooks to run around chunk moves and batch operations. Don't err
when tramp hasn't been loaded yet.
---
vlf-base.el | 12 ++++++++++++
vlf-ediff.el | 21 ++++++++++++---------
vlf-integrate.el | 18 +++++++-----------
vlf-occur.el | 11 ++++++++---
vlf-search.el | 14 ++++++++++----
vlf-write.el | 7 +++++--
vlf.el | 12 ++++++++++++
7 files changed, 66 insertions(+), 29 deletions(-)
diff --git a/vlf-base.el b/vlf-base.el
index d8f60a1..21dfbac 100644
--- a/vlf-base.el
+++ b/vlf-base.el
@@ -35,6 +35,14 @@
:group 'vlf :type 'integer)
(put 'vlf-batch-size 'permanent-local t)
+(defcustom vlf-before-chunk-update nil
+ "Hook that runs before chunk update."
+ :group 'vlf :type 'hook)
+
+(defcustom vlf-after-chunk-update nil
+ "Hook that runs after chunk update."
+ :group 'vlf :type 'hook)
+
;;; Keep track of file position.
(defvar vlf-start-pos 0
"Absolute position of the visible chunk start.")
@@ -139,6 +147,7 @@ bytes added to the end."
((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)
(let ((shift-start 0)
(shift-end 0))
(let ((pos (+ (position-bytes (point)) vlf-start-pos))
@@ -197,12 +206,14 @@ bytes added to the end."
(setq vlf-start-pos start))
(set-buffer-modified-p modified)
(set-visited-file-modtime)
+ (run-hooks 'vlf-after-chunk-update)
(cons shift-start shift-end))))))
(defun vlf-move-to-chunk-2 (start end)
"Unconditionally move to chunk enclosed by START END bytes.
Return number of bytes moved back for proper decoding and number of
bytes added to the end."
+ (run-hooks 'vlf-before-chunk-update)
(vlf-verify-size t)
(setq vlf-start-pos (max 0 start)
vlf-end-pos (min end vlf-file-size))
@@ -220,6 +231,7 @@ bytes added to the end."
(set-buffer-modified-p nil)
(or (eq buffer-undo-list t)
(setq buffer-undo-list nil))
+ (run-hooks 'vlf-after-chunk-update)
shifts))
(defun vlf-insert-file-contents (start end adjust-start adjust-end
diff --git a/vlf-ediff.el b/vlf-ediff.el
index 51c8aec..2b7c63f 100644
--- a/vlf-ediff.el
+++ b/vlf-ediff.el
@@ -1,4 +1,4 @@
-;;; vlf-ediff.el --- VLF ediff functionality
+;;; vlf-ediff.el --- VLF ediff functionality -*- lexical-binding: t -*-
;; Copyright (C) 2014 Free Software Foundation, Inc.
@@ -154,6 +154,7 @@ beginning of difference list."
governed by EDIFF-BUFFER. NEXT-FUNC is used to jump to the next
logical chunks in case there is no difference at the current ones."
(set-buffer buffer-A)
+ (run-hook-with-args 'vlf-before-batch-functions 'ediff)
(setq buffer-A (current-buffer)) ;names change, so reference by buffer object
(let ((end-A (= vlf-start-pos vlf-end-pos))
(chunk-A (cons vlf-start-pos vlf-end-pos))
@@ -163,9 +164,11 @@ logical chunks in case there is no difference at the
current ones."
(forward-p (eq next-func 'vlf-next-chunk)))
(font-lock-mode 0)
(set-buffer buffer-B)
+ (run-hook-with-args 'vlf-before-batch-functions 'ediff)
(setq buffer-B (current-buffer)
min-file-size (min min-file-size vlf-file-size))
- (let ((tramp-verbose (min 2 tramp-verbose))
+ (let ((tramp-verbose (if (boundp 'tramp-verbose)
+ (min tramp-verbose 2)))
(end-B (= vlf-start-pos vlf-end-pos))
(chunk-B (cons vlf-start-pos vlf-end-pos))
(font-lock-B font-lock-mode)
@@ -222,12 +225,6 @@ logical chunks in case there is no difference at the
current ones."
(and (not end-A) (not end-B)))
(vlf-ediff-refine buffer-A buffer-B)))
(setq done t))
- (when font-lock-A
- (set-buffer buffer-A)
- (font-lock-mode 1))
- (when font-lock-B
- (set-buffer buffer-B)
- (font-lock-mode 1))
(unless done
(set-buffer buffer-A)
(set-buffer-modified-p nil)
@@ -237,7 +234,13 @@ logical chunks in case there is no difference at the
current ones."
(vlf-move-to-chunk (car chunk-B) (cdr chunk-B))
(set-buffer ediff-buffer)
(ediff-update-diffs)
- (vlf-ediff-refine buffer-A buffer-B))))))
+ (vlf-ediff-refine buffer-A buffer-B))
+ (set-buffer buffer-A)
+ (if font-lock-A (font-lock-mode 1))
+ (run-hook-with-args 'vlf-after-batch-functions 'ediff)
+ (set-buffer buffer-B)
+ (if font-lock-B (font-lock-mode 1))
+ (run-hook-with-args 'vlf-after-batch-functions 'ediff)))))
(defun vlf-ediff-refine (buffer-A buffer-B)
"Try to minimize differences between BUFFER-A and BUFFER-B.
diff --git a/vlf-integrate.el b/vlf-integrate.el
index c072398..435ac45 100644
--- a/vlf-integrate.el
+++ b/vlf-integrate.el
@@ -26,10 +26,8 @@
;;; Code:
-(defgroup vlf nil
- "View Large Files in Emacs."
- :prefix "vlf-"
- :group 'files)
+(defgroup vlf nil "View Large Files in Emacs."
+ :prefix "vlf-" :group 'files)
(defcustom vlf-application 'ask
"Determines when `vlf' will be offered on opening files.
@@ -37,18 +35,16 @@ Possible values are: nil to never use it;
`ask' offer `vlf' when file size is beyond `large-file-warning-threshold';
`dont-ask' automatically use `vlf' for large files;
`always' use `vlf' for all files."
- :group 'vlf
- :type '(radio (const :format "%v " nil)
- (const :format "%v " ask)
- (const :format "%v " dont-ask)
- (const :format "%v" always)))
+ :group 'vlf :type '(radio (const :format "%v " nil)
+ (const :format "%v " ask)
+ (const :format "%v " dont-ask)
+ (const :format "%v" always)))
(defcustom vlf-forbidden-modes-list
'(archive-mode tar-mode jka-compr git-commit-mode image-mode
doc-view-mode doc-view-mode-maybe ebrowse-tree-mode)
"Major modes which VLF will not be automatically applied to."
- :group 'vlf
- :type '(list symbol))
+ :group 'vlf :type '(list symbol))
(unless (fboundp 'file-size-human-readable)
(defun file-size-human-readable (file-size)
diff --git a/vlf-occur.el b/vlf-occur.el
index 3b7be85..5ecd07b 100644
--- a/vlf-occur.el
+++ b/vlf-occur.el
@@ -131,8 +131,10 @@ Prematurely ending indexing will still show what's found
so far."
(set (make-local-variable 'vlf-batch-size) batch-size)
(vlf-mode 1)
(goto-char (point-min))
+ (run-hook-with-args 'vlf-before-batch-functions 'occur)
(vlf-with-undo-disabled
(vlf-build-occur regexp vlf-buffer))))
+ (run-hook-with-args 'vlf-before-batch-functions 'occur)
(let ((start-pos vlf-start-pos)
(end-pos vlf-end-pos)
(pos (point)))
@@ -141,11 +143,13 @@ Prematurely ending indexing will still show what's found
so far."
(goto-char (point-min))
(unwind-protect (vlf-build-occur regexp (current-buffer))
(vlf-move-to-chunk start-pos end-pos)
- (goto-char pos))))))
+ (goto-char pos)))))
+ (run-hook-with-args 'vlf-before-after-functions 'occur))
(defun vlf-build-occur (regexp vlf-buffer)
"Build occur style index for REGEXP over VLF-BUFFER."
- (let ((tramp-verbose (min 2 tramp-verbose))
+ (let ((tramp-verbose (if (boundp 'tramp-verbose)
+ (min tramp-verbose 2)))
(case-fold-search t)
(line 1)
(last-match-line 0)
@@ -244,7 +248,8 @@ in file: %s" total-matches line regexp file)
(set-buffer-modified-p nil)
(forward-char 2)
(vlf-occur-mode))
- (display-buffer occur-buffer)))))
+ (display-buffer occur-buffer))
+ (run-hook-with-args 'vlf-after-batch-functions 'occur))))
(provide 'vlf-occur)
diff --git a/vlf-search.el b/vlf-search.el
index 8fa2ce4..9eb2485 100644
--- a/vlf-search.el
+++ b/vlf-search.el
@@ -34,7 +34,9 @@
BATCH-STEP is amount of overlap between successive chunks."
(if (<= count 0)
(error "Count must be positive"))
- (let* ((tramp-verbose (min 2 tramp-verbose))
+ (run-hook-with-args 'vlf-before-batch-functions 'search)
+ (let* ((tramp-verbose (if (boundp 'tramp-verbose)
+ (min tramp-verbose 2)))
(case-fold-search t)
(match-chunk-start vlf-start-pos)
(match-chunk-end vlf-end-pos)
@@ -118,7 +120,8 @@ BATCH-STEP is amount of overlap between successive chunks."
count to-find)
(vlf-goto-match match-chunk-start match-chunk-end
match-start-pos match-end-pos
- count to-find))))))
+ count to-find)))))
+ (run-hook-with-args 'vlf-after-batch-functions 'search))
(defun vlf-goto-match (match-chunk-start match-chunk-end
match-pos-start
@@ -179,8 +182,10 @@ Search is performed chunk by chunk in `vlf-batch-size'
memory."
"Go to line N. If N is negative, count from the end of file."
(interactive (if (vlf-no-modifications)
(list (read-number "Go to line: "))))
+ (run-hook-with-args 'vlf-before-batch-functions 'goto-line)
(vlf-verify-size)
- (let ((tramp-verbose (min 2 tramp-verbose))
+ (let ((tramp-verbose (if (boundp 'tramp-verbose)
+ (min tramp-verbose 2)))
(start-pos vlf-start-pos)
(end-pos vlf-end-pos)
(pos (point))
@@ -244,7 +249,8 @@ Search is performed chunk by chunk in `vlf-batch-size'
memory."
(vlf-with-undo-disabled
(vlf-move-to-chunk-2 start-pos end-pos))
(goto-char pos)
- (message "Unable to find line")))))
+ (message "Unable to find line"))
+ (run-hook-with-args 'vlf-after-batch-functions 'goto-line))))
(provide 'vlf-search)
diff --git a/vlf-write.el b/vlf-write.el
index e8549a7..b974f94 100644
--- a/vlf-write.el
+++ b/vlf-write.el
@@ -52,7 +52,9 @@ Save anyway? "))
region-length)))
(if (zerop size-change)
(write-region nil nil buffer-file-name vlf-start-pos t)
- (let ((tramp-verbose (min 2 tramp-verbose))
+ (run-hook-with-args 'vlf-before-batch-functions 'write)
+ (let ((tramp-verbose (if (boundp 'tramp-verbose)
+ (min tramp-verbose 2)))
(pos (point))
(font-lock font-lock-mode))
(font-lock-mode 0)
@@ -66,7 +68,8 @@ Save anyway? "))
(+ vlf-start-pos vlf-batch-size)
vlf-end-pos))
(vlf-update-buffer-name)
- (goto-char pos))))))
+ (goto-char pos))
+ (run-hook-with-args 'vlf-after-batch-functions 'write)))))
t)
(defun vlf-file-shift-back (size-change)
diff --git a/vlf.el b/vlf.el
index 18f274b..2469011 100644
--- a/vlf.el
+++ b/vlf.el
@@ -39,6 +39,18 @@
;;; Code:
+(defcustom vlf-before-batch-functions nil
+ "Hook that runs before multiple batch operations.
+One argument is supplied that specifies current action. Possible
+values are: `write', `ediff', `occur', `search', `goto-line'."
+ :group 'vlf :type 'hook)
+
+(defcustom vlf-after-batch-functions nil
+ "Hook that runs after multiple batch operations.
+One argument is supplied that specifies current action. Possible
+values are: `write', `ediff', `occur', `search', `goto-line'."
+ :group 'vlf :type 'hook)
+
(require 'vlf-base)
(autoload 'vlf-write "vlf-write" "Write current chunk to file." t)
- [elpa] externals/vlf 28646fb 148/310: Reduce scope of vlf-with-undo-disabled usages., (continued)
- [elpa] externals/vlf 28646fb 148/310: Reduce scope of vlf-with-undo-disabled usages., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 72fec35 162/310: Update README and bump version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 65b4d74 170/310: Refactor vlf-write., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 099adab 171/310: Fix abort-if-file-too-large advice not to activate VLF in case of empty, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c58d0d8 180/310: Shift buffer-undo-list elements when chunk beginning moves., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4f99eaa 183/310: Fixes to tiny chunk moves., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 7794b2c 185/310: Merge branch 'shift-undo' into chunk-move, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d7766f2 209/310: Update documentation and mark autoloaded functions as interactive., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5d30eb4 206/310: Use single ediff pass to adjust borders. Protect against user, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ffac697 217/310: Keep undo list after occur or unsuccessful line search., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b05255b 220/310: Add hooks to run around chunk moves and batch operations. Don't err,
Stefan Monnier <=
- [elpa] externals/vlf 557d751 236/310: Be more precise on restoring hexl-mode after chunk update has been, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ece554a 231/310: Wording., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 069b2f5 240/310: Replace operations with respective vlf-tune wrappers., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fb05030 241/310: Add basic tune strategies., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e18a05b 247/310: Add linear search for tuning and prefer smaller batches., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 48a014f 250/310: Fix write measuring and endless loop in nearby approximation., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ee7409b 254/310: Tune batch size in more cases., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5651ee3 252/310: Rename vlf-tune-optimal to vlf-tune-batch., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 06b4f85 262/310: Respect disabled tune settings and move custom options., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 199209f 263/310: Fix vlf-tune-optimal-load with no optional arguments supplied., Stefan Monnier, 2020/11/28