Function: pcomplete-parse-arguments
pcomplete-parse-arguments is a byte-compiled function defined in
pcomplete.el.gz.
Signature
(pcomplete-parse-arguments &optional EXPAND-P)
Documentation
Parse the command line arguments. Most completions need this info.
Source Code
;; Defined in /usr/src/emacs/lisp/pcomplete.el.gz
(defun pcomplete-parse-arguments (&optional expand-p)
"Parse the command line arguments. Most completions need this info."
(let ((results (funcall pcomplete-parse-arguments-function)))
(when results
(setq pcomplete-args (or (car results) (list ""))
pcomplete-begins (or (cdr results) (list (point)))
pcomplete-last (1- (length pcomplete-args))
pcomplete-index 0
pcomplete-stub (pcomplete-arg 'last))
(let ((begin (pcomplete-begin 'last)))
(if (and (listp pcomplete-stub) ;??
(not pcomplete-expand-only-p))
;; If `pcomplete-stub' is a list, it means it's a list of
;; completions computed during parsing, e.g. Eshell uses
;; that to turn globs into lists of completions.
(if (not pcomplete-allow-modifications)
(let ((completions pcomplete-stub))
;; FIXME: The mapping from what's in the buffer to the list
;; of completions can be arbitrary and will often fail to be
;; understood by the completion style. See bug#50470.
;; E.g. `pcomplete-stub' may end up being "~/Down*"
;; while the completions contain entries like
;; "/home/<foo>/Downloads" which will fail to match the
;; "~/Down*" completion pattern since the completion
;; is neither told that it's a file nor a global pattern.
(setq pcomplete-stub (buffer-substring begin (point)))
(throw 'pcomplete-completions completions))
(let* ((completions pcomplete-stub)
(common-prefix (try-completion "" completions))
(len (length common-prefix)))
(setq pcomplete-stub common-prefix
pcomplete-autolist t)
(when (and begin (> len 0) (not pcomplete-show-list))
(delete-region begin (point))
(pcomplete-insert-entry "" pcomplete-stub))
(throw 'pcomplete-completions completions)))
(when expand-p
(if (stringp pcomplete-stub)
(when begin
(delete-region begin (point))
(insert-and-inherit pcomplete-stub))
(if (and (listp pcomplete-stub)
pcomplete-expand-only-p)
;; this is for the benefit of `pcomplete-expand'
(setq pcomplete-last-completion-length (- (point) begin)
pcomplete-current-completions pcomplete-stub)
(error "Cannot expand argument"))))
(if pcomplete-expand-only-p
(throw 'pcompleted t)
pcomplete-args))))))