Function: cape-wrap-debug

cape-wrap-debug is an autoloaded and byte-compiled function defined in cape.el.

Signature

(cape-wrap-debug CAPF &optional NAME)

Documentation

Call CAPF and return a completion table which prints trace messages.

If CAPF is an anonymous lambda, pass the Capf NAME explicitly for meaningful debugging output.

Source Code

;; Defined in ~/.emacs.d/elpa/cape-20260804.2303/cape.el
;;;###autoload
(defun cape-wrap-debug (capf &optional name)
  "Call CAPF and return a completion table which prints trace messages.
If CAPF is an anonymous lambda, pass the Capf NAME explicitly for
meaningful debugging output."
  (unless name
    (setq name (if (symbolp capf) capf "capf")))
  (setq name (format "%s@%s" name (incf cape--debug-id)))
  (pcase (funcall capf)
    (`(,beg ,end ,table . ,plist)
     (let* ((limit (1+ cape--debug-length))
            (pred (plist-get plist :predicate))
            (cands
             ;; Reset regexps for `all-completions'
             (let (completion-ignore-case completion-regexp-list)
               (all-completions
                "" table
                (lambda (&rest args)
                  (and (or (not pred) (apply pred args)) (>= (decf limit) 0))))))
            (plist-str "")
            (plist-elt plist))
       (while (cdr plist-elt)
         (setq plist-str (format "%s %s=%s" plist-str
                                 (substring (symbol-name (car plist-elt)) 1)
                                 (cape--debug-print (cadr plist-elt)))
               plist-elt (cddr plist-elt)))
       (cape--debug-message
        "%s => input=%s:%s:%S table=%s%s"
        name (+ beg 0) (+ end 0) (buffer-substring-no-properties beg end)
        (cape--debug-print cands)
        plist-str))
     `( ,beg ,end
        ,(cape--debug-table
          table name (copy-marker beg) (copy-marker end t))
        ,@(when-let* ((exit (plist-get plist :exit-function)))
            (list :exit-function
                  (lambda (str status)
                    (cape--debug-message "%s:exit(status=%s string=%S)"
                                         name status str)
                    (funcall exit str status))))
        . ,plist))
    (result
     (cape--debug-message "%s() => %s (No completion)"
                          name (cape--debug-print result)))))