Function: eshell-complete-special-reference
eshell-complete-special-reference is a byte-compiled function defined
in esh-arg.el.gz.
Signature
(eshell-complete-special-reference)
Documentation
If there is a special reference, complete it.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-arg.el.gz
(defun eshell-complete-special-reference ()
"If there is a special reference, complete it."
(when (string-prefix-p "#<" (pcomplete-actual-arg))
(let ((special-ref-types (mapcar #'car eshell-special-ref-alist))
num-args explicit-type)
;; When finished with completion, add a trailing ">" when
;; appropriate.
(add-function
:around (var pcomplete-exit-function)
(lambda (oldfun value status)
(when (eq status 'finished)
;; Don't count the special reference type (e.g. "buffer").
(when (or explicit-type
(and (= num-args 1)
(member value special-ref-types)))
(setq num-args (1- num-args)))
(let ((creation-fun (eshell--special-ref-function
explicit-type 'creation-function)))
;; Check if we already have the maximum number of
;; arguments for this special ref type. If so, finish
;; the ref with ">". Otherwise, insert a space and set
;; the completion status to `sole'.
(if (eq (cdr (func-arity creation-fun)) num-args)
(if (looking-at ">")
(goto-char (match-end 0))
(insert ">"))
(pcomplete-default-exit-function value status)
(setq status 'sole))
(funcall oldfun value status)))))
;; Parse the arguments to this special reference and call the
;; appropriate completion function.
(save-excursion
(eshell-with-temp-command (cons (+ 2 (pcomplete-begin)) (point))
(goto-char (point-max))
(let (pcomplete-args pcomplete-last pcomplete-index pcomplete-begins)
(when (let ((eshell-current-argument-plain t))
(pcomplete-parse-arguments
pcomplete-expand-before-complete))
(setq num-args (length pcomplete-args))
(if (= pcomplete-index pcomplete-last)
;; Call the default special ref completion function,
;; and also add the known special ref types as
;; possible completions.
(throw 'pcomplete-completions
(nconc
(mapcar #'car eshell-special-ref-alist)
(catch 'pcomplete-completions
(funcall (eshell--special-ref-function
nil 'completion-function)))))
;; Get the special ref type and call its completion
;; function.
(let ((first (pcomplete-arg 'first)))
(when (member first special-ref-types)
;; "Complete" the ref type (which we already
;; completed above).
(pcomplete-here)
(setq explicit-type first)))
(funcall (eshell--special-ref-function
explicit-type 'completion-function))))))))))