Commit dd2ac746 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

Add support for completion of quoted/escaped data.

parents 784e7d6e cc356a5d
...@@ -169,6 +169,14 @@ still be supported for Emacs 24.x. ...@@ -169,6 +169,14 @@ still be supported for Emacs 24.x.
* Lisp changes in Emacs 24.2 * Lisp changes in Emacs 24.2
** Completion
*** New function `completion-table-with-quoting' to handle completion
in the presence of quoting, such as file completion in shell buffers.
*** New function `completion-table-subvert' to use an existing completion
table, but with a different prefix.
* Changes in Emacs 24.2 on non-free operating systems * Changes in Emacs 24.2 on non-free operating systems
......
2012-04-25 Stefan Monnier <monnier@iro.umontreal.ca>
* ffap.el: Remove old code for obsolete package.
(ffap-complete-as-file-p): Remove.
Use completion-table-with-quoting for comint and pcomplete.
* comint.el (comint--unquote&requote-argument)
(comint--unquote-argument, comint--requote-argument): New functions.
(comint--unquote&expand-filename, comint-unquote-filename): Obsolete.
(comint-quote-filename): Use regexp-opt-charset.
(comint--common-suffix, comint--common-quoted-suffix)
(comint--table-subvert): Remove.
(comint-unquote-function, comint-requote-function): New vars.
(comint--complete-file-name-data): Use them with
completion-table-with-quoting.
* pcmpl-unix.el (pcomplete/scp): Use completion-table-subvert.
* pcomplete.el (pcomplete-arg-quote-list)
(pcomplete-quote-arg-hook, pcomplete-quote-argument): Obsolete.
(pcomplete-unquote-argument-function): Default to non-nil.
(pcomplete-unquote-argument): Simplify.
(pcomplete--common-quoted-suffix): Remove.
(pcomplete-requote-argument-function): New var.
(pcomplete--common-suffix): New function.
(pcomplete-completions-at-point): Use completion-table-with-quoting
and completion-table-subvert.
* minibuffer.el: Use completion-table-with-quoting for read-file-name.
(minibuffer--double-dollars): Preserve properties.
(completion--sifn-requote): New function.
(completion--file-name-table): Rewrite using it and c-t-with-quoting.
* minibuffer.el: Add support for completion of quoted/escaped data.
(completion-table-with-quoting, completion-table-subvert): New funs.
(completion--twq-try, completion--twq-all): New functions.
(completion--nth-completion): New function.
(completion-try-completion, completion-all-completions): Use it.
2012-04-25 Leo Liu <sdl.web@gmail.com> 2012-04-25 Leo Liu <sdl.web@gmail.com>
* progmodes/python.el (python-pdbtrack-get-source-buffer): Use * progmodes/python.el (python-pdbtrack-get-source-buffer):
compilation-message if available to find real filename. Use compilation-message if available to find real filename.
2012-04-25 Chong Yidong <cyd@gnu.org> 2012-04-25 Chong Yidong <cyd@gnu.org>
...@@ -21,32 +58,31 @@ ...@@ -21,32 +58,31 @@
2012-04-25 Alex Harsanyi <AlexHarsanyi@gmail.com> 2012-04-25 Alex Harsanyi <AlexHarsanyi@gmail.com>
Sync with soap-client repository. Support SOAP simpleType. (Bug#10331) Sync with soap-client repository. Support SOAP simpleType (Bug#10331).
* soap-client.el (soap-resolve-references-for-sequence-type) * soap-client.el (soap-resolve-references-for-sequence-type)
(soap-resolve-references-for-array-type): hack to prevent self (soap-resolve-references-for-array-type): Hack to prevent self
references, see Bug#9. references, see Bug#9.
(soap-parse-envelope): report the contents of the 'detail' node (soap-parse-envelope): Report the contents of the 'detail' node
when receiving a fault reply. when receiving a fault reply.
(soap-parse-envelope): report the contents of the entire 'detail' (soap-parse-envelope): Report the contents of the entire 'detail' node.
node.
* soap-inspect.el (soap-sample-value-for-simple-type) * soap-inspect.el (soap-sample-value-for-simple-type)
(soap-inspect-simple-type): new function (soap-inspect-simple-type): New function.
* soap-client.el (soap-simple-type): new struct * soap-client.el (soap-simple-type): New struct.
(soap-default-xsd-types, soap-default-soapenc-types) (soap-default-xsd-types, soap-default-soapenc-types)
(soap-decode-basic-type, soap-encode-basic-type): support (soap-decode-basic-type, soap-encode-basic-type):
unsignedInt and double basic types support unsignedInt and double basic types.
(soap-resolve-references-for-simple-type) (soap-resolve-references-for-simple-type)
(soap-parse-simple-type, soap-encode-simple-type): new function (soap-parse-simple-type, soap-encode-simple-type): New function.
(soap-parse-schema): parse xsd:simpleType declarations (soap-parse-schema): Parse xsd:simpleType declarations.
* soap-client.el (soap-default-xsd-types) * soap-client.el (soap-default-xsd-types)
(soap-default-soapenc-types): add integer, byte and anyURI types (soap-default-soapenc-types): Add integer, byte and anyURI types.
(soap-parse-complex-type-complex-content): use `soap-wk2l' to find (soap-parse-complex-type-complex-content): Use `soap-wk2l' to find
the local name of "soapenc:Array" the local name of "soapenc:Array".
(soap-decode-basic-type, soap-encode-basic-type): support encoding (soap-decode-basic-type, soap-encode-basic-type): Support encoding
decoding integer, byte and anyURI xsd types. decoding integer, byte and anyURI xsd types.
2012-04-25 Chong Yidong <cyd@gnu.org> 2012-04-25 Chong Yidong <cyd@gnu.org>
...@@ -166,8 +202,8 @@ ...@@ -166,8 +202,8 @@
* ispell.el (ispell-insert-word) Remove unneeded function using * ispell.el (ispell-insert-word) Remove unneeded function using
obsolete `translation-table-for-input'. obsolete `translation-table-for-input'.
(ispell-word, ispell-process-line, ispell-complete-word): Use (ispell-word, ispell-process-line, ispell-complete-word):
plain `insert' instead of removed `ispell-insert-word'. Use plain `insert' instead of removed `ispell-insert-word'.
2012-04-22 Chong Yidong <cyd@gnu.org> 2012-04-22 Chong Yidong <cyd@gnu.org>
...@@ -185,8 +221,8 @@ ...@@ -185,8 +221,8 @@
Move functions from C to Lisp. Make non-blocking method calls Move functions from C to Lisp. Make non-blocking method calls
the default. Implement further D-Bus standard interfaces. the default. Implement further D-Bus standard interfaces.
* net/dbus.el (dbus-message-internal): Declare function. Remove * net/dbus.el (dbus-message-internal): Declare function.
unneeded function declarations. Remove unneeded function declarations.
(defvar dbus-message-type-invalid, dbus-message-type-method-call) (defvar dbus-message-type-invalid, dbus-message-type-method-call)
(dbus-message-type-method-return, dbus-message-type-error) (dbus-message-type-method-return, dbus-message-type-error)
(dbus-message-type-signal): Declare variables. Remove local (dbus-message-type-signal): Declare variables. Remove local
...@@ -202,8 +238,8 @@ ...@@ -202,8 +238,8 @@
(dbus-register-signal, dbus-register-method): New defuns, moved (dbus-register-signal, dbus-register-method): New defuns, moved
from dbusbind.c from dbusbind.c
(dbus-call-method-handler, dbus-setenv) (dbus-call-method-handler, dbus-setenv)
(dbus-get-all-managed-objects, dbus-managed-objects-handler): New (dbus-get-all-managed-objects, dbus-managed-objects-handler):
defuns. New defuns.
(dbus-call-method-non-blocking): Make it an obsolete function. (dbus-call-method-non-blocking): Make it an obsolete function.
(dbus-unregister-object, dbus-unregister-service) (dbus-unregister-object, dbus-unregister-service)
(dbus-handle-event, dbus-register-property) (dbus-handle-event, dbus-register-property)
...@@ -328,8 +364,8 @@ ...@@ -328,8 +364,8 @@
2012-04-20 Chong Yidong <cyd@gnu.org> 2012-04-20 Chong Yidong <cyd@gnu.org>
* progmodes/gdb-mi.el (gdb-inferior-io--maybe-delete-pty): New * progmodes/gdb-mi.el (gdb-inferior-io--maybe-delete-pty):
function to call delete-process on the gdb-inferior buffer's pty. New function to call delete-process on the gdb-inferior buffer's pty.
(gdb-reset): Use it, instead of relying on kill-buffer to kill the (gdb-reset): Use it, instead of relying on kill-buffer to kill the
pty process (Bug#11273). pty process (Bug#11273).
(gdb-update): New arg to suppress talking to the gdb process. (gdb-update): New arg to suppress talking to the gdb process.
...@@ -360,8 +396,8 @@ ...@@ -360,8 +396,8 @@
(c-comment-indent, c-scan-conditionals, c-indent-defun) (c-comment-indent, c-scan-conditionals, c-indent-defun)
(c-context-line-break): Bind case-fold-search to nil. (c-context-line-break): Bind case-fold-search to nil.
* progmodes/cc-mode.el (c-font-lock-fontify-region): Bind * progmodes/cc-mode.el (c-font-lock-fontify-region):
case-fold-search to nil. Bind case-fold-search to nil.
2012-04-20 Chong Yidong <cyd@gnu.org> 2012-04-20 Chong Yidong <cyd@gnu.org>
...@@ -1112,8 +1148,8 @@ ...@@ -1112,8 +1148,8 @@
2012-03-30 Agustín Martín Domingo <agustin.martin@hispalinux.es> 2012-03-30 Agustín Martín Domingo <agustin.martin@hispalinux.es>
* ispell.el (ispell-get-extended-character-mode): Disable * ispell.el (ispell-get-extended-character-mode):
extended-char-mode for hunspell. hunspell does not support it Disable extended-char-mode for hunspell. hunspell does not support it
and treats ~word as ordinary words in pipe mode. and treats ~word as ordinary words in pipe mode.
2012-03-30 Glenn Morris <rgm@gnu.org> 2012-03-30 Glenn Morris <rgm@gnu.org>
......
...@@ -104,6 +104,7 @@ ...@@ -104,6 +104,7 @@
(eval-when-compile (require 'cl)) (eval-when-compile (require 'cl))
(require 'ring) (require 'ring)
(require 'ansi-color) (require 'ansi-color)
(require 'regexp-opt) ;For regexp-opt-charset.
;; Buffer Local Variables: ;; Buffer Local Variables:
;;============================================================================ ;;============================================================================
...@@ -3000,26 +3001,62 @@ interpreter (e.g., the percent notation of cmd.exe on Windows)." ...@@ -3000,26 +3001,62 @@ interpreter (e.g., the percent notation of cmd.exe on Windows)."
See `comint-word'." See `comint-word'."
(comint-word comint-file-name-chars)) (comint-word comint-file-name-chars))
(defun comint--unquote&expand-filename (filename) (defun comint--unquote&requote-argument (qstr &optional upos)
;; FIXME: The code below does unquote-then-expand which means that "\\$HOME" (unless upos (setq upos 0))
;; gets expanded to the same as "$HOME" (let* ((qpos 0)
(comint-substitute-in-file-name (dquotes nil)
(comint-unquote-filename filename))) (ustrs '())
(re (concat
"[\"']\\|\\\\\\(.\\)"
"\\|\\$\\(?:\\([[:alpha:]][[:alnum:]]*\\)"
"\\|{\\(?2:[^{}]+\\)}\\)"
(when (memq system-type '(ms-dos windows-nt))
"\\|%\\(?2:[^\\\\/]*\\)%")))
(qupos nil)
(push (lambda (str end)
(push str ustrs)
(setq upos (- upos (length str)))
(unless (or qupos (> upos 0))
(setq qupos (if (< end 0) (- end) (+ upos end))))))
match)
(while (setq match (string-match re qstr qpos))
(funcall push (substring qstr qpos match) match)
(cond
((match-beginning 1) (funcall push (match-string 1 qstr) (match-end 0)))
((match-beginning 2) (funcall push (getenv (match-string 2 qstr))
(- (match-end 0))))
((eq (aref qstr match) ?\") (setq dquotes (not dquotes)))
((eq (aref qstr match) ?\')
(cond
(dquotes (funcall push "'" (match-end 0)))
((< match (1+ (length qstr)))
(let ((end (string-match "'" qstr (1+ match))))
(funcall push (substring qstr (1+ match) end)
(or end (length qstr)))))
(t nil)))
(t (error "Unexpected case in comint--unquote&requote-argument!")))
(setq qpos (match-end 0)))
(funcall push (substring qstr qpos) (length qstr))
(list (mapconcat #'identity (nreverse ustrs) "")
qupos #'comint-quote-filename)))
(defun comint--unquote-argument (str)
(car (comint--unquote&requote-argument str)))
(define-obsolete-function-alias 'comint--unquote&expand-filename
#'comint--unquote-argument "24.2")
(defun comint-match-partial-filename () (defun comint-match-partial-filename ()
"Return the unquoted&expanded filename at point, or nil if none is found. "Return the unquoted&expanded filename at point, or nil if none is found.
Environment variables are substituted. See `comint-word'." Environment variables are substituted. See `comint-word'."
(let ((filename (comint--match-partial-filename))) (let ((filename (comint--match-partial-filename)))
(and filename (comint--unquote&expand-filename filename)))) (and filename (comint--unquote-argument filename))))
(defun comint-quote-filename (filename) (defun comint-quote-filename (filename)
"Return FILENAME with magic characters quoted. "Return FILENAME with magic characters quoted.
Magic characters are those in `comint-file-name-quote-list'." Magic characters are those in `comint-file-name-quote-list'."
(if (null comint-file-name-quote-list) (if (null comint-file-name-quote-list)
filename filename
(let ((regexp (let ((regexp (regexp-opt-charset comint-file-name-quote-list)))
(format "[%s]"
(mapconcat 'char-to-string comint-file-name-quote-list ""))))
(save-match-data (save-match-data
(let ((i 0)) (let ((i 0))
(while (string-match regexp filename i) (while (string-match regexp filename i)
...@@ -3033,6 +3070,12 @@ Magic characters are those in `comint-file-name-quote-list'." ...@@ -3033,6 +3070,12 @@ Magic characters are those in `comint-file-name-quote-list'."
filename filename
(save-match-data (save-match-data
(replace-regexp-in-string "\\\\\\(.\\)" "\\1" filename t)))) (replace-regexp-in-string "\\\\\\(.\\)" "\\1" filename t))))
(make-obsolete 'comint-unquote-filename nil "24.2")
(defun comint--requote-argument (upos qstr)
;; See `completion-table-with-quoting'.
(let ((res (comint--unquote&requote-argument qstr upos)))
(cons (nth 1 res) (nth 2 res))))
(defun comint-completion-at-point () (defun comint-completion-at-point ()
(run-hook-with-args-until-success 'comint-dynamic-complete-functions)) (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
...@@ -3066,87 +3109,6 @@ Returns t if successful." ...@@ -3066,87 +3109,6 @@ Returns t if successful."
(when (comint--match-partial-filename) (when (comint--match-partial-filename)
(comint--complete-file-name-data))) (comint--complete-file-name-data)))
;; FIXME: comint--common-suffix, comint--common-quoted-suffix, and
;; comint--table-subvert don't fully solve the problem, since
;; selecting a file from *Completions* won't quote it, among several
;; other problems.
(defun comint--common-suffix (s1 s2)
(assert (not (or (string-match "\n" s1) (string-match "\n" s2))))
;; Since S2 is expected to be the "unquoted/expanded" version of S1,
;; there shouldn't be any case difference, even if the completion is
;; case-insensitive.
(let ((case-fold-search nil))
(string-match ".*?\\(.*\\)\n.*\\1\\'" (concat s1 "\n" s2))
(- (match-end 1) (match-beginning 1))))
(defun comint--common-quoted-suffix (s1 s2)
;; FIXME: Copied in pcomplete.el.
"Find the common suffix between S1 and S2 where S1 is the expanded S2.
S1 is expected to be the unquoted and expanded version of S2.
Returns (PS1 . PS2), i.e. the shortest prefixes of S1 and S2, such that
S1 = (concat PS1 SS1) and S2 = (concat PS2 SS2) and
SS1 = (unquote SS2)."
(let* ((cs (comint--common-suffix s1 s2))
(ss1 (substring s1 (- (length s1) cs)))
(qss1 (comint-quote-filename ss1))
qc s2b)
(if (and (not (equal ss1 qss1))
(setq qc (comint-quote-filename (substring ss1 0 1)))
(setq s2b (- (length s2) cs (length qc) -1))
(>= s2b 0) ;bug#11158.
(eq t (compare-strings s2 s2b (- (length s2) cs -1)
qc nil nil)))
;; The difference found is just that one char is quoted in S2
;; but not in S1, keep looking before this difference.
(comint--common-quoted-suffix
(substring s1 0 (- (length s1) cs))
(substring s2 0 s2b))
(cons (substring s1 0 (- (length s1) cs))
(substring s2 0 (- (length s2) cs))))))
(defun comint--table-subvert (table s1 s2 &optional quote-fun unquote-fun)
"Completion table that replaces the prefix S1 with S2 in STRING.
The result is a completion table which completes strings of the
form (concat S1 S) in the same way as TABLE completes strings of
the form (concat S2 S)."
(lambda (string pred action)
(let* ((str (if (eq t (compare-strings string 0 (length s1) s1 nil nil
completion-ignore-case))
(let ((rest (substring string (length s1))))
(concat s2 (if unquote-fun
(funcall unquote-fun rest) rest)))))
(res (if str (complete-with-action action table str pred))))
(when res
(cond
((and (eq (car-safe action) 'boundaries))
(let ((beg (or (and (eq (car-safe res) 'boundaries) (cadr res)) 0)))
(list* 'boundaries
(max (length s1)
;; FIXME: Adjust because of quoting/unquoting.
(+ beg (- (length s1) (length s2))))
(and (eq (car-safe res) 'boundaries) (cddr res)))))
((stringp res)
(if (eq t (compare-strings res 0 (length s2) s2 nil nil
completion-ignore-case))
(let ((rest (substring res (length s2))))
(concat s1 (if quote-fun (funcall quote-fun rest) rest)))))
((eq action t)
(let ((bounds (completion-boundaries str table pred "")))
(if (>= (car bounds) (length s2))
(if quote-fun (mapcar quote-fun res) res)
(let ((re (concat "\\`"
(regexp-quote (substring s2 (car bounds))))))
(delq nil
(mapcar (lambda (c)
(if (string-match re c)
(let ((str (substring c (match-end 0))))
(if quote-fun
(funcall quote-fun str) str))))
res))))))
;; E.g. action=nil and it's the only completion.
(res))))))
(defun comint-completion-file-name-table (string pred action) (defun comint-completion-file-name-table (string pred action)
(if (not (file-name-absolute-p string)) (if (not (file-name-absolute-p string))
(completion-file-name-table string pred action) (completion-file-name-table string pred action)
...@@ -3165,6 +3127,13 @@ the form (concat S2 S)." ...@@ -3165,6 +3127,13 @@ the form (concat S2 S)."
res))) res)))
(t (completion-file-name-table string pred action))))) (t (completion-file-name-table string pred action)))))
(defvar comint-unquote-function #'comint--unquote-argument
"Function to use for completion of quoted data.
See `completion-table-with-quoting' and `comint-requote-function'.")
(defvar comint-requote-function #'comint--requote-argument
"Function to use for completion of quoted data.
See `completion-table-with-quoting' and `comint-requote-function'.")
(defun comint--complete-file-name-data () (defun comint--complete-file-name-data ()
"Return the completion data for file name at point." "Return the completion data for file name at point."
(let* ((filesuffix (cond ((not comint-completion-addsuffix) "") (let* ((filesuffix (cond ((not comint-completion-addsuffix) "")
...@@ -3175,14 +3144,11 @@ the form (concat S2 S)." ...@@ -3175,14 +3144,11 @@ the form (concat S2 S)."
(filename (comint--match-partial-filename)) (filename (comint--match-partial-filename))
(filename-beg (if filename (match-beginning 0) (point))) (filename-beg (if filename (match-beginning 0) (point)))
(filename-end (if filename (match-end 0) (point))) (filename-end (if filename (match-end 0) (point)))
(unquoted (if filename (comint--unquote&expand-filename filename) ""))
(table (table
(let ((prefixes (comint--common-quoted-suffix (completion-table-with-quoting
unquoted filename))) #'comint-completion-file-name-table
(comint--table-subvert comint-unquote-function
#'comint-completion-file-name-table comint-requote-function)))
(cdr prefixes) (car prefixes)
#'comint-quote-filename #'comint-unquote-filename))))
(nconc (nconc
(list (list
filename-beg filename-end filename-beg filename-end
......
...@@ -1340,20 +1340,6 @@ which may actually result in an URL rather than a filename." ...@@ -1340,20 +1340,6 @@ which may actually result in an URL rather than a filename."
;; We must inform complete about whether our completion function ;; We must inform complete about whether our completion function
;; will do filename style completion. ;; will do filename style completion.
(defun ffap-complete-as-file-p ()
;; Will `minibuffer-completion-table' complete the minibuffer
;; contents as a filename? Assumes the minibuffer is current.
;; Note: t and non-nil mean somewhat different reasons.
(if (eq minibuffer-completion-table 'ffap-read-file-or-url-internal)
(not (ffap-url-p (buffer-string))) ; t
(and minibuffer-completing-file-name '(t)))) ;list
(and
(featurep 'complete)
(if (boundp 'PC-completion-as-file-name-predicate)
;; modern version of complete.el, just set the variable:
(setq PC-completion-as-file-name-predicate 'ffap-complete-as-file-p)))
;;; Highlighting (`ffap-highlight'): ;;; Highlighting (`ffap-highlight'):
;; ;;
......
This diff is collapsed.
...@@ -732,8 +732,7 @@ See Info node `(elisp) Programmed Completion' for details." ...@@ -732,8 +732,7 @@ See Info node `(elisp) Programmed Completion' for details."
;; Shush compiler. ;; Shush compiler.
(mh-do-in-xemacs (mh-do-in-xemacs
(defvar completion-root-regexp) (defvar completion-root-regexp))
(defvar minibuffer-completing-file-name))
(defun mh-folder-completing-read (prompt default allow-root-folder-flag) (defun mh-folder-completing-read (prompt default allow-root-folder-flag)
"Read folder name with PROMPT and default result DEFAULT. "Read folder name with PROMPT and default result DEFAULT.
......
This diff is collapsed.
...@@ -205,8 +205,8 @@ Includes files as well as host names followed by a colon." ...@@ -205,8 +205,8 @@ Includes files as well as host names followed by a colon."
;; Avoid connecting to the remote host when we're ;; Avoid connecting to the remote host when we're
;; only completing the host name. ;; only completing the host name.
(list string) (list string)
(comint--table-subvert (pcomplete-all-entries) (completion-table-subvert (pcomplete-all-entries)
"" "/ssh:"))) "" "/ssh:")))
((string-match "/" string) ; Local file name. ((string-match "/" string) ; Local file name.
(pcomplete-all-entries)) (pcomplete-all-entries))
(t ;Host name or local file name. (t ;Host name or local file name.
......
...@@ -165,22 +165,8 @@ A non-nil value is useful if `pcomplete-autolist' is non-nil too." ...@@ -165,22 +165,8 @@ A non-nil value is useful if `pcomplete-autolist' is non-nil too."
:type 'boolean :type 'boolean
:group 'pcomplete) :group 'pcomplete)
(defcustom pcomplete-arg-quote-list nil (define-obsolete-variable-alias
"List of characters to quote when completing an argument." 'pcomplete-arg-quote-list 'comint-file-name-quote-list "24.2")
:type '(choice (repeat character)
(const :tag "Don't quote" nil))
:group 'pcomplete)
(defcustom pcomplete-quote-arg-hook nil
"A hook which is run to quote a character within a filename.
Each function is passed both the filename to be quoted, and the index
to be considered. If the function wishes to provide an alternate
quoted form, it need only return the replacement string. If no
function provides a replacement, quoting shall proceed as normal,
using a backslash to quote any character which is a member of
`pcomplete-arg-quote-list'."
:type 'hook
:group 'pcomplete)
(defcustom pcomplete-man-function 'man (defcustom pcomplete-man-function 'man
"A function to that will be called to display a manual page. "A function to that will be called to display a manual page.
...@@ -370,48 +356,28 @@ modified to be an empty string, or the desired separation string." ...@@ -370,48 +356,28 @@ modified to be an empty string, or the desired separation string."
;; it pretty much impossible to have completion other than ;; it pretty much impossible to have completion other than
;; prefix-completion. ;; prefix-completion.
;; ;;
;; pcomplete--common-quoted-suffix and comint--table-subvert try to ;; pcomplete--common-suffix and completion-table-subvert try to work around
;; work around this difficulty with heuristics, but it's ;; this difficulty with heuristics, but it's really a hack.
;; really a hack.
(defvar pcomplete-unquote-argument-function #'comint--unquote-argument)
(defvar pcomplete-unquote-argument-function nil)
(defsubst pcomplete-unquote-argument (s)
(defun pcomplete-unquote-argument (s) (funcall pcomplete-unquote-argument-function s))
(cond
(pcomplete-unquote-argument-function (defvar pcomplete-requote-argument-function #'comint--requote-argument)
(funcall pcomplete-unquote-argument-function s))
((null pcomplete-arg-quote-list) s) (defun pcomplete--common-suffix (s1 s2)
(t ;; Since S2 is expected to be the "unquoted/expanded" version of S1,
(replace-regexp-in-string "\\\\\\(.\\)" "\\1" s t)))) ;; there shouldn't be any case difference, even if the completion is
;; case-insensitive.
(defun pcomplete--common-quoted-suffix (s1 s2) (let ((case-fold-search nil))
;; FIXME: Copied in comint.el. (string-match
"Find the common suffix between S1 and S2 where S1 is the expanded S2. ;; \x3FFF7F is just an arbitrary char among the ones Emacs accepts
S1 is expected to be the unquoted and expanded version of S2. ;; that hopefully will never appear in normal text.
Returns (PS1 . PS2), i.e. the shortest prefixes of S1 and S2, such that "\\(?:.\\|\n\\)*?\\(\\(?:.\\|\n\\)*\\)\x3FFF7F\\(?:.\\|\n\\)*\\1\\'"
S1 = (concat PS1 SS1) and S2 = (concat PS2 SS2) and (concat s1 "\x3FFF7F" s2))
SS1 = (unquote SS2)." (- (match-end 1) (match-beginning 1))))
(let* ((cs (comint--common-suffix s1 s2))
(ss1 (substring s1 (- (length s1) cs)))
(qss1 (pcomplete-quote-argument ss1))
qc s2b)
(if (and (not (equal ss1 qss1))
(setq qc (pcomplete-quote-argument (substring ss1 0 1)))
(setq s2b (- (length s2) cs (length qc) -1))
(>= s2b 0) ;bug#11158.
(eq t (compare-strings s2 s2b (- (length s2) cs -1)
qc nil nil)))
;; The difference found is just that one char is quoted in S2
;; but not in S1, keep looking before this difference.
(pcomplete--common-quoted-suffix
(substring s1 0 (- (length s1) cs))
(substring s2 0 s2b))
(cons (substring s1 0 (- (length s1) cs))
(substring s2 0 (- (length s2) cs))))))
;; I don't think such commands are usable before first setting up buffer-local
;; variables to parse args, so there's no point autoloading it.
;; ;;;###autoload
(defun pcomplete-completions-at-point () (defun pcomplete-completions-at-point ()
"Provide standard completion using pcomplete's completion tables. "Provide standard completion using pcomplete's completion tables.
Same as `pcomplete' but using the standard completion UI." Same as `pcomplete' but using the standard completion UI."
...@@ -442,34 +408,31 @@ Same as `pcomplete' but using the standard completion UI." ...@@ -442,34 +408,31 @@ Same as `pcomplete' but using the standard completion UI."
;; pcomplete-stub and works from the buffer's text instead, ;; pcomplete-stub and works from the buffer's text instead,
;; we need to trick minibuffer-complete, into using ;; we need to trick minibuffer-complete, into using
;; pcomplete-stub without its knowledge. To that end, we ;; pcomplete-stub without its knowledge. To that end, we
;; use comint--table-subvert to construct a completion ;; use completion-table-subvert to construct a completion