From fdadeb4997504f17682f164a906ac9c024816e0d Mon Sep 17 00:00:00 2001 From: Jarek Czekalski Date: Fri, 27 Dec 2013 21:58:21 +0100 Subject: [PATCH] Shell completion for filenames from current directory, related docs. * lisp/shell.el Shell completion now matches executable filenames from the current buffer's directory, on systems in which this behaviour is the default (windows-nt, ms-dos). * src/callproc.c (Vexec_path): Document that exec-directory is in it. * doc/emacs/mini.texi (Completion Options): Add a link to Shell Options. * doc/emacs/misc.texi (Shell Mode): Move documentation of shell-completion-fignore from Shell Mode to Shell Options. Fixes: debbugs:15461 --- doc/emacs/ChangeLog | 6 ++++++ doc/emacs/mini.texi | 3 +++ doc/emacs/misc.texi | 25 ++++++++++++++++--------- lisp/ChangeLog | 6 ++++++ lisp/shell.el | 11 +++++++---- src/ChangeLog | 4 ++++ src/callproc.c | 6 +++++- 7 files changed, 47 insertions(+), 14 deletions(-) diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index c9e6682aeaa..935ddf39272 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,3 +1,9 @@ +2013-12-27 Jarek Czekalski + + * mini.texi (Completion Options): Add a link to Shell Options. + * misc.texi (Shell Mode): Move documentation of + shell-completion-fignore from Shell Mode to Shell Options. + 2013-12-26 João Távora * emacs.texi (Matching): Describe new features of Electric Pair mode. diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index f3fab686ed9..33e0b142d55 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi @@ -550,6 +550,9 @@ previous example, @samp{foo.e} completes to @samp{foo.elc}. Emacs disregards @code{completion-ignored-extensions} when showing completion alternatives in the completion list. + Shell completion is an extended version of filename completion, +@pxref{Shell Options}. + @vindex completion-auto-help If @code{completion-auto-help} is set to @code{nil}, the completion commands never display the completion list buffer; you must type diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index a773ec022de..7fd35e7fd5a 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -677,20 +677,13 @@ in the shell buffer to submit the current line as input. @item @key{TAB} @kindex TAB @r{(Shell mode)} @findex completion-at-point +@cindex shell completion Complete the command name or file name before point in the shell buffer (@code{completion-at-point}). This uses the usual Emacs completion rules (@pxref{Completion}), with the completion alternatives being file names, environment variable names, the shell command history, and history references (@pxref{History References}). - -@vindex shell-completion-fignore -@vindex comint-completion-fignore -The variable @code{shell-completion-fignore} specifies a list of file -name extensions to ignore in Shell mode completion. The default -setting is @code{nil}, but some users prefer @code{("~" "#" "%")} to -ignore file names ending in @samp{~}, @samp{#} or @samp{%}. Other -related Comint modes use the variable @code{comint-completion-fignore} -instead. +For options controlling the completion, @pxref{Shell Options}. @item M-? @kindex M-? @r{(Shell mode)} @@ -1179,6 +1172,20 @@ the possible completions whenever completion is not exact. If you set @code{shell-completion-execonly} to @code{nil}, it considers nonexecutable files as well. +@vindex shell-completion-fignore +@vindex comint-completion-fignore +The variable @code{shell-completion-fignore} specifies a list of file +name extensions to ignore in Shell mode completion. The default +setting is @code{nil}, but some users prefer @code{("~" "#" "%")} to +ignore file names ending in @samp{~}, @samp{#} or @samp{%}. Other +related Comint modes use the variable @code{comint-completion-fignore} +instead. + +@findex shell-dynamic-complete-command +Some implementation details of the shell command completion may also be found +in the lisp documentation of the @code{shell-dynamic-complete-command} +function. + @findex shell-pushd-tohome @findex shell-pushd-dextract @findex shell-pushd-dunique diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b93d9ff4e98..988322d4f40 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-12-27 Jarek Czekalski + + * shell.el Shell completion now matches executable filenames from + the current buffer's directory, on systems in which this behaviour + is the default (windows-nt, ms-dos). + 2013-12-27 Glenn Morris * emacs-lisp/lisp-mode.el (lisp-mode-variables): Unbreak bootstrap. diff --git a/lisp/shell.el b/lisp/shell.el index 2047543f288..6e1b46aeeec 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -1108,12 +1108,13 @@ See `shell-command-regexp'." (defun shell-dynamic-complete-command () "Dynamically complete the command at point. This function is similar to `comint-dynamic-complete-filename', except that it -searches `exec-path' (minus the trailing Emacs library path) for completion +searches `exec-path' (minus trailing `exec-directory') for completion candidates. Note that this may not be the same as the shell's idea of the path. -Completion is dependent on the value of `shell-completion-execonly', plus -those that effect file completion. +Completion is dependent on the value of `shell-completion-execonly', +`shell-completion-fignore', plus those that affect file completion. See Info +node `Shell Options'. Returns t if successful." (interactive) @@ -1138,7 +1139,9 @@ Returns t if successful." (start (if (zerop (length filename)) (point) (match-beginning 0))) (end (if (zerop (length filename)) (point) (match-end 0))) (filenondir (file-name-nondirectory filename)) - (path-dirs (cdr (reverse exec-path))) ;FIXME: Why `cdr'? + ; why cdr? see `shell-dynamic-complete-command' + (path-dirs (append (cdr (reverse exec-path)) + (if (memq system-type '(windows-nt ms-dos)) '(".")))) (cwd (file-name-as-directory (expand-file-name default-directory))) (ignored-extensions (and comint-completion-fignore diff --git a/src/ChangeLog b/src/ChangeLog index 7f69572dc01..606ac9a6430 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2013-12-27 Jarek Czekalski + + * callproc.c (Vexec_path): Document that exec-directory is in it. + 2013-12-27 Steve Purcell (tiny change) * nsterm.m (syms_of_nsterm): Enable ns-use-srgb-colorspace by diff --git a/src/callproc.c b/src/callproc.c index 3b383a7fbef..9a9b57bd923 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1686,7 +1686,11 @@ default if SHELL is not set. */); DEFVAR_LISP ("exec-path", Vexec_path, doc: /* List of directories to search programs to run in subprocesses. -Each element is a string (directory name) or nil (try default directory). */); +Each element is a string (directory name) or nil (try default directory). + +By default the last element of this list is `exec-directory'. The +last element is not always used, for example in shell completion +(`shell-dynamic-complete-command'). */); DEFVAR_LISP ("exec-suffixes", Vexec_suffixes, doc: /* List of suffixes to try to find executable file names. -- 2.39.2