From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jonathan Oddie Newsgroups: gmane.emacs.help Subject: Re: Why is TAB-completion in shell not working for some commands? Date: Wed, 9 Nov 2011 18:49:20 +0000 Message-ID: <3CEC37A8-B58E-4F94-98B5-25383B07082F@gmail.com> References: <8BF2824B-97AC-4722-8F2C-C572C5F558FF@gmail.com> <1E4EE682-3100-41C9-A4C5-1E537BF01647@math.ethz.ch> <1979BC10-E138-4B26-83BD-CBBBEC6F09CC@gmail.com> <0FFA3486-2A4A-4F10-8564-A9C5E176A756@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1320864584 17557 80.91.229.12 (9 Nov 2011 18:49:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 9 Nov 2011 18:49:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 09 19:49:40 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RODDP-0002zu-UD for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Nov 2011 19:49:40 +0100 Original-Received: from localhost ([::1]:39829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RODDK-0008AG-A7 for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Nov 2011 13:49:34 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:41711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RODDE-00089u-Fp for help-gnu-emacs@gnu.org; Wed, 09 Nov 2011 13:49:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RODDD-0006NA-5P for help-gnu-emacs@gnu.org; Wed, 09 Nov 2011 13:49:28 -0500 Original-Received: from mail-wy0-f169.google.com ([74.125.82.169]:34962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RODDC-0006My-UT for help-gnu-emacs@gnu.org; Wed, 09 Nov 2011 13:49:27 -0500 Original-Received: by wyg24 with SMTP id 24so2335792wyg.0 for ; Wed, 09 Nov 2011 10:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=8diGaJu7GfddL0FkdlGlWXle/sdZVJ7yA1fDrGHyi1o=; b=DHiUwFnHf+TKBX9uXbTDQR50DC989on8CTFvCZ7IJWgUs8oevSSvkkWrAmJw5oWJpR JaBsCoFziwaELk+h7MKkCy2X8WrNY6ETsSAq87lncI6SWyDZ9ZzAdV4pB7eBciO+++Cs KXLFk0OwgxlYCWZf6yjqC8n2RYgyUEaRzz7JI= Original-Received: by 10.227.204.141 with SMTP id fm13mr2834965wbb.12.1320864566027; Wed, 09 Nov 2011 10:49:26 -0800 (PST) Original-Received: from stu-40-200.magd.ox.ac.uk (stu-40-200.magd.ox.ac.uk. [129.67.40.200]) by mx.google.com with ESMTPS id em4sm6599592wbb.20.2011.11.09.10.49.21 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Nov 2011 10:49:22 -0800 (PST) In-Reply-To: <0FFA3486-2A4A-4F10-8564-A9C5E176A756@gmail.com> X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:82832 Archived-At: Hi all, One more detail about this that surprised me: the last component of `exec-path' is always ignored by tab-completion in shell-mode. I thought this was weird initially, but it's because by default the last component of `exec-path' will be a directory of executables Emacs uses internally: stuff like `vcdiff' and `movemail'. This also means one needs to be a bit careful about setting the value of `exec-path'. I wonder if there should be a note about this in the docstring either for `exec-path' or `shell-dynamic-complete-as-command'? cheers, Jonathan On 9 Nov 2011, at 18:05, Jonathan Oddie wrote: > Hi Marius, >=20 > I did a couple of experiments and I think the below works better than > my previous code: >=20 > (let ((path (shell-command-to-string ". ~/.profile; echo -n $PATH"))) > (setenv "PATH" path) > (setq exec-path=20 > (append > (split-string-and-unquote path ":") > exec-path))) >=20 > This makes sure to read your bash startup before echoing the PATH env > variable; I hadn't thought of that before. >=20 > Also, I'm pretty sure now it really is `exec-path' that makes the > difference, not the PATH environment variable itself. Here's the > docstring for `shell-dynamic-complete-command': >=20 >> This function is similar to `comint-dynamic-complete-filename', = except that it >> searches `exec-path' (minus the trailing Emacs library path) for = completion >> candidates. Note that this may not be the same as the shell's idea = of the >> path. >=20 > So as long as `exec-path' gets set correctly it *ought* to work. Let > me know if that helps, I think we must be close to the solution now! >=20 > cheers, > Jonathan >=20 >=20 >=20 > On 9 Nov 2011, at 17:51, Marius Hofert wrote: >=20 >>=20 >> On 2011-11-09, at 18:38 , Jonathan Oddie wrote: >>=20 >>>=20 >>> Hi Marius, >>>=20 >>>> 1) If I start emacs from the terminal, TAB-completion works (as = reported earlier). Now the emacs I start from the terminal is actally = (output of "which emacs"): >>>> /Applications/Emacs.app/Contents/MacOS//emacs >>>> and not the /Applications/Emacs.app (the GUI version one clicks on = in the dock). So when I started emacs from the terminal, I used Options = -> Keep in Dock to keep that in the dock instead of = /Applications/Emacs.app. Starting the former, I again did not have = TAB-completion, so it only works when (really) starting emacs from the = terminal (which is funny cause I thought I can get rid of the Mac's = terminal since I have a shell in emacs...) >>>> Don't know if that makes sense to the experts, I just wanted to = report on this. >>>=20 >>> Those two are actually the same >>> thing. /Applications/Emacs.app/Contents/MacOS/emacs is just the >>> executable file hidden inside the Emacs.app bundle. So it really = does >>> depend on starting from the Terminal and picking up your PATH >>> settings. >>=20 >> okay >>=20 >>>=20 >>>> [snip] >>>=20 >>>>=20 >>>> =3D> Clearly, the /opt-directories are missing. I haven't tried but = one might just add all directories from PATH to exec-path, but whenever = I change PATH, I have to remember to do the same for exec-path. Is there = a nicer way? >>>=20 >>> Yes, I'd try adding your /opt directories to `exec-path' first and = see if that fixes >>> the problem. You can either something like the (setq exec-path = (append ... )) solution in my last email, or the following: >>>=20 >>> (add-to-list 'exec-path "/some/path/here") >>>=20 >>> Note that you might *also* need to set the environment PATH variable >>> from within Emacs; that's the line with `mapconcat' in my prev >>> email. As I said, I forget exactly how each of these things = interacts >>> with shell-mode's tab-completion. >>>=20 >>> If that works, the nicer solution would probably involve having your >>> .emacs run a short shell script to print out and parse the value of >>> PATH set in your .bashrc (or wherever), and set PATH and `exec-path' >>> based on that. I'll try and work out a quick hack for this later = this >>> evening, if someone doesn't beat me to it ;-) >>>=20 >>> cheers, >>> Jonathan >>=20 >>=20 >> Okay, in the meantime, I tried something like: >> (setq exec-path (getenv "PATH")) >> but that of course failed. >>=20 >> I then put in: >> (setq exec-path (append exec-path '("/opt/local/bin"))); set = exec-path >> (setenv "PATH" (mapconcat 'identity exec-path ":")); set PATH >> and restarted emacs. Still no TAB-completion :-( >>=20 >> If that helps, I originally had the following to get the same PATH as = in the terminal: >> (setq explicit-bash-args (list "--login" "-i")) >> (that with the seq exec-path command above also did not work, though) >>=20 >> I'll try what you suggested in your recent mail, soon. >>=20 >>=20 >>=20 >=20