2

Perhaps I'm kind of misusing that feature – but I find desktop files rather handy to be kept with projects. Clearly, it doesn't make much sense then to store absolute paths for the files to be opened; rather, I would like paths relative to the desktop file's own folder, so I can move the entire project folder al gusto and always load the desktop file within.

Emacs has indeed no problem opening such “local desktop files”, like

(desktop-create-buffer 206
  "src/Main.hs"
  "Main"
  'haskell-mode
  ... )

However, as soon as I do desktop-save (e.g. because I added a new file to the project), all the stored paths will get changed to absolute format

(desktop-create-buffer 206
  "/home/me/right/now/the/project/is/stored/here/src/Main.hs"
  "Main"
  'haskell-mode
  ... )

It's not hard to undo this by hand or with a quick sed command, but that's quite annoying. Can I tell emacs not to store those paths in absolute format?

3

I believe you can achieve this by setting desktop-file-name-format to "local".

Here's what describe-variable says about it:

desktop-file-name-format is a variable defined in `desktop.el'.
Its value is absolute

Documentation:
Format in which desktop file names should be saved.
Possible values are:
   absolute -- Absolute file name.
   tilde    -- Relative to ~.
   local    -- Relative to directory of desktop file.

You can customize this variable.

This variable was introduced, or its default value was changed, in
version 22.1 of Emacs.

With the "local" desktop-file-name-format you just need to make sure that the desktop file is saved in the top directory of a project. One way to do this is by setting desktop-dirname using Per-Directory Local Variables.

  • Yup, that's exactly what I was looking for. – leftaroundabout Feb 15 '16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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