I am looking for something that could be used like this:
(when (cl-applicable-method-p 'foo "arg") ...)
I vaguely remember that I have seen that once and that it came with a comment saying that one shouldn't use it. However I would like to at least investigate this approach, which I cannot do if I cannot guess the name and am unable to find the implementation. (But please let me know what is wrong with using such a predicate, if anything.)
I cannot just call the generic function and prepare to handle cl-no-applicable-method
errors or use a no-op default-method because I have to do some additional work before and after calling the generic function, but only if it actually is implemented given the arguments I intend to call it with
Actually the "argument" is the current major-mode, the arglist of the methods is (&context (major-mode MODE))
, which probably complicates this further.
It would be nice if I could do something like:
(when (cl-applicable-method-p 'foo &context major-mode)
(prepare)
(foo)
(finish))
Another approach would be:
(defmacro foo-common (&rest body)
`(progn (prepare)
,@body
(finish)))
(cl-defgeneric foo ()
nil) ; noop
(cl-defmethod foo (&context (major-mode emacs-lisp-mode))
(foo-common
(mode-specific-stuff)))
but that feels hackish, it would be nicer if foo-common
could be replaced with a foo
:around
method.
I am trying to replace the various magit-...-refresh-buffer
functions used in magit-refresh-buffer
with a generic function.