0

I have this little LaTeX helper function:

(defun my--insert-chord (chord)
  "Prompt for a CHORD and insert it at point. TODO: make it agnostic to the package used."
  (interactive "MChord: ")
  (insert (concat "\\[" chord "]")))

that works like a breeze.

Now, I want to integrate with isearch. I have this other helper function (taken from this question and in turn from Endless Parentheses):

(defun isearch-exit-other-end ()
  "Exit isearch, at the opposite end of the string."
  (interactive)
  (goto-char isearch-other-end)
  (isearch-exit))

Now, I want to combine the two and bind themto a key. Since it's a one-off use, IIUC it makes sense to use a lambda:

(define-key isearch-mode-map (kbd "C-M-c")
          (lambda () (interactive) (isearch-exit-other-end) (call-interactively (my--insert-chord))))

But Emacs complains:

Debugger entered--Lisp error: (wrong-number-of-arguments (lambda (chord) "Prompt for a CHORD and insert it at point. TODO: m..." (interactive "MChord: ") (insert (concat "\\[" chord "]"))) 0)
  my--insert-chord()
  (call-interactively (my--insert-chord))
  (lambda nil (interactive) (isearch-exit-other-end) (call-interactively (my--insert-chord)))()
  funcall-interactively((lambda nil (interactive) (isearch-exit-other-end) (call-interactively (my--insert-chord))))
  command-execute((lambda nil (interactive) (isearch-exit-other-end) (call-interactively (my--insert-chord))))

Now, of course I haven't provided the correct number of arguments, that's because my--insert-chord should prompt for one. How can I achieve this? Of course, I can duplicate the interactive string in the lambda, but I suspect there's a clever way, since this would lead to code duplication. My Google-fu only provided examples to pass arguments via code, but that's not what I want. If this is a dup I apologize, and I will gratefully taken redirection.

Thanks!

1 Answer 1

3

Instead of providing a function to `call-interactively, you are calling the function (to pass the return value from that call).

Try (call-interactively 'my--insert-chord).

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.