Skip to content

Instantly share code, notes, and snippets.

@emasaka
Created March 17, 2011 11:29
Show Gist options
  • Select an option

  • Save emasaka/874182 to your computer and use it in GitHub Desktop.

Select an option

Save emasaka/874182 to your computer and use it in GitHub Desktop.
(defvar *replace-count-base* 0)
(defvar *replace-count-format* "%d")
(defadvice query-replace-compile-replacement
(after replace-count-format)
"Change \\# format of (query-)replace-regexp"
(when (consp ad-return-value)
(let ((oldexp '(number-to-string replace-count))
(newexp '(format *replace-count-format*
(+ replace-count *replace-count-base*) )))
(if (and (eq (car ad-return-value) 'replace-eval-replacement)
(equal (cdr ad-return-value) oldexp) )
(setcdr ad-return-value newexp) ; only \#
(let ((lst ad-return-value))
(while lst
(if (equal (car lst) oldexp) (setcar lst newexp))
(pop lst) )) ))))
(ad-activate 'query-replace-compile-replacement)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment