1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-31 02:00:47 +00:00

Fix when batch hooks are run for occur and save.

This commit is contained in:
Andrey Kotlarski 2014-02-14 12:34:31 +02:00
parent 074f9e960d
commit 8c61b776d6
2 changed files with 40 additions and 40 deletions

View File

@ -133,7 +133,8 @@ Prematurely ending indexing will still show what's found so far."
(goto-char (point-min)) (goto-char (point-min))
(run-hook-with-args 'vlf-before-batch-functions 'occur) (run-hook-with-args 'vlf-before-batch-functions 'occur)
(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-before-after-functions 'occur)))
(run-hook-with-args 'vlf-before-batch-functions 'occur) (run-hook-with-args 'vlf-before-batch-functions 'occur)
(let ((start-pos vlf-start-pos) (let ((start-pos vlf-start-pos)
(end-pos vlf-end-pos) (end-pos vlf-end-pos)
@ -143,8 +144,8 @@ Prematurely ending indexing will still show what's found so far."
(goto-char (point-min)) (goto-char (point-min))
(unwind-protect (vlf-build-occur regexp (current-buffer)) (unwind-protect (vlf-build-occur regexp (current-buffer))
(vlf-move-to-chunk start-pos end-pos) (vlf-move-to-chunk start-pos end-pos)
(goto-char pos))))) (goto-char pos))))
(run-hook-with-args 'vlf-before-after-functions 'occur)) (run-hook-with-args 'vlf-before-after-functions 'occur)))
(defun vlf-build-occur (regexp vlf-buffer) (defun vlf-build-occur (regexp vlf-buffer)
"Build occur style index for REGEXP over VLF-BUFFER." "Build occur style index for REGEXP over VLF-BUFFER."

View File

@ -33,43 +33,42 @@
"Write current chunk to file. Always return true to disable save. "Write current chunk to file. Always return true to disable save.
If changing size of chunk, shift remaining file content." If changing size of chunk, shift remaining file content."
(interactive) (interactive)
(and (buffer-modified-p) (when (and (buffer-modified-p)
(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? ")))
(if (zerop vlf-file-size) ;new file (run-hook-with-args 'vlf-before-batch-functions 'write)
(progn (if (zerop vlf-file-size) ;new file
(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) (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)))
(size-change (- vlf-end-pos vlf-start-pos (size-change (- vlf-end-pos vlf-start-pos
region-length))) region-length)))
(if (zerop size-change) (if (zerop size-change)
(write-region nil nil buffer-file-name vlf-start-pos t) (write-region nil nil buffer-file-name vlf-start-pos t)
(run-hook-with-args 'vlf-before-batch-functions 'write) (let ((tramp-verbose (if (boundp 'tramp-verbose)
(let ((tramp-verbose (if (boundp 'tramp-verbose) (min tramp-verbose 2)))
(min tramp-verbose 2))) (pos (point))
(pos (point)) (font-lock font-lock-mode))
(font-lock font-lock-mode)) (font-lock-mode 0)
(font-lock-mode 0) (if (< 0 size-change)
(if (< 0 size-change) (vlf-file-shift-back size-change)
(vlf-file-shift-back size-change) (vlf-file-shift-forward (- size-change)))
(vlf-file-shift-forward (- size-change))) (if font-lock (font-lock-mode 1))
(if font-lock (font-lock-mode 1)) (vlf-move-to-chunk-2 vlf-start-pos
(vlf-move-to-chunk-2 vlf-start-pos (if (< (- vlf-end-pos vlf-start-pos)
(if (< (- vlf-end-pos vlf-start-pos) vlf-batch-size)
vlf-batch-size) (+ vlf-start-pos vlf-batch-size)
(+ vlf-start-pos vlf-batch-size) vlf-end-pos))
vlf-end-pos)) (vlf-update-buffer-name)
(vlf-update-buffer-name) (goto-char pos)))))
(goto-char pos)) (run-hook-with-args 'vlf-after-batch-functions 'write))
(run-hook-with-args 'vlf-after-batch-functions 'write)))))
t) t)
(defun vlf-file-shift-back (size-change) (defun vlf-file-shift-back (size-change)