Platform-independent path (in LaTex and Elisp)?
I run Emacs on Win7 and Ubuntu and try to share most of my configuration via dropbox.com. I still could not figure out how to write the path to load-files or images (for example) in a platform independent way.
I mirrored my directory structure on both machines so that inside the home directory the relative path should work out. Is there a way to achieve this with a single path without if-clauses (if system ... else ...) everywhere?
I tried ~/ and it worked sometimes, sometimes not.
'home' is set on Win7, but it must be addressed as %home% on Win7 and as $HOME on ubuntu (right?).
I need a solution f开发者_如何学Pythonor:
- elisp code
- latex files (adress images, listings)
In Windows, ~
resolves to whatever the HOME environment variable is set to. I found it most useful to set HOME to C:\Users\username
(in Win 7). This means I can put my .emacs file there, and also that ~
will reference files in it when I'm opening files.
Once you do this, your elisp can refer to ~
as your home directory on either Windows or Linux.
I have a setting at the top of my .emacs the tests the OS, and sets a CONST pointing to the the root directory of the path accordingly. Then, within the configurations, I just reference the variable within my path statements. Just tested on OS X and Windows 7.
Here's some examples:
(defconst HOME_DIR
(if (eq system-type 'darwin)
(concat "/Users/" (getenv "USER"))
(concat "c:/cygwin/home/" (getenv "USER")))
"Home directory. I could rely on the HOME environment variable,
but I'm being retentive.")
(defconst EMACS_PKGS (concat HOME_DIR "/emacs-pkgs")
"Directory for the emacs pkgs and configuration files.
Default uses `HOME_DIR' as a prefix")
;; isolate customize settings
(setq custom-file (concat EMACS_PKGS "/emacs-custom.el"))
My experience with Emacs on Windows is that ~
is not at C:\Users\yourusername. For me, it's in C:\Users\rafe\AppData\Roaming. So, for the case of Emacs, if you drop files in, say, %HOME%\AppData\Roaming (or, in Windows Emacs, ~
), you'll have access to those files. That's where my .emacs was by default, at least. The path might be different on your system, so see where Emacs takes you when you try to find a file and type ~/
.
That setting might be configurable, but I've never cared enough to change it.
As for LaTeX, sadly I can't help.
For LaTeX, see: “How to add an extra searchable dir with personal style files to TeXLive, NOT under ~/Library/texmf?” on the TeX SE. It might help.
精彩评论