mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 12:05:31 +00:00
Refactor vlf-query-replace and don't adjust batch size if only
statistics are enabled.
This commit is contained in:
parent
f63ea96c2b
commit
3cfa9b1935
@ -328,11 +328,10 @@ Assume `hexl-mode' is active."
|
||||
|
||||
(defun vlf-query-replace (regexp to-string &optional delimited backward)
|
||||
"Query replace over whole file matching REGEXP with TO-STRING.
|
||||
Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
|
||||
Third arg DELIMITED (prefix arg if interactive), if non-nil, replace
|
||||
only matches surrounded by word boundaries. A negative prefix arg means
|
||||
replace BACKWARD."
|
||||
(interactive
|
||||
(let ((common (query-replace-read-args
|
||||
(interactive (let ((common (query-replace-read-args
|
||||
(concat "Query replace over whole file"
|
||||
(if current-prefix-arg
|
||||
(if (eq current-prefix-arg '-)
|
||||
@ -341,32 +340,24 @@ replace BACKWARD."
|
||||
"")
|
||||
" regexp")
|
||||
t)))
|
||||
(list (nth 0 common) (nth 1 common) (nth 2 common) (nth 3 common))))
|
||||
(query-replace-regexp regexp to-string delimited nil nil backward)
|
||||
(if (buffer-modified-p)
|
||||
(save-buffer))
|
||||
(let ((match-found t)
|
||||
(automatic (eq (lookup-key query-replace-map
|
||||
(vector last-input-event))
|
||||
'automatic)))
|
||||
(while (and match-found (if backward
|
||||
(not (zerop vlf-start-pos))
|
||||
(< vlf-end-pos vlf-file-size)))
|
||||
(setq match-found (vlf-re-search regexp 1 backward
|
||||
(min 1024 (/ vlf-batch-size 8))))
|
||||
(when match-found
|
||||
(cond ((not automatic)
|
||||
(list (nth 0 common) (nth 1 common) (nth 2 common)
|
||||
(nth 3 common))))
|
||||
(let ((not-automatic t))
|
||||
(while (vlf-re-search regexp 1 backward
|
||||
(min 1024 (/ vlf-batch-size 8)))
|
||||
(cond (not-automatic
|
||||
(query-replace-regexp regexp to-string delimited
|
||||
nil nil backward)
|
||||
(setq automatic (eq (lookup-key query-replace-map
|
||||
(setq not-automatic
|
||||
(not (eq (lookup-key query-replace-map
|
||||
(vector last-input-event))
|
||||
'automatic)))
|
||||
'automatic))))
|
||||
(backward (while (re-search-backward regexp nil t)
|
||||
(replace-match to-string)))
|
||||
(t (while (re-search-forward regexp nil t)
|
||||
(replace-match to-string))))
|
||||
(if (buffer-modified-p)
|
||||
(save-buffer))))))
|
||||
(save-buffer)))))
|
||||
|
||||
(provide 'vlf-search)
|
||||
|
||||
|
@ -382,7 +382,7 @@ Suitable for multiple batch operations."
|
||||
Best considered where primitive operations total is closest to
|
||||
`vlf-tune-load-time'. If MIN-IDX and MAX-IDX are given,
|
||||
confine search to this region."
|
||||
(if vlf-tune-enabled
|
||||
(if (eq vlf-tune-enabled t)
|
||||
(progn
|
||||
(setq min-idx (max 0 (or min-idx 0))
|
||||
max-idx (min (or max-idx vlf-tune-max)
|
||||
|
Loading…
x
Reference in New Issue
Block a user