mirror of
				https://github.com/m00natic/vlfi.git
				synced 2025-11-04 09:01:37 +00:00 
			
		
		
		
	Refactor vlf-query-replace and don't adjust batch size if only
statistics are enabled.
This commit is contained in:
		@@ -328,45 +328,36 @@ 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 '-)
 | 
					                                              " backward"
 | 
				
			||||||
                                  " backward"
 | 
					                                            " word")
 | 
				
			||||||
                                " word")
 | 
					                                        "")
 | 
				
			||||||
                            "")
 | 
					                                      " regexp")
 | 
				
			||||||
                          " regexp")
 | 
					                              t)))
 | 
				
			||||||
                  t)))
 | 
					                 (list (nth 0 common) (nth 1 common) (nth 2 common)
 | 
				
			||||||
     (list (nth 0 common) (nth 1 common) (nth 2 common) (nth 3 common))))
 | 
					                       (nth 3 common))))
 | 
				
			||||||
  (query-replace-regexp regexp to-string delimited nil nil backward)
 | 
					  (let ((not-automatic t))
 | 
				
			||||||
  (if (buffer-modified-p)
 | 
					    (while (vlf-re-search regexp 1 backward
 | 
				
			||||||
      (save-buffer))
 | 
					                          (min 1024 (/ vlf-batch-size 8)))
 | 
				
			||||||
  (let ((match-found t)
 | 
					      (cond (not-automatic
 | 
				
			||||||
        (automatic (eq (lookup-key query-replace-map
 | 
					             (query-replace-regexp regexp to-string delimited
 | 
				
			||||||
                                   (vector last-input-event))
 | 
					                                   nil nil backward)
 | 
				
			||||||
                       'automatic)))
 | 
					             (setq not-automatic
 | 
				
			||||||
    (while (and match-found (if backward
 | 
					                   (not (eq (lookup-key query-replace-map
 | 
				
			||||||
                                (not (zerop vlf-start-pos))
 | 
					                                        (vector last-input-event))
 | 
				
			||||||
                              (< vlf-end-pos vlf-file-size)))
 | 
					                            'automatic))))
 | 
				
			||||||
      (setq match-found (vlf-re-search regexp 1 backward
 | 
					            (backward (while (re-search-backward regexp nil t)
 | 
				
			||||||
                                       (min 1024 (/ vlf-batch-size 8))))
 | 
					                        (replace-match to-string)))
 | 
				
			||||||
      (when match-found
 | 
					            (t (while (re-search-forward regexp nil t)
 | 
				
			||||||
        (cond ((not automatic)
 | 
					                 (replace-match to-string))))
 | 
				
			||||||
               (query-replace-regexp regexp to-string delimited
 | 
					      (if (buffer-modified-p)
 | 
				
			||||||
                                     nil nil backward)
 | 
					          (save-buffer)))))
 | 
				
			||||||
               (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))))))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user