tags:

views:

170

answers:

1

Hello all,

I'm trying to configure my .emacs file to work in a Windows, Linux, and Mac environment--specifically, I need it to choose the correct font and a certain directory for org-mode.

I have tried the following which loads the correct font, but does not load the path specified for org-mode:

;; On Windows
(if (eq system-type 'windows-nt)
    (set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
  (setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
  )

;; On Linux
(if (eq system-type 'gnu/linux)
    (set-default-font "Inconsolata-11")
  (setq load-path (cons "~/elisp/org-current/lisp" load-path))
  )

I have tried the following which on my Windows machine returns the error Font Inconsolata-11 is not defined, and on my Linux machine returns the error Font -outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1 is not defined. For both, the specified org path is not loaded:

;; On Windows
(if (eq system-type 'windows-nt)
    (setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
  (set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
  )

;; On Linux
(if (eq system-type 'gnu/linux)
    (setq load-path (cons "~/elisp/org-current/lisp" load-path))
  (set-default-font "Inconsolata-11")
  )

I evaluated the system-type variable in both environments, and they both evaluate correctly.

Can anyone see what's wrong--also, I'm not very versed in emacs-lisp, can you see what incorrect assumptions I'm making?

Thank you, Zachary

+1  A: 

note that if in lisp is if-then-else. so, in your first case you are doing if windows, set the font, ELSE set the loadpath for windows! then independantly, you are doin if linux setthe font, else set the loadpath for linux!

try

(if (eq system-type 'windows-nt)
    (progn
       (setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
       (set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
     )
     (progn
            (setq load-path (cons "~/elisp/org-current/lisp" load-path))
            (set-default-font "Inconsolata-11")
     )
)

this won't work on mac, or whatever, but if you're only ever using NT or linux, this should work. Otherwise you can stick the other if outside the 2nd progn...

Brian Postow
Thank you very much, Brian. I really appreciate the explanation of the `if` statements if-then-else nature. I did think it odd the way the two statements in the `if` were indented at different levels and knew it was not insignificant--it's so obvious now. I'm going for the approach of having separate `if` statements for each type, but just enclosing the the True condition in `progn()` block like you described, effectively omitting the else clause. Thanks again. Cheers!
Zachary Young
that works too. always remember, emacs doesn't do anything for no reason. if it's indenting something in a way that surprises you, you probably did something wrong B-)
Brian Postow
You can also use the `when` construct, which is like `if` but has no "else" branch. It evaluates multiple lines (as if there is an implicit `progn`), so your original example would work if you just replaced all `if` with `when`.
pheaver
You don't need the `progn` in the else clause, all forms will be evaluated
scottfrazer