[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is TAB-completion in shell not working for some commands?

From: Jonathan Oddie
Subject: Re: Why is TAB-completion in shell not working for some commands?
Date: Wed, 9 Nov 2011 18:05:40 +0000

Hi Marius,

I did a couple of experiments and I think the below works better than
my previous code:

(let ((path (shell-command-to-string ". ~/.profile; echo -n $PATH")))
  (setenv "PATH" path)
  (setq exec-path 
         (split-string-and-unquote path ":")

This makes sure to read your bash startup before echoing the PATH env
variable; I hadn't thought of that before.

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':

> 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.

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!


On 9 Nov 2011, at 17:51, Marius Hofert wrote:

> On 2011-11-09, at 18:38 , Jonathan Oddie wrote:
>> Hi Marius,
>>> 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/
>>> and not the /Applications/ (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/ 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.
>> Those two are actually the same
>> thing. /Applications/ is just the
>> executable file hidden inside the bundle. So it really does
>> depend on starting from the Terminal and picking up your PATH
>> settings.
> okay
>>> [snip]
>>> => 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?
>> 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:
>> (add-to-list 'exec-path "/some/path/here")
>> 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.
>> 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 ;-)
>> cheers,
>> Jonathan
> Okay, in the meantime, I tried something like:
> (setq exec-path (getenv "PATH"))
> but that of course failed.
> 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 :-(
> 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)
> I'll try what you suggested in your recent mail, soon.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]