Function: gptel--maybe-funcall

gptel--maybe-funcall is a macro defined in gptel-request.el.

Signature

(gptel--maybe-funcall FUNC-OR-SYM &rest ARGS)

Documentation

If FUNC-OR-SYM is a function, call it with ARGS.

Otherwise, evaluate it as a variable.

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(defmacro gptel--maybe-funcall (func-or-sym &rest args)
  "If FUNC-OR-SYM is a function, call it with ARGS.

Otherwise, evaluate it as a variable."
  `(if (functionp ,func-or-sym)
       ;; TODO(v1.0) Remove this condition-case.  This arity check is for
       ;; benefit of users who have personal customizations touching gptel's
       ;; internal API re: backend header and url functions.
       (condition-case nil
           (apply ,func-or-sym (list ,@args))
         (wrong-number-of-arguments
          (message "Displaying warning")
          (display-warning
           'gptel (format "%s calling convention has changed: \
Called with %d arguments but accept %d.  \
Please update them, and see NEWS (0.9.9.5) for details."
                          (if (symbolp ,func-or-sym) (format "Function %s" ,func-or-sym)
                            "gptel-backend-header/gptel-backend-url function")
                          (length ',args) (car (func-arity ,func-or-sym))))
          (funcall ,func-or-sym)))
     ,func-or-sym))