tags:

views:

63

answers:

2

Is there a way to give the 'find-file' function a hint?

I'm working with files in the same directory on a remote server, and I'm getting tired of typing in the machine name, and directory structure all the time. It would sure be great if I could write a function that would bring up the find-file prompt with the machine name and directory already filled in.

(Note: I use Emacs 23.1)

Thanks for your help in advance.

+1  A: 

If you're starting the 'find-file command from buffers associated with files on the remote server, the staring point should already include the directory/remote server filled in.

One way to skin this cat is to do

M-x cd /ssh:user@machine:/starting/path

note: I use tramp, and that's how find-file starts. I'd not noticed the /ssh: before today, but I don't use tramp very much any longer.

To answer your question directly, this command calls find-file with the "hint":

(defun my-remote-find-file ()
  "call 'find-file with a starting directory"
  (interactive)
  (let ((default-directory "/ssh:user@machine:/starting/path/"))
    (call-interactively 'find-file)))

Obviously customize the starting point.

One last way I can think of solving this is to do M-x dired on the remote server, and do your file finding from that point.

Trey Jackson
Thanks for your help. You've taught me a little bit more about emacs and lisp.
Kevin
A: 

Set up recentf, and when you want to open a file on the server, go through the recentf menu; if the exact file you want is not there, just open something else in the same directory, then type C-x C-f and the directory should be filled in for you.

Jouni K. Seppänen
I like this approach. It's not exactly what I'm looking for, but I'll give it a try.
Kevin