在emacs 23和emacs 24之间共享emacs配置

时间:2013-06-11 14:00:14

标签: emacs emacs23 emacs24

我正在尝试将所有emacs配置置于版本控制之下,以便在不同的计算机之间轻松切换。实际上我的首选系统是OSX(10.8.3),来自http://emacsformacosx.com/的emacs 24.3。但我也可以在其他系统中工作(更可能是基于linux的,虽然不同的发行版ubuntu / scientific-linux),它们通常都配备了emacs 23.4。我想要的是一个init文件,它检查emacs和操作系统的版本,从emacs包管理器加载所需的包。 到目前为止,我在OSX上的emacs 24.3的.emacs init文件如下

(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)

加上一些依赖于已内置软件包的东西 我承认我不知道如何开始拥有一个可以在所有设备中无差别地使用的.emacs init文件。此外,我还想有一种方法来加载基于系统配置的url-proxy-services

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

感谢您的帮助

3 个答案:

答案 0 :(得分: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 :(得分:1)

除了giornado答案之外,您还可以通过测试(require)结果,仅在包存在时评估特定于包的设置。 bbdb包的示例:

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

答案 2 :(得分: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))