1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-04-18 16:50:19 +01:00

Optionally strip superfluous operations when inserting batches.

This commit is contained in:
Andrey Kotlarski 2013-04-14 01:09:13 +03:00
parent 4cbefdeeca
commit e67895afc4

30
vlfi.el
View File

@ -276,9 +276,10 @@ When prefix argument is negative
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(vlfi-update-buffer-name)) (vlfi-update-buffer-name))
(defun vlfi-move-to-batch (start) (defun vlfi-move-to-batch (start &optional minimal)
"Move to batch determined by START. "Move to batch determined by START.
Adjust according to file start/end and show `vlfi-batch-size' bytes." Adjust according to file start/end and show `vlfi-batch-size' bytes.
When given MINIMAL flag, skip non important operations."
(setq vlfi-start-pos (max 0 start) (setq vlfi-start-pos (max 0 start)
vlfi-end-pos (+ vlfi-start-pos vlfi-batch-size)) vlfi-end-pos (+ vlfi-start-pos vlfi-batch-size))
(if (< vlfi-file-size vlfi-end-pos) ; re-check file size (if (< vlfi-file-size vlfi-end-pos) ; re-check file size
@ -291,12 +292,14 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
(insert-file-contents buffer-file-name nil (insert-file-contents buffer-file-name nil
vlfi-start-pos vlfi-end-pos) vlfi-start-pos vlfi-end-pos)
(goto-char pos)) (goto-char pos))
(set-visited-file-modtime)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(vlfi-update-buffer-name)) (unless minimal
(set-visited-file-modtime)
(vlfi-update-buffer-name)))
(defun vlfi-move-to-chunk (start end) (defun vlfi-move-to-chunk (start end &optional minimal)
"Move to chunk determined by START END." "Move to chunk determined by START END.
When given MINIMAL flag, skip non important operations."
(if (< vlfi-file-size end) ; re-check file size (if (< vlfi-file-size end) ; re-check file size
(setq vlfi-file-size (vlfi-get-file-size buffer-file-name))) (setq vlfi-file-size (vlfi-get-file-size buffer-file-name)))
(setq vlfi-start-pos (max 0 start) (setq vlfi-start-pos (max 0 start)
@ -307,9 +310,10 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
(insert-file-contents buffer-file-name nil (insert-file-contents buffer-file-name nil
vlfi-start-pos vlfi-end-pos) vlfi-start-pos vlfi-end-pos)
(goto-char pos)) (goto-char pos))
(set-visited-file-modtime)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(vlfi-update-buffer-name)) (unless minimal
(set-visited-file-modtime)
(vlfi-update-buffer-name)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; search ;;; search
@ -344,7 +348,7 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
(vlfi-move-to-batch (vlfi-move-to-batch
(if (< match-start-pos batch-move) (if (< match-start-pos batch-move)
(- match-start-pos vlfi-batch-size) (- match-start-pos vlfi-batch-size)
batch-move))) batch-move) t))
(goto-char (if (< match-start-pos (goto-char (if (< match-start-pos
vlfi-end-pos) vlfi-end-pos)
(- match-start-pos (- match-start-pos
@ -365,7 +369,7 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
(vlfi-move-to-batch (vlfi-move-to-batch
(if (< batch-move match-end-pos) (if (< batch-move match-end-pos)
match-end-pos match-end-pos
batch-move))) batch-move) t))
(goto-char (if (< vlfi-start-pos match-end-pos) (goto-char (if (< vlfi-start-pos match-end-pos)
(- match-end-pos vlfi-start-pos) (- match-end-pos vlfi-start-pos)
(point-min))) (point-min)))
@ -383,9 +387,9 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
According to COUNT and left TO-FIND, show if search has been According to COUNT and left TO-FIND, show if search has been
successful. Return nil if nothing found." successful. Return nil if nothing found."
(let ((success (zerop to-find))) (let ((success (zerop to-find)))
(or success (if success
(vlfi-move-to-batch (- match-pos-start (vlfi-update-buffer-name)
(/ vlfi-batch-size 2)))) (vlfi-move-to-batch (- match-pos-start (/ vlfi-batch-size 2))))
(let* ((match-end (- match-pos-end vlfi-start-pos)) (let* ((match-end (- match-pos-end vlfi-start-pos))
(overlay (make-overlay (- match-pos-start vlfi-start-pos) (overlay (make-overlay (- match-pos-start vlfi-start-pos)
match-end))) match-end)))