2013-06-11 47 views
5

我試圖將所有emacs配置放在版本控制下,以便在不同計算機之間輕鬆切換。其實我的首選系統是OSX(10.8.3),其中emacs 24.3從http://emacsformacosx.com/。但我也可以在其他系統上工作(更可能是基於Linux的,雖然不同的發行版ubuntu/scientific-linux),這些系統一般都配有emacs 23.4。我想要的是一個init文件,它檢查emacs的版本和操作系統,從emacs package manager加載所需的軟件包。 到目前爲止,我的.emacs初始化文件的emacs的24.3 OSX上是遵循在emacs 23和emacs之間共享emacs配置24

(require 'package) 
(setq package-archives '(
    ("marmalade" . "http://marmalade-repo.org/packages/") 
    ("org" . "http://orgmode.org/elpa/") 
    ("melpa" . "http://melpa.milkbox.net/packages/"))) 
(package-initialize) 

後,有配置(單獨加載例如

(load "python-sy") 

它使用未安裝默認一些軟件包:特別

color-theme 
org-mode 
theme-changer 
ess-site 
magit 
auctex 
python.el (fgallina implementation) 

加上它依賴於已經內置包一些其他的事情 我承認我對豪不知道w開始擁有一個可以在所有設備中無差別使用的.emacs init文件。此外,我也想有一種方式來加載基於系統配置

(setq url-proxy-services '(("http" . "proxy.server.com:8080"))) 

感謝您的幫助

+0

您可以獲取Emacs 23的'package.el'版本;請按照[ELPA EmacsWiki頁面](http://www.emacswiki.org/emacs/ELPA)上的鏈接進行操作。 (如果有問題的系統升級到Emacs 24時,請確保將其移開。) – legoscia

回答

4

相關變量是system-typeemacs-major-version網址代理服務。您可以使用類似下面的

(if (>= emacs-major-version 24) 
    (progn 
     ;; Do something for Emacs 24 or later 
    ) 
    ;; Do something else for Emacs 23 or less 
) 

(cond 
((eq system-type 'windows-nt) 
    ;; Do something on Windows NT 
) 
((eq system-type 'darwind) 
    ;; Do something on MAC OS 
) 
((eq system-type 'gnu/linux) 
    ;; Do something on GNU/Linux 
) 
;; ... 
(t 
    ;; Do something in any other case 
)) 
1

隨着giornado答案,你也可以把你的包特定設置的方式,只有當包是目前通過測試(require)結果,他們將進行評估。例如與bbdb包:

(when (require 'bbdb nil t) 
    (progn ...put your (setq) and other stuff here...)) 
+0

加載後的eval是否更好?這可以稍微減少啓動時間並僅在必要時執行代碼。 – giordano

+0

親愛的佐丹奴你能否讓我使用eval-after-load? –

+2

@giordano:加載後的eval-allow只允許在加載包時執行代碼。在我的例子中,我想在啓動時加載多個軟件包,但如果packahe不存在則不會出現錯誤(我曾經在Linux,Windows和Mac主機之間共享我的'.emacs',而不是所有的每個都安裝了相同的軟件包)。 – Seki

0

對於這種情況,我在的.emacs頂部定義幾個常量:

(defconst --xemacsp (featurep 'xemacs) "Is this XEmacs?") 
(defconst --emacs24p (and (not --xemacsp) (>= emacs-major-version 24))) 
(defconst --emacs23p (and (not --xemacsp) (>= emacs-major-version 23))) 
(defconst --emacs22p (and (not --xemacsp) (>= emacs-major-version 22))) 
(defconst --emacs21p (and (not --xemacsp) (>= emacs-major-version 21))) 

用法示例:

(when --emacs24p 
    (require 'epa-file) 
    (epa-file-enable) 
    (setq epa-file-cache-passphrase-for-symmetric-encryption t) ; default is nil 
    ) 

或者:

(if --emacs22p 
     (c-toggle-auto-newline 1) 
    (c-toggle-auto-state 1))