Emacs tramp mode - filename auto complete doesn't work

1

I am using tramp mode in Emacs to edit files over ssh. But the problem is that on remote shell I have aliased ls as "ls --color". Tramp uses ls for auto completion and it is unable to parse color coded ls output.

The solution mentioned in https://www.gnu.org/software/tramp/#Frequently-Asked-Questions is to disable coloring of output from ls by removing the alias. I do not want to do it as it is a major feature for me.

Is there are way to redefine how tramp issues ls command so that I can keep my shell configuration and still use file name completion with tramp.

Edit 1: It seems that problem is something else. I tried changing alias to 'ls --color=auto' as suggested by @chepner and then to simply 'ls'. It still doesn't work. How can I further troubleshoot the problem?

Xolve

Posted 2013-03-12T08:42:37.417

Reputation: 450

"Renaming" a standard command via alias or function is pretty much always a bad idea. Why don't you just call your coloureful ls "lc" instead? – tink – 2013-03-12T17:54:30.290

Did you try (setq tramp-debug-buffer t) (setq tramp-verbose 10)? – Old Pro – 2013-05-19T19:13:31.350

@OldPro Here is the debug output: http://pastebin.com/PZuxs1St

– Xolve – 2013-05-20T19:53:02.040

1

Hard to make sense of that. You need to put the debug statements in your .emacs file so you can see how tramp configures itself when it loads. Probably tramp is making a bad guess. It might think /home/username is a host name and be trying to connect to that host?Or maybe it's unable to run perl scripts on the target? Just guessing. See if any of the configuration options ring a bell: https://www.gnu.org/software/tramp/#Customizing-Completion

– Old Pro – 2013-05-20T21:26:00.660

Answers

0

Tramp send following Perl snippet to get file completions

\perl5 -e 'sub case {
 my $str = shift;
 if ($ARGV[2]) {
  return lc($str);
 }
 else {
  return $str;
 }
}
opendir(d, $ARGV[0]) || die("$ARGV[0]: $!\nfail\n");
@files = readdir(d); closedir(d);
foreach $f (@files) {
 if (case(substr($f, 0, length($ARGV[1]))) eq case($ARGV[1])) {
  if (-d "$ARGV[0]/$f") {
   print "$f/\n";
  }
  else {
   print "$f\n";
  }
 }
}
print "ok\n"
' /home/ '' 0

perl5 was broken on remote host because of missing library. The solution was to manually fix the broken perl5. All this thanks to Michael Albinus.

Xolve

Posted 2013-03-12T08:42:37.417

Reputation: 450

1Hey, I said maybe it was unable to run perl on the target, too. :-) – Old Pro – 2013-05-24T23:52:07.413

Yeah right! I could have given you bounty if you provided it as an answer. – Xolve – 2013-05-25T05:27:53.690

2

Redefine your alias to read

alias ls="ls --color=auto"

This way, ls only colorizes its output when it senses it is writing to the terminal. I'm not familiar with tramp, but this should be sufficient.

chepner

Posted 2013-03-12T08:42:37.417

Reputation: 5 645

Your alias doesn't matter. Well-written scripts (like tramp) bypass aliases by using full path names, e.g. /bin/ls. – Old Pro – 2013-05-19T19:40:43.750

BSD ls has an environment variables CLICOLOR and CLICOLOR_FORCE that can also affect how ls produces colored output. I'm not sure if GNU ls has anything similar (nothing in the man page, and seemingly nothing in the Texinfo manual). – chepner – 2013-05-20T12:15:16.170

0

The other thing I would do, is look in my environment if there is anything that indicates you're in "tramp mode"

Say, do:

printenv | sort > ~/notramp.txt

then in emacs/tramp-mode:

printenv | sort > ~/withtramp.txt

Diff the two env files, and see what's different.

Then, in your ~/.bashrc, you can put

if [ -z "$TRAMPFLAG" ]
then
    alias ls='ls --color=auto'
fi

Rich Homolka

Posted 2013-03-12T08:42:37.417

Reputation: 27 121

I tried your method and it doesn't same to work. Looks like its some other issue. – Xolve – 2013-03-14T09:22:23.017

0

Tramp uses sophisticated techniques to be portable across a variety of systems, but it is not foolproof. Often to provide things like remote filename completion tramp will actually run modest perl scripts on the remote host. So check to make sure you have perl 5 installed, configured, and available on the remote host.

Old Pro

Posted 2013-03-12T08:42:37.417

Reputation: 1 751