Recently I upgraded my emacs from 24 to 25.3.1. After the upgrade, the following code does not work anymore:

;;           Wrap Query Replace
;; copy the original query-replace-function 
(fset 'wrap-query-replace 'query-replace)

;; advise the new version to repeat the search after it 
;; finishes at the bottom of the buffer the first time:    
(defadvice wrap-query-replace 
    (around replace-wrap 
  "Execute a query-replace, wrapping to the top of the buffer 
   after you reach the bottom"
    (let ((start (point)))
      (goto-char (point-min))
      (ad-set-args 4 (list (point-min) start))

;; Turn on the advice    
(ad-activate 'wrap-query-replace)
(global-set-key "\C-cq" 'wrap-query-replace)

When I tried to call the function with C-cq, it asked me for word to search and word to replace as usual, but when I press return, I received the following error in emacs 25.3.1 : enter image description here

Any idea what's wrong with it?

  • Try to re-byte-compile the file. Furthermore, you should gradually switch from the depreciated defadvice to advice-add.
    – Tobias
    Sep 14, 2017 at 14:12

1 Answer 1


The problem is the usual one for pieces of advice: they are tightly linked to the associated function and need to be updated when that function is modified. E.g. the newer Emacsen have added optional arguments to that function, hence your declaration (FROM-STRING TO-STRING &optional DELIMITED START END) is now incorrect. You might be able to fix it by adding &rest args to it, tho I'd suggest you simply remove it since you don't make use of it anyway.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.