4

Bookmarks in the bookmarks file appear to be saved using absolute paths. This creates conflicts resolving bookmarks in a file that is synced across different computers:

Absolute path computer 1: /user/sync/file_with_bookmark

Absolute path computer 2: C:\sync\file_with_bookmark

The absolute path of either file is used when writing to the emacs bookmarks file, which is also synced across both computers. Is there a way to save the bookmark in a way that would work on either computer? For example, perhaps the synced path for each computer could be expanded when resolving the bookmark?

Emacs 25.1

  • 1
    Have you tried using symlinks? – DoMiNeLa10 Dec 11 '16 at 22:13
2

It looks like the relevant bookmark function is bookmark-get-filename. You could advise this to expand or otherwise transform the path.

For example, add some 'filter return' advice to call expand-file-name:

 (advice-add 'bookmark-get-filename :filter-return 'expand-file-name)

Update

To be able to share a bookmarks file between systems, you need some way to map between paths. In your example it looks like you have a root 'sync' directory on each system, so you could do something like this:

(defconst sync-dir
  (if (eq system-type 'windows-nt)
      "C:/sync/"
    "/user/sync/"))

(defun sync-relative-name (file)
  (cond 
   ((file-exists-p file)
    file)
   ((string-match "^.+/sync/\\(.+\\)" file)
    (expand-file-name (match-string 1 file) sync-dir))
   (t file)))

(advice-add 'bookmark-get-filename :filter-return 'sync-relative-name)

That is:

  • Define the root path for your sync tree on each system.
  • Define a function that can take the absolute path from one system and convert it to the equivalent on the other system. Here I'm just taking everything after sync/ and using that to build a new path, relative to the local sync dir.
  • Use this function to advise `bookmark-get-filename'.
  • Yes, the two computers are unix (specifically OSX) and Windows. Could you elaborate on the solution to consolidate synced bookmarks for these two platforms? – Snelephant Dec 13 '16 at 23:25

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.