“Wrong number of arguments: (1 . 2), 0” means that a function expects at least 1 and at most 2 arguments (i.e. 1 mandatory and 1 optional argument), but it was called with 0 arguments.
As npostavs explained in a comment, you can run M-x toggle-debug-on-error
and repeat the action again to get more information. When the error occurs, you'll see a backtrace, which lists the active function calls, from innermost to outermost. The first line is the function that was just called, that's the one which isn't receiving the correct number of arguments. When you've finished reading the backtrace, press ESC ESC ESC
or C-]
to exit the debugging mode.
The help for the function ggtags-find-tag-dwim
(C-h f ggtags-find-tag-dwim RET
) tells you that its call syntax is
(ggtags-find-tag-dwim NAME &optional WHAT)
I.e. it's called with two parameters called name
and what
(the names are capitalized in the help), and the second parameter is optional.
When the function is called interactively, i.e. when it's directly bound to a key (or mouse or other event), Emacs passes it parameters based on the function's interactive specification. Some common examples of automatic parameter passing include the numerical prefix argument, the point or region (point and mark), something typed by the user (arbitrary string, file name, buffer name, etc.), etc. Parameters can also be generated by Lisp code given in the function definition.
You need to pull up the source code to see the interactive specification. The source code will be linked from the function help if it's available. The interactive specification looks like a call to a function called interactive
just below the function's documentation string.
(defun ggtags-find-tag-dwim (name &optional what)
"Find NAME by context.
…"
(interactive
(let ((include (and (not current-prefix-arg) (ggtags-include-file))))
(ggtags-ensure-project)
(if include (list include 'include)
(list (ggtags-read-tag 'definition current-prefix-arg)
(and current-prefix-arg 'definition)))))
…
You can copy this interactive specification into your own wrapper. But since it's complicated and your wrapper is simple, you should instead tell Emacs to call the function interactively, i.e. to pass parameters automatically as if the function had been directly invoked by pressing a key.
(define-key ggtags-mode-map (kbd "M-.")
(lambda ()
(interactive)
(call-interactively 'ggtags-find-tag-dwim)
(recenter)))
For this specific case, since it seems that you always want to run recenter
after ggtags-find-tag-dwim
, there's a simpler way: the Ggtags package has a customization for this. In the Customize interface, navigate to the Ggtags group (“GNU Global source code tagging system”), and change “Hook run immediately after finding a tag.” to recenter
. Alternatively, put the following line in your init file:
(setq ggtags-find-tag-hook 'recenter)
M-x toggle-debug-on-error
should give you more info when that happens.ggtags-find-tag-dwim
takes a mandatory argumentNAME
and a second, optionalWHAT
. You are calling it without any arguments. Refer to its documentation withM-x describe-function RET ggtags-find-tag-dwim RET
orC-h f ggtags-find-tag-dwim RET
.ggtags-find-tag-dwim
provides aninteractive
form for generating its two arguments when called as a command, rather than as a function.