+ (let ((from-input (let ((el-search--initial-mb-contents
+ (or el-search--initial-mb-contents
+ (and (eq last-command 'el-search-pattern)
+ (car el-search-history)))))
+ (el-search--read-pattern "Query replace pattern: " nil
+ 'el-search-query-replace-history)))
+ from to)
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (insert from-input)
+ (goto-char 1)
+ (forward-sexp)
+ (skip-chars-forward " \t\n\f")
+ ;; FIXME: maybe more sanity tests here...
+ (if (not (looking-at "->"))
+ (setq from from-input
+ to (let ((el-search--initial-mb-contents nil))
+ (el-search--read-pattern "Replace with result of evaluation of: " from)))
+ (delete-char 2)
+ (goto-char 1)
+ (forward-sexp)
+ (setq from (buffer-substring 1 (point)))
+ (skip-chars-forward " \t\n\f")
+ (setq to (buffer-substring (point) (progn (forward-sexp) (point))))))
+ (unless (and el-search-query-replace-history
+ (not (string= from from-input))
+ (string= from-input (car el-search-query-replace-history)))
+ (push (with-temp-buffer
+ (emacs-lisp-mode)
+ (insert (let ((newline-in-from (string-match-p "\n" from))
+ (newline-in-to (string-match-p "\n" to)))
+ (format "%s%s%s ->%s%s"
+ (if (and (or newline-in-from newline-in-to)
+ (not (string-match-p "\\`\n" from))) "\n" "")
+ (if newline-in-from "\n" "" ) from
+ (if (and (or newline-in-from newline-in-to)
+ (not (string-match-p "\\`\n" to))) "\n" " ") to)))
+ (indent-region 1 (point-max))
+ (buffer-string))
+ el-search-query-replace-history))
+ (el-search--pushnew-to-history from 'el-search-history)