I'm working with files which are stored on a server. The structure on the server is:


In every years folder are the folders of the year, sometimes up to 1000.

Emacs 24.4 is running on a Win 7 machine. I used to map the folders of the years with letters (X:), but I'm running out of letters now, 2015 is mapped to Z:.

If I wish to open a file of the year 2015, I do: C-x C-f, delete whatever appears in the minibuffer, type Z:, followed by the first letters of the folder. Without mapping the share to Z:, I'd have to type much more: //SBS/share/path/to/somewhere/2015/

Emacs can't handle the Windows shortcuts *.lnk. Windows can't map more shares than 26.

My general idea is that I could customise the command "find file" (C-x C-f) somehow.

What I'd like to have that I just type something like C-x C-f 2015 and get in the minibuffer the line:

Find file: //SBS/share/path/to/somewhere/2015/

with the cursor on the point after the last "/" and the usual auto-complition working, so that typing foo will be completed to foo.tex, if this exists (or a folder called foo).

  • 1
    Perhaps ido-mode?
    – Dan
    Jan 8, 2015 at 20:56
  • 1
    @Dan How could that spare typing a long path? Auto-completion is definitely helpfull, but typing just 2015 would be much faster...
    – Keks Dose
    Jan 8, 2015 at 21:19
  • 1
    Bookmarks? C-x r m and C-x r b
    – phils
    Jan 8, 2015 at 21:51
  • @phils combining that with helm-bookmarks might work well for him.
    – nanny
    Jan 8, 2015 at 22:02
  • 1
    I don't understand why you aren't assigning //SBS/share/path/to/somewhere itself a letter. Or, still solving this in Windows rather than Emacs, using reparse points. Jan 8, 2015 at 22:22

3 Answers 3

  1. I'd echo the suggestion of using bookmarks.

  2. You can use environment variables (define your own, to correspond to whatever directory prefixes you want).

  3. You can define directory abbreviations, using option directory-abbrev-alist. That's what it is for. See the Emacs manual, node File Aliases.

    The doc focuses on the use of directory-abbrev-alist with symbolic links, but you can use it for any directory abbreviations.

    Vanilla Emacs does not complete your directory abbreviations, but Icicles does. (RMS gave as the reason that vanilla Emacs should not do this: "I don’t think Emacs should alter the names that the user enters."

    Here is the doc string for option directory-abbrev-alist:

    directory-abbrev-alist is a variable defined in `files.el'.
    Its value is nil
    Alist of abbreviations for file directories.
    A list of elements of the form (FROM . TO), each meaning to replace
    FROM with TO when it appears in a directory name.  This replacement is
    done when setting up the default directory of a newly visited file.
    FROM is matched against directory names anchored at the first
    character, so it should start with a "\\`", or, if directory
    names cannot have embedded newlines, with a "^".
    FROM and TO should be equivalent names, which refer to the
    same directory.  Do not use `~' in the TO strings;
    they should be ordinary absolute directory names.
    Use this feature when you have directories which you normally refer to
    via absolute symbolic links.  Make TO the name of the link, and FROM
    the name it is linked to.
    You can customize this variable.

    So as an example, you might have an entry like this in directory-abbrev-alist:

    (\`2015 . //SBS/share/path/to/somewhere/2015)

Then if you use C-x C-f 2015 TAB (in Icicles) your input of 2015 is completed to //SBS/share/path/to/somewhere/2015, and you can type more to complete to something in that directory.

And if you had an entry like this (same thing, but with a trailing /):

    (\`2015 . //SBS/share/path/to/somewhere/2015/)

Then C-x C-f 2015 TAB shows you all of the files in that directory as completion candidates.

  • 1
    I'll try bookmarks. Low effort, nothing more than I need.
    – Keks Dose
    Jan 9, 2015 at 13:19

You open these files frequently so the paths will be in history. Use C-x C-f C-r 2015 to bring the last file you opened with 2015 in it's path into the mini-buffer and use normal completion from there. Pressing C-r again will get the next to last used path with 2015, and so on.


As an alternate method you could use symbolic links in Windows 7 to map your network shares to folders (and thus spare your Drive Letters). (Source: SuperUser: How to mount a network drive to a folder )

Suppose you have folder c:\yearly\ to store the various year folders

mklink /D c:\yearly\2015 \\SBS\share\path\to\somewhere\2015

Then you can directly use: C:\yearly\2015\... as your path to access the files.

I've tested this on a desktop with a fixed access to the destination server. A laptop may run into connection issues (due to lack of availability of the folder).

Note: This will not work on WindowsXP without a third party tool. mklink was only introduced in Vista.

  • I'm on Win 7. I'm surprised mklink works with shares, I thought this worked only for local folders.
    – Keks Dose
    Jan 9, 2015 at 15:07
  • 1
    Without the /D it won't necessarily work. Hard Links /H will not work (can't share the node on another device) and Junctions /J don't behave properly when going to the network. I think that without the /D it tries to default to Junction, which is why it will fail. Jan 9, 2015 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.