1

I am trying to apply following solution(How to jump to backward found word when switched into reverse incremental search?) into Emacs >27.1, (which works in emacs 26.3):

(define-advice isearch-repeat (:before (direction) goto-other-end)
  "If reversing, start the search from the other end of the current match."
  (unless (eq isearch-forward (eq direction 'forward))
    (when isearch-other-end
      (goto-char isearch-other-end))))

But I am having following error message when I use emacs >27.1:

Wrong number of arguments: (lambda (direction) "If reversing, start the search \
from the other end of the current match." (if (eq isearch-forward (eq direction\
 'forward)) nil (if isearch-other-end (progn (goto-char isearch-other-end))))),\
 2

How could I fix this error?

Drew
  • 75,699
  • 9
  • 109
  • 225
alper
  • 1,238
  • 11
  • 30

1 Answers1

1
  1. It's always more informative to set debug-on-error to t and repro the error, then post the backtrace (at least the beginning). That will show the complete error message, which tells what function raised the error and how many args it expected versus how many it received.

  2. After Emacs 26.3, function isearch-repeat, which you are advising, and whose advice accepts only one argument, was changed to accept either one or two args.

(defun isearch-repeat (direction) ; Emacs 26.3
(defun isearch-repeat (direction &optional count) ; Emacs 27.1 and later

So try this - it matches the lambda list of the Emacs 27 isearch-repeat:

(define-advice isearch-repeat (:before (direction &optional count) goto-other-end)
  "If reversing, start the search from the other end of the current match."
  (unless (eq isearch-forward (eq direction 'forward))
    (when isearch-other-end
      (goto-char isearch-other-end))))
Drew
  • 75,699
  • 9
  • 109
  • 225
  • Can I also keep the function for `26.3` under` (if (version< "27.0" emacs-version)` condition?. I have tried something as follows which didn't work: https://gist.github.com/avatar-lavventura/1b302bb482fc1d48e8dad4ec51dbeed7 – alper Jul 23 '21 at 16:52
  • 1
    I think you have `(version< "27.0" emacs-version)`, but what you're saying is that you really want `(version< emacs-version "27.0")` – Drew Jul 23 '21 at 18:31