简体   繁体   English

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

[英]share emacs configuration between emacs 23 and emacs 24

I'm trying to put all my emacs configuration under version control in order to easily switch between different computers. 我试图将所有emacs配置置于版本控制下,以便在不同的计算机之间轻松切换。 Actually my preferred system is OSX (10.8.3) with emacs 24.3 from http://emacsformacosx.com/ . 实际上,我首选的系统是来自http://emacsformacosx.com/的 OSX(10.8.3)和emacs 24.3。 But I can also work in other systems (more likely linux-based although different distribution ubuntu/scientific-linux) which generally are equipped with emacs 23.4. 但是我也可以在通常配备emacs 23.4的其他系统(更可能是基于linux的系统,尽管使用不同的ubuntu / scientific-linux)中工作。 What I would like to have is a init file which check the version of emacs and the operating system, load the needed packages from emacs package manager. 我想要的是一个初始化文件,该文件检查emacs的版本和操作系统,并从emacs软件包管理器中加载所需的软件包。 So far my .emacs init file for emacs 24.3 on OSX is as follow 到目前为止,我在OSX上的emacs 24.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)

After that there are configuration (loaded separately as for example 之后,有配置(例如,单独加载

(load "python-sy")

which uses some packages not installed as default: in particular 使用某些未默认安装的软件包:特别是

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

plus some other things which relies in already built-in packages I admit that I have no idea on how to start for having a .emacs init file which could be used indifferently in all the devices. 加上依赖于内置软件包的其他一些东西,我承认我不知道如何开始拥有一个.emacs初始化文件,该文件可以在所有设备中使用。 Furthermore I also would like to have a way to load url-proxy-services based on the system configuration 此外,我还希望有一种基于系统配置来加载url-proxy-services的方法

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

Thank you for any help 感谢您的任何帮助

Relevant variables are system-type and emacs-major-version . 相关变量是system-typeemacs-major-version You can use something like the following 您可以使用以下内容

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

Along with giornado answer, you can also put your package-specific settings in a way they will be evaluated only when the package is present by testing the (require) result. 除了giornado答案外,您还可以通过特定的方式设置特定于软件包的设置,以便仅通过测试(require)结果对存在的软件包进行评估。 Example with the bbdb package: bbdb软件包的示例:

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

For this situation I define few constants at the top of .emacs : 对于这种情况,我在.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)))

Example usage: 用法示例:

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

Or: 要么:

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

etc. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM