Perform completion action A on string S with predicate P."
(let ((start 0))
- (while (string-match "[[:space:]]" s start)
+ (while (string-match "[[:space:]=]" s start)
(setq start (match-end 0)))
- (cond
- ((eq (car-safe a) 'boundaries)
- `(boundaries ,start . ,(and (string-match "[[:space:]]" (cdr a))
- (match-beginning 0))))
- ((eq a 'metadata)
- `(metadata
- (category . kubed-command-line)
- (affixation-function
- . ,(lambda (cands)
- (let ((max (seq-max
- (cons 0 (mapcar #'string-width cands)))))
- (mapcar
- (lambda (cand)
- (list
- cand ""
- (if-let
- ((desc (get-text-property
- 0 'kubed-command-line-argument-description
- cand)))
- (concat
- (make-string (1+ (- max (string-width cand))) ?\s)
- (propertize desc 'face 'completions-annotations))
- "")))
- cands))))))
- (t (let ((table
- (let* ((lines
- (apply #'process-lines-ignore-status
- kubed-kubectl-executable "__complete"
- (let ((args (cdr (split-string-and-unquote s))))
- (if (string-suffix-p " " s)
- (nconc args '(""))
- args))))
- (code nil)
- (comps (seq-take-while
- (lambda (line)
- (not (and (string-match "^:\\([0-9]+\\)$" line)
- (setq code (string-to-number
- (match-string 1 line))))))
- lines)))
- (when (and code (zerop (logand #b1001 code)))
- (mapcar
- (lambda (comp)
- (pcase (split-string comp "\t" t)
- (`(,c ,a . ,_)
- (propertize c 'kubed-command-line-argument-description
- (car (split-string a "\\." t))))
- (`(,c . ,_) c)))
- comps)))))
- (if a (complete-with-action a table (substring s start) p)
- (let ((comp (complete-with-action a table (substring s start) p)))
- (if (stringp comp) (concat (substring s 0 start) comp) comp))))))))
+ (if (eq a 'metadata)
+ `(metadata
+ (category . kubed-command-line)
+ (affixation-function
+ . ,(lambda (cands)
+ (let ((max (seq-max
+ (cons 0 (mapcar #'string-width cands)))))
+ (mapcar
+ (lambda (cand)
+ (list
+ cand ""
+ (if-let
+ ((desc (get-text-property
+ 0 'kubed-command-line-argument-description
+ cand)))
+ (concat
+ (make-string (1+ (- max (string-width cand))) ?\s)
+ (propertize desc 'face 'completions-annotations))
+ "")))
+ cands)))))
+ (let* ((lines
+ (apply #'process-lines-ignore-status
+ kubed-kubectl-executable "__complete"
+ (let ((args (cdr (split-string-and-unquote s))))
+ (if (string-suffix-p " " s)
+ (nconc args '(""))
+ args))))
+ (code nil)
+ (comps (seq-take-while
+ (lambda (line)
+ (not (and (string-match "^:\\([0-9]+\\)$" line)
+ (setq code (string-to-number
+ (match-string 1 line))))))
+ lines)))
+ (when (and code (not (zerop code)))
+ (if (zerop (logand #b1001 code))
+ (if (eq (car-safe a) 'boundaries)
+ `(boundaries ,start . ,(and (string-match "[[:space:]=]" (cdr a))
+ (match-beginning 0)))
+ (let ((table (mapcar
+ (lambda (comp)
+ (pcase (split-string comp "\t" t)
+ (`(,c ,a . ,_)
+ (propertize c 'kubed-command-line-argument-description
+ (car (split-string a "\\." t))))
+ (`(,c . ,_) c)))
+ comps)))
+ (if a (complete-with-action a table (substring s start) p)
+ ;; `try-completion'.
+ (let ((comp (complete-with-action a table (substring s start) p)))
+ (if (stringp comp) (concat (substring s 0 start) comp) comp)))))
+ ;; File name completion. `comps' are valid extensions.
+ (setq p (lambda (f)
+ (or (file-directory-p f)
+ (when (string-match "\\.[^.]*\\'" f)
+ (member (substring f (1+ (match-beginning 0)))
+ comps)))))
+ (if (eq (car-safe a) 'boundaries)
+ ;; Find nested boundaries.
+ (let* ((suf (cdr a))
+ (bounds (completion-boundaries
+ (substring s start) #'completion-file-name-table p
+ (substring suf 0 (string-match "[[:space:]=]" suf)))))
+ `(boundaries ,(+ (car bounds) start) . ,(cdr bounds)))
+ (if a (complete-with-action a #'completion-file-name-table
+ (substring s start) p)
+ (let ((comp (complete-with-action a #'completion-file-name-table
+ (substring s start) p)))
+ (if (stringp comp) (concat (substring s 0 start) comp) comp))))))))))
(defvar kubed-kubectl-command-history nil
"Minibuffer history for `kubed-kubectl-command'.")