emacs - A `query-replace` that asks for a new replacement string for each occurrence -


i'm looking function works similar query-replace instead of using same replacement string on , on again, asks replacement string each time match found. say, once match found, can either skip match or enter replacement mode, can specify string used replacing match (with history of previous replacements).

even more useful query-replace-regexp variant, allows use groupings of search string.

i have written piece of code used non-regexp version, however, i'm stuck @ part of replacing , repeating whole search after replacement done/the match skipped. code far is:

(defun query-replace-ask (search)   (interactive "squery replace: ")   (if (search-forward search nil t)       (let ((beg (match-beginning 0))             (end (match-end 0))             (if (y-or-n-p "replace?")                 (replacement (read-string "replacement: "))               (                ;; next search                )))         ;; replace beg end replacement         ;; next search         ))) 

also, nice if function output number of total replacements once function finishes.

this functionality part of query-replace. can call e. see options, press ? while replacing.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -