Fix Pcompletion of "tar" when using unrecognized arguments

Previously, arguments to tar like "--warning=no-timestamp" would cause
Pcompletion to hang (bug#58921).

This simplifies the logic flow by moving all the cases for "--"
arguments inside the THEN form of '(if (pcomplete-match "^--" 0)', and
for all "-" arguments inside the ELSE form.

* lisp/pcmpl-gnu.el (pcmpl-gnu--tar-long-options): New variable.
(pcomplete/tar): Properly handle completion of arguments that look
like "--ARG=", even if they're not recognized by this function.
This commit is contained in:
Jim Porter 2023-02-09 23:27:50 -08:00
parent 2e73dec15f
commit 38427494d5

View file

@ -184,17 +184,8 @@ Return the new list."
(when (and (not ,exist) (buffer-live-p ,buf))
(kill-buffer ,buf))))))
;;;###autoload
(defun pcomplete/tar ()
"Completion for the GNU tar utility."
;; options that end in an equal sign will want further completion...
(let (saw-option complete-within)
(while (pcomplete-match "^-" 0)
(setq saw-option t)
(if (pcomplete-match "^--" 0)
(if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
(defvar pcmpl-gnu--tar-long-options
;; FIXME: Extract this list from "tar --help".
(pcomplete-here*
'("--absolute-names"
"--after-date="
"--append"
@ -271,29 +262,30 @@ Return the new list."
"--verbose"
"--verify"
"--version"
"--volno-file=")))
(pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
"--volno-file="))
;;;###autoload
(defun pcomplete/tar ()
"Completion for the GNU tar utility."
;; options that end in an equal sign will want further completion...
(let (saw-option complete-within)
(while (pcomplete-match "^-" 0)
(setq saw-option t)
(if (pcomplete-match "^--" 0)
(cond
((pcomplete-match "\\`-\\'" 0)
(pcomplete-here*))
((pcomplete-match "\\`--after-date=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--backup=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--blocking-factor=" 0)
(pcomplete-here*))
((pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
(pcomplete-here* pcmpl-gnu--tar-long-options))
((pcomplete-match "\\`--directory=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-dirs)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-entries)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--exclude=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
(setq complete-within t))
((pcomplete-match "\\`--file=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)
(pcomplete-here* (pcomplete-dirs-or-entries
pcmpl-gnu-tarfile-regexp)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-entries)
@ -304,36 +296,29 @@ Return the new list."
((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-entries)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--label=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--mode=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-entries)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--newer=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--owner=\\(.*\\)" 0)
(pcomplete-here* (pcmpl-unix-user-names)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--record-size=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
(pcomplete-here* (funcall pcomplete-command-completion-function)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-entries)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--suffix=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--tape-length=" 0)
(pcomplete-here*))
((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
(pcomplete-here* (funcall pcomplete-command-completion-function)
(pcomplete-match-string 1 0)))
((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
(pcomplete-here* (pcomplete-entries)
(pcomplete-match-string 1 0)))))
(pcomplete-match-string 1 0)))
(t
(pcomplete-here*)))
(pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")
(when (pcomplete-match "\\`-\\'" 0)
(pcomplete-here*))))
(unless saw-option
(pcomplete-here
(mapcar #'char-to-string