diff --git a/vlf-search.el b/vlf-search.el index 7a67467..5be45b7 100644 --- a/vlf-search.el +++ b/vlf-search.el @@ -328,45 +328,36 @@ 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 - (concat "Query replace over whole file" - (if current-prefix-arg - (if (eq current-prefix-arg '-) - " backward" - " word") - "") - " 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) - (query-replace-regexp regexp to-string delimited - nil nil backward) - (setq automatic (eq (lookup-key query-replace-map - (vector last-input-event)) - '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)))))) + (interactive (let ((common (query-replace-read-args + (concat "Query replace over whole file" + (if current-prefix-arg + (if (eq current-prefix-arg '-) + " backward" + " word") + "") + " regexp") + t))) + (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 not-automatic + (not (eq (lookup-key query-replace-map + (vector last-input-event)) + '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))))) (provide 'vlf-search) diff --git a/vlf-tune.el b/vlf-tune.el index eb0fa81..c2fe69a 100644 --- a/vlf-tune.el +++ b/vlf-tune.el @@ -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)