Function: majutsu-jj--completion-table

majutsu-jj--completion-table is a natively compiled function defined in majutsu-jj.el.

Signature

(majutsu-jj--completion-table ARGS &optional CATEGORY)

Documentation

Return a dynamic Emacs completion table using jj native completion.

ARGS are command-line arguments before the value being completed. The current input string is passed to jj as the value argument, which lets expression arguments such as revsets continue completing after operators like | or ... CATEGORY, when non-nil, is exposed in completion metadata.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-jj.el
(defun majutsu-jj--completion-table (args &optional category)
  "Return a dynamic Emacs completion table using jj native completion.
ARGS are command-line arguments before the value being completed.  The
current input string is passed to jj as the value argument, which lets
expression arguments such as revsets continue completing after operators
like `|' or `..'.  CATEGORY, when non-nil, is exposed in completion
metadata."
  (let* ((payload-cache (make-hash-table :test #'equal))
         (annotations (make-hash-table :test #'equal))
         (metadata-category (or category 'majutsu-revision))
         (metadata
          (majutsu-completion-payload-metadata
           (list :category metadata-category
                 :annotation-function
                 (lambda (candidate)
                   (when-let* ((annotation (gethash candidate annotations)))
                     (if (string-prefix-p " " annotation)
                         annotation
                       (concat " " annotation))))
                 :annotation-suffix-function
                 (apply-partially #'majutsu-jj--completion-suffix
                                  annotations))
           metadata-category)))
    (cl-labels
        ((payload-for
           (string)
           (or (gethash string payload-cache)
               (let ((payload (majutsu-jj--completion-payload
                               (append args (list string))
                               metadata-category)))
                 (puthash string payload payload-cache)
                 (when-let* ((payload-annotations (plist-get payload :annotations)))
                   (maphash (lambda (candidate annotation)
                              (puthash candidate annotation annotations))
                            payload-annotations))
                 payload))))
      (completion-table-with-metadata
       (lambda (string predicate action)
         (complete-with-action
          action
          (plist-get (payload-for string) :candidates)
          string predicate))
       metadata))))