Subject: bug#18388: 24.4.50; REGRESSION: incompatible change to `replace-match-maybe-edit' (and no doc)

From: Drew Adams <[email-masked]>
Date: Fri, 5 Feb 2016 17:40:37 -0800 (PST)

> >> You added argument BACKWARD to this function, and you did not add it as
> >> an &optional parameter.  This breaks all existing code that uses the
> >> function.  The parameter should be &optional.
> >>
> >> What's more, you did not even mention the new arg in the doc string.
> >
> > ping
> 
> I wonder what code and how might use this internal function?

Does it matter?  Could you please make the parameter optional
(and document it)?

This code uses it:

http://www.emacswiki.org/emacs/download/icicles-cmd2.el
See the definition of `icicle-search-replace-match'.

Here is that definition, if you don't want to look at it in context:

(defun icicle-search-replace-match (replacement fixedcase)
  "Replace current match with REPLACEMENT, interpreting escapes.

If REPLACEMENT is a function then call that function on the match
 string and use the result as the replacement.
Otherwise, REPLACEMENT is a string, and it is treated as it would be
 treated by `query-replace-regexp'.

FIXEDCASE is as for `replace-match'.  Non-nil means do not alter case."
  (if (functionp replacement)
      (condition-case icicle-search-replace-match0
          (replace-match (funcall replacement (match-string 0)) fixedcase icicle-search-replace-literally-flag)
        (error (replace-match (funcall replacement (match-string 0)) fixedcase t)))
    (if (fboundp 'query-replace-compile-replacement) ; Emacs 22+.
        (let ((compiled
               (save-match-data
                 (query-replace-compile-replacement replacement
                                                    (not icicle-search-replace-literally-flag)))))
          (condition-case icicle-search-replace-match1
              (let ((enable-recursive-minibuffers    t) ; So we can read input from \?.
                    ;; Save and restore these, because we might read input from \?.
                    (icicle-last-completion-command  icicle-last-completion-command)
                    (icicle-last-input               icicle-last-input))
                (replace-match-maybe-edit
                 (if (consp compiled)
                     ;; `replace-count' is free here, bound in `icicle-search'.
                     (funcall (car compiled) (cdr compiled) (setq replace-count  (1+ replace-count)))
                   compiled)
                 fixedcase icicle-search-replace-literally-flag nil (match-data)
                 nil))                  ; BACKWARD parameter for Emacs 24.4+ - see bug #18388
            ;; @@@@@@ Hopefully this is only a temporary hack, until Emacs bug #18388 is fixed.
            (wrong-number-of-arguments
             (condition-case icicle-search-replace-match3
                 (replace-match-maybe-edit
                  (if (consp compiled)
                      ;; `replace-count' is free here, bound in `icicle-search'.
                      (funcall (car compiled) (cdr compiled) (setq replace-count  (1+ replace-count)))
                    compiled)
                  fixedcase icicle-search-replace-literally-flag nil (match-data))
               (buffer-read-only (ding) (icicle-user-error "Buffer is read-only"))
               (error (icicle-remove-Completions-window) (icicle-user-error "No match for `%s'" replacement))))
            (buffer-read-only (ding) (icicle-user-error "Buffer is read-only"))
            (error (icicle-remove-Completions-window) (icicle-user-error "No match for `%s'" replacement))))
      (condition-case icicle-search-replace-match2 ; Emacs < 22.  Try to interpret `\'.
          (replace-match replacement fixedcase icicle-search-replace-literally-flag)
        (error (replace-match replacement fixedcase t))))))