2

I've a problem with this statement:

(setq org-mobile-directory "~/Dropbox/MobileOrg")

It works in Linux (and maybe in OSX too), because the tilde is expanded in /home/<me>/Dropbox/MobileOrg. It doesn't in Windows, because emacs expand the tilde into C:\Users\<me>\AppData\Roaming\ while Dropbox refers to the %USERPROFILE% environmental variable, which is expanded into C:\Users\<me>\.

I already know I can use two different files depending to the OS, or introduce a condition. But I'm wondering if I can somehow avail of some variable I did not take in consideration. Any clue?

Thanks in advance.

1
  • Without testing it, what if you try: (setenv "USERPROFILE" (or (getenv "USERPROFILE") (getenv "HOME")), and then write (setq org-mobile-directory "$USERPROFILE/Dropbox/MobileOrg"). I.e. Linux doesn't have USERPROFILE variable, so setting it would have no effect on anything else, but Emacs would know to expand it to the same path as your HOME directory.
    – wvxvw
    May 11, 2017 at 3:48

2 Answers 2

2

You can set %HOME% to c:\Users\<me>\, and Emacs will then consider that your home directory. The downside is that you may have to move your .emacs to that directory too.

More information here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html

2

You could check the system type and then set a variable that holds the location of your Dropbox directory on that platform. For example:

(setq dropbox (if (eq system-type 'windows-nt)
                  (concat (file-name-as-directory (getenv "USERPROFILE"))
                          "Dropbox")
                "~/Dropbox"))

Once you've got that you can easily setup any other variables you need without them needing to know where the Dropbox actually is:

(setq org-mobile-directory (concat (file-name-as-directory dropbox)
                                   "MobileOrg"))

I use something like this to store all sorts of Emacs related stuff such bookmarks, abbreviations, and various bits of code.

Your Answer

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

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