From 8c61b776d61540d74b47636be84665a5ab153fa2 Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Fri, 14 Feb 2014 12:34:31 +0200 Subject: [PATCH] Fix when batch hooks are run for occur and save. --- vlf-occur.el | 7 ++--- vlf-write.el | 73 ++++++++++++++++++++++++++-------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/vlf-occur.el b/vlf-occur.el index 5ecd07b..5d6f5d8 100644 --- a/vlf-occur.el +++ b/vlf-occur.el @@ -133,7 +133,8 @@ Prematurely ending indexing will still show what's found so far." (goto-char (point-min)) (run-hook-with-args 'vlf-before-batch-functions 'occur) (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) (let ((start-pos vlf-start-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)) (unwind-protect (vlf-build-occur regexp (current-buffer)) (vlf-move-to-chunk start-pos end-pos) - (goto-char pos))))) - (run-hook-with-args 'vlf-before-after-functions 'occur)) + (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." diff --git a/vlf-write.el b/vlf-write.el index b974f94..1c5db49 100644 --- a/vlf-write.el +++ b/vlf-write.el @@ -33,43 +33,42 @@ "Write current chunk to file. Always return true to disable save. If changing size of chunk, shift remaining file content." (interactive) - (and (buffer-modified-p) - (or (verify-visited-file-modtime (current-buffer)) - (y-or-n-p "File has changed since visited or saved. \ -Save anyway? ")) - (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))) - (size-change (- vlf-end-pos vlf-start-pos - region-length))) - (if (zerop size-change) - (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) - (min tramp-verbose 2))) - (pos (point)) - (font-lock font-lock-mode)) - (font-lock-mode 0) - (if (< 0 size-change) - (vlf-file-shift-back size-change) - (vlf-file-shift-forward (- size-change))) - (if font-lock (font-lock-mode 1)) - (vlf-move-to-chunk-2 vlf-start-pos - (if (< (- vlf-end-pos vlf-start-pos) - vlf-batch-size) - (+ vlf-start-pos vlf-batch-size) - vlf-end-pos)) - (vlf-update-buffer-name) - (goto-char pos)) - (run-hook-with-args 'vlf-after-batch-functions 'write))))) + (when (and (buffer-modified-p) + (or (verify-visited-file-modtime (current-buffer)) + (y-or-n-p "File has changed since visited or saved.\ + Save anyway? "))) + (run-hook-with-args 'vlf-before-batch-functions 'write) + (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))) + (size-change (- vlf-end-pos vlf-start-pos + region-length))) + (if (zerop size-change) + (write-region nil nil buffer-file-name vlf-start-pos t) + (let ((tramp-verbose (if (boundp 'tramp-verbose) + (min tramp-verbose 2))) + (pos (point)) + (font-lock font-lock-mode)) + (font-lock-mode 0) + (if (< 0 size-change) + (vlf-file-shift-back size-change) + (vlf-file-shift-forward (- size-change))) + (if font-lock (font-lock-mode 1)) + (vlf-move-to-chunk-2 vlf-start-pos + (if (< (- vlf-end-pos vlf-start-pos) + vlf-batch-size) + (+ vlf-start-pos vlf-batch-size) + vlf-end-pos)) + (vlf-update-buffer-name) + (goto-char pos))))) + (run-hook-with-args 'vlf-after-batch-functions 'write)) t) (defun vlf-file-shift-back (size-change)