Answers:
我将以下用于Emacs 24+的工作:
;; query replace all from buffer start
(fset 'my-query-replace-all 'query-replace)
(advice-add 'my-query-replace-all
:around
#'(lambda(oldfun &rest args)
"Query replace the whole buffer."
;; set start pos
(unless (nth 3 args)
(setf (nth 3 args)
(if (region-active-p)
(region-beginning)
(point-min))))
(unless (nth 4 args)
(setf (nth 4 args)
(if (region-active-p)
(region-end)
(point-max))))
(apply oldfun args)))
(global-set-key "\C-cr" 'my-query-replace-all)
关于区域替换大小写,以及是否通过了任何START和END参数。