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