aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/shell.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/shell.el')
-rw-r--r--lisp/shell.el38
1 files changed, 36 insertions, 2 deletions
diff --git a/lisp/shell.el b/lisp/shell.el
index de811543ba0..909ebb48afc 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -383,6 +383,39 @@ to `dirtrack-mode'."
383 :group 'shell 383 :group 'shell
384 :type '(choice (const nil) regexp)) 384 :type '(choice (const nil) regexp))
385 385
386(defun shell-parse-pcomplete-arguments ()
387 "Parse whitespace separated arguments in the current region."
388 (let ((begin (save-excursion (shell-backward-command 1) (point)))
389 (end (point))
390 begins args)
391 (save-excursion
392 (goto-char begin)
393 (while (< (point) end)
394 (skip-chars-forward " \t\n")
395 (push (point) begins)
396 (let ((arg ()))
397 (while (looking-at
398 (eval-when-compile
399 (concat
400 "\\(?:[^\s\t\n\\\"']+"
401 "\\|'\\([^']*\\)'?"
402 "\\|\"\\(\\(?:[^\"\\]\\|\\\\.\\)*\\)\"?"
403 "\\|\\\\\\(\\(?:.\\|\n\\)?\\)\\)")))
404 (goto-char (match-end 0))
405 (cond
406 ((match-beginning 3) ;Backslash escape.
407 (push (if (= (match-beginning 3) (match-end 3))
408 "\\" (match-string 3))
409 arg))
410 ((match-beginning 2) ;Double quote.
411 (push (replace-regexp-in-string
412 "\\\\\\(.\\)" "\\1" (match-string 2))
413 arg))
414 ((match-beginning 1) ;Single quote.
415 (push (match-string 1) arg))
416 (t (push (match-string 0) arg))))
417 (push (mapconcat #'identity (nreverse arg) "") args)))
418 (cons (nreverse args) (nreverse begins)))))
386 419
387(defun shell-completion-vars () 420(defun shell-completion-vars ()
388 "Setup completion vars for `shell-mode' and `read-shell-command'." 421 "Setup completion vars for `shell-mode' and `read-shell-command'."
@@ -396,8 +429,9 @@ to `dirtrack-mode'."
396 (set (make-local-variable 'comint-dynamic-complete-functions) 429 (set (make-local-variable 'comint-dynamic-complete-functions)
397 shell-dynamic-complete-functions) 430 shell-dynamic-complete-functions)
398 (set (make-local-variable 'pcomplete-parse-arguments-function) 431 (set (make-local-variable 'pcomplete-parse-arguments-function)
399 ;; FIXME: This function should be moved to shell.el. 432 #'shell-parse-pcomplete-arguments)
400 #'pcomplete-parse-comint-arguments) 433 (set (make-local-variable 'pcomplete-arg-quote-list)
434 (append "\\ \t\n\r\"'`$|&;(){}[]<>#" nil))
401 (set (make-local-variable 'pcomplete-termination-string) 435 (set (make-local-variable 'pcomplete-termination-string)
402 (cond ((not comint-completion-addsuffix) "") 436 (cond ((not comint-completion-addsuffix) "")
403 ((stringp comint-completion-addsuffix) 437 ((stringp comint-completion-addsuffix)