]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/em-cmpl.el
merge trunk
[gnu-emacs] / lisp / eshell / em-cmpl.el
index 19a0f595e6fcb535622b5965c16e85167e1e7685..a67861e83a9a8b847805536751087393562b1ee5 100644 (file)
@@ -1,13 +1,15 @@
-;;; em-cmpl --- completion using the TAB key
+;;; em-cmpl.el --- completion using the TAB key
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999-2012  Free Software Foundation, Inc.
+
+;; Author: John Wiegley <johnw@gnu.org>
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
-
-(provide 'em-cmpl)
-
-(eval-when-compile (require 'esh-maint))
-
-(defgroup eshell-cmpl nil
-  "This module provides a programmable completion function bound to
-the TAB key, which allows for completing command names, file names,
-variable names, arguments, etc."
-  :tag "Argument completion"
-  :group 'eshell-module)
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -78,29 +67,46 @@ variable names, arguments, etc."
 ;; This only works well if the completion function has provided Eshell
 ;; with sufficient pointers to locate the relevant help text.
 
+;;; Code:
+
+(eval-when-compile
+  (require 'cl-lib)
+  (require 'eshell))
+(require 'esh-util)
+
+;;;###autoload
+(progn
+(defgroup eshell-cmpl nil
+  "This module provides a programmable completion function bound to
+the TAB key, which allows for completing command names, file names,
+variable names, arguments, etc."
+  :tag "Argument completion"
+  :group 'eshell-module))
+
 ;;; User Variables:
 
-(defcustom eshell-cmpl-load-hook '(eshell-cmpl-initialize)
-  "*A list of functions to run when `eshell-cmpl' is loaded."
+(defcustom eshell-cmpl-load-hook nil
+  "A list of functions to run when `eshell-cmpl' is loaded."
+  :version "24.1"                      ; removed eshell-cmpl-initialize
   :type 'hook
   :group 'eshell-cmpl)
 
 (defcustom eshell-show-lisp-completions nil
-  "*If non-nil, include Lisp functions in the command completion list.
+  "If non-nil, include Lisp functions in the command completion list.
 If this variable is nil, Lisp completion can still be done in command
 position by using M-TAB instead of TAB."
   :type 'boolean
   :group 'eshell-cmpl)
 
 (defcustom eshell-show-lisp-alternatives t
-  "*If non-nil, and no other completions found, show Lisp functions.
+  "If non-nil, and no other completions found, show Lisp functions.
 Setting this variable means nothing if `eshell-show-lisp-completions'
 is non-nil."
   :type 'boolean
   :group 'eshell-cmpl)
 
 (defcustom eshell-no-completion-during-jobs t
-  "*If non-nil, don't allow completion while a process is running."
+  "If non-nil, don't allow completion while a process is running."
   :type 'boolean
   :group 'eshell-cmpl)
 
@@ -114,13 +120,14 @@ is non-nil."
     ("CC"       . "\\.[Cc]\\([Cc]\\|[Pp][Pp]\\)?\\'")
     ("acc"      . "\\.[Cc]\\([Cc]\\|[Pp][Pp]\\)?\\'")
     ("bcc"      . "\\.[Cc]\\([Cc]\\|[Pp][Pp]\\)?\\'")
-    ("objdump"  . "\\(\\`[^.]*\\|\\.[ao]\\)\\'")
-    ("nm"       . "\\(\\`[^.]*\\|\\.[ao]\\)\\'")
+    ("readelf"  . "\\(\\`[^.]*\\|\\.\\([ao]\\|so\\)\\)\\'")
+    ("objdump"  . "\\(\\`[^.]*\\|\\.\\([ao]\\|so\\)\\)\\'")
+    ("nm"       . "\\(\\`[^.]*\\|\\.\\([ao]\\|so\\)\\)\\'")
     ("gdb"      . "\\`\\([^.]*\\|a\\.out\\)\\'")
     ("dbx"      . "\\`\\([^.]*\\|a\\.out\\)\\'")
     ("sdb"      . "\\`\\([^.]*\\|a\\.out\\)\\'")
     ("adb"      . "\\`\\([^.]*\\|a\\.out\\)\\'"))
-  "*An alist that defines simple argument type correlations.
+  "An alist that defines simple argument type correlations.
 This is provided for common commands, as a simplistic alternative
 to writing a completion function."
   :type '(repeat (cons string regexp))
@@ -132,8 +139,7 @@ to writing a completion function."
   :type (get 'pcomplete-file-ignore 'custom-type)
   :group 'eshell-cmpl)
 
-(defcustom eshell-cmpl-dir-ignore
-  (format "\\`\\(\\.\\.?\\|CVS\\)%c\\'" directory-sep-char)
+(defcustom eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\)/\\'"
   (documentation-property 'pcomplete-dir-ignore
                          'variable-documentation)
   :type (get 'pcomplete-dir-ignore 'custom-type)
@@ -151,7 +157,7 @@ to writing a completion function."
   :type (get 'pcomplete-autolist 'custom-type)
   :group 'eshell-cmpl)
 
-(defcustom eshell-cmpl-suffix-list (list directory-sep-char ?:)
+(defcustom eshell-cmpl-suffix-list (list ?/ ?:)
   (documentation-property 'pcomplete-suffix-list
                          'variable-documentation)
   :type (get 'pcomplete-suffix-list 'custom-type)
@@ -275,13 +281,11 @@ to writing a completion function."
   ;; `pcomplete-arg-quote-list' should only be set after all the
   ;; load-hooks for any other extension modules have been run, which
   ;; is true at the time `eshell-mode-hook' is run
-  (make-local-hook 'eshell-mode-hook)
   (add-hook 'eshell-mode-hook
            (function
             (lambda ()
               (set (make-local-variable 'pcomplete-arg-quote-list)
                    eshell-special-chars-outside-quoting))) nil t)
-  (make-local-hook 'pcomplete-quote-arg-hook)
   (add-hook 'pcomplete-quote-arg-hook 'eshell-quote-backslash nil t)
   (define-key eshell-mode-map [(meta tab)] 'lisp-complete-symbol)
   (define-key eshell-mode-map [(meta control ?i)] 'lisp-complete-symbol)
@@ -294,17 +298,16 @@ to writing a completion function."
   (define-key eshell-mode-map [tab] 'pcomplete)
   (define-key eshell-mode-map [(control ?i)] 'pcomplete)
   ;; jww (1999-10-19): Will this work on anything but X?
-  (if (eshell-under-xemacs-p)
+  (if (featurep 'xemacs)
       (define-key eshell-mode-map [iso-left-tab] 'pcomplete-reverse)
-    (define-key eshell-mode-map [(shift iso-lefttab)] 'pcomplete-reverse)
-    (define-key eshell-mode-map [(shift control ?i)] 'pcomplete-reverse))
+    (define-key eshell-mode-map [backtab] 'pcomplete-reverse))
   (define-key eshell-mode-map [(meta ??)] 'pcomplete-list))
 
 (defun eshell-completion-command-name ()
   "Return the command name, possibly sans globbing."
   (let ((cmd (file-name-nondirectory (pcomplete-arg 'first))))
     (setq cmd (if (and (> (length cmd) 0)
-                      (eq (aref cmd 0) ?*))
+                      (eq (aref cmd 0) eshell-explicit-command-char))
                  (substring cmd 1)
                cmd))
     (if (eshell-under-windows-p)
@@ -355,7 +358,7 @@ to writing a completion function."
            (nconc posns (list pos)))
        (setq pos (1+ pos))))
     (setq posns (cdr posns))
-    (assert (= (length args) (length posns)))
+    (cl-assert (= (length args) (length posns)))
     (let ((a args)
          (i 0)
          l final)
@@ -367,8 +370,9 @@ to writing a completion function."
       (and l
           (setq args (nthcdr (1+ l) args)
                 posns (nthcdr (1+ l) posns))))
-    (assert (= (length args) (length posns)))
-    (when (and args (eq (char-syntax (char-before end)) ? ))
+    (cl-assert (= (length args) (length posns)))
+    (when (and args (eq (char-syntax (char-before end)) ? )
+              (not (eq (char-before (1- end)) ?\\)))
       (nconc args (list ""))
       (nconc posns (list (point))))
     (cons (mapcar
@@ -379,7 +383,7 @@ to writing a completion function."
                         (let ((result
                                (eshell-do-eval
                                 (list 'eshell-commands arg) t)))
-                          (assert (eq (car result) 'quote))
+                          (cl-assert (eq (car result) 'quote))
                           (cadr result))
                       arg)))
                (if (numberp val)
@@ -394,11 +398,11 @@ to writing a completion function."
     (if (file-name-directory filename)
        (pcomplete-executables)
       (if (and (> (length filename) 0)
-              (eq (aref filename 0) ?*))
+              (eq (aref filename 0) eshell-explicit-command-char))
          (setq filename (substring filename 1)
                pcomplete-stub filename
                glob-name t))
-      (let* ((paths (split-string (getenv "PATH") path-separator))
+      (let* ((paths (eshell-parse-colon-path eshell-path-env))
             (cwd (file-name-as-directory
                   (expand-file-name default-directory)))
             (path "") (comps-in-path ())
@@ -445,6 +449,10 @@ to writing a completion function."
                        (all-completions filename obarray 'functionp))
                   completions)))))))
 
-;;; Code:
+(provide 'em-cmpl)
+
+;; Local Variables:
+;; generated-autoload-file: "esh-groups.el"
+;; End:
 
 ;;; em-cmpl.el ends here