我正在尝试将我所有的emacs配置置于版本控制之下,以便在不同的计算机之间轻松切换。实际上,我首选的系统是带有http://emacsformacosx.com/的emacs24.3的OSX (10.8.3)。但我也可以在其他系统上工作(更有可能是基于linux的,尽管不同的发行版ubuntu/scientific linux不同),它们通常都配备了emacs23.4。我想要的是一个init文件,检查emacs的版本和操作系统,从emacs包管理器加载所需的包。到目前为止,我在OSX上的emacs24.3的.emacs初始化文件如下
(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初始化文件。此外,我也希望有一种方法来加载url代理服务的基础上的系统配置
(setq url-proxy-services '(("http" . "proxy.server.com:8080")))感谢您的帮助
发布于 2013-06-11 22:09:54
相关变量为system-type和emacs-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
))发布于 2013-06-11 22:38:10
除了giornado回答,您还可以通过测试(require)结果,将特定于包的设置放在只有当包存在时才会进行评估的方式。bbdb包的示例:
(when (require 'bbdb nil t)
(progn ...put your (setq) and other stuff here... ))发布于 2013-10-17 15:38:14
对于这种情况,我在.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))等。
https://stackoverflow.com/questions/17046035
复制相似问题