简体   繁体   English

如何使用不同的配置启动emacs

[英]How to start up emacs with different configurations

I often come across the following popular emacs builds: 我经常遇到以下流行的emacs构建:

Currently I'm running a custom configuration, but I'd like to experiment with these builds without clobbering my current ~/.emacs.d . 目前,我正在运行自定义配置,但我想尝试使用这些版本,而不会破坏我当前的~/.emacs.d

Here's some background on my current installation: 这是我当前安装的一些背景:

I installed Emacs via Homebrew, so it's located here: /usr/local/Cellar/emacs/HEAD/Emacs.app My current version of emacs is: GNU Emacs 24.3.50.1 (i386-apple-darwin13.0.0, NS apple-appkit-1265.00) 我通过Homebrew安装了Emacs,因此它位于以下位置: /usr/local/Cellar/emacs/HEAD/Emacs.app我当前的emacs版本是: GNU Emacs 24.3.50.1 (i386-apple-darwin13.0.0, NS apple-appkit-1265.00)

Basically, here's what I'd like to know: 基本上,这是我想知道的:

  1. What's the easiest way to switch between these builds as well as my current custom configuration? 在这些版本以及当前的自定义配置之间切换的最简单方法是什么?

  2. Given my current setup, is it possible to start multiple emacs sessions, each with their respective configuration/buffers? 根据我当前的设置,是否可以启动多个emacs会话,每个会话都有各自的配置/缓冲区?

You can symlink ~/.emacs.d , this is what I do 您可以符号链接~/.emacs.d ,这就是我所做的

1) Try to keep my emacs configuration ~/.emacs.d oriented ie all the config files should live in that folder. 1)尝试保持我的emacs配置~/.emacs.d定向,即所有配置文件都应位于该文件夹中。 For example I use workgroups2 , by default it stores workgroup configuration in ~/.emacs_workgroups but I have configured it to store configuration in ~/.emacs.d/workgroups , so my entire emacs configuration is in just one folder. 例如,我使用workgroups2 ,默认情况下它将工作组配置存储在~/.emacs_workgroups但是我已将其配置为将配置存储在~/.emacs.d/workgroups ,因此我的整个emacs配置都位于一个文件夹中。

2) Then I have an ~/emacs_configs folder where all config folders (basically a folder with a init.el and rest of the configuration) live, so my personal config folder will be ~/emacs_configs/iqbal , a prelude distribution will be in ~/emacs_configs/prelude 2)然后我有一个~/emacs_configs文件夹,其中所有配置文件夹 (基本上是一个带有init.el且其余配置的文件夹)都存在,因此我的个人配置文件夹将为~/emacs_configs/iqbal ,一个前奏分布在~/emacs_configs/prelude

3) Then finally I symlink ~/.emacs.d to the configuration I actually want to use, eg. 3)然后最后我将~/.emacs.d符号链接到我实际要使用的配置,例如。 to use my configuration I will do ln -s ~/emacs_configs/iqbal .emacs.d . 要使用我的配置,我将使用ln -s ~/emacs_configs/iqbal .emacs.d If you want to tryout some configuration just copy the configuration folder to ~/emacs_configs/whatever_name and change the symlink 如果要尝试一些配置,只需将配置文件夹复制到~/emacs_configs/whatever_name并更改符号链接

Hope this helps 希望这可以帮助

( Edit: I've wrapped this approach up into a shell script which I've added to the EmacsWiki .) 编辑:我已经将这种方法包装到一个外壳脚本中,该脚本已添加到EmacsWiki中 。)

I'd be inclined to use the $HOME environment variable: 我倾向于使用$HOME环境变量:

  1. Firstly copy the 'distribution' (for want of a better term) into a sub-directory .emacs.d of a directory which will serve as the replacement $HOME for that distribution. 首先,将“发行版”(为了更好的用词)复制到目录的子目录.emacs.d ,该子目录将用作该发行版的替代$HOME ie /path/to/(distribution)/.emacs.d : /path/to/(distribution)/.emacs.d

     $ git clone https://github.com/bbatsov/prelude.git ~/emacs/prelude/.emacs.d $ git clone https://github.com/overtone/emacs-live.git ~/emacs/emacs-live/.emacs.d 
  2. Then you can start emacs using env to set the HOME environment variable locally for that command: 然后,您可以使用env启动emacs以在本地为该命令设置HOME环境变量:

     $ env HOME=$HOME/emacs/prelude emacs $ env HOME=$HOME/emacs/emacs-live emacs 

They shouldn't interact with each other, so you can run them together and have multiple side-by-side emacs instances, each using a different configuration. 它们不应该相互交互,因此您可以将它们一起运行,并具有多个并排的emacs实例,每个实例使用不同的配置。

I see that graphene is actually an ELPA package, so it has no init.el file and needs to be installed via the package manager; 我看到石墨烯实际上是ELPA软件包,因此它没有init.el文件,需要通过软件包管理器进行安装。 but you can still use the same technique to install it in a separate clean configuration: Simply make a similar directory structure to the others, then create an init.el file (eg ~/emacs/graphene/.emacs.d/init.el ) containing the code from the graphene installation instructions, then run emacs (eg env HOME=$HOME/emacs/graphene emacs ), and finish the remainder of the installation instructions. 但是您仍然可以使用相同的技术将其安装在单独的干净配置中:只需创建与其他目录类似的目录结构,然后创建一个init.el文件(例如~/emacs/graphene/.emacs.d/init.el )(包含来自石墨烯安装说明的代码),然后运行emacs(例如env HOME=$HOME/emacs/graphene emacs ),并完成其余的安装说明。

The down-side to this technique is that Emacs won't see all your other dot files (because it will be looking in $HOME ), and so running other processes from within Emacs won't necessarily work as normal; 这种技术的缺点是Emacs不会看到您的所有其他点文件(因为它将在$HOME查找),因此从Emacs内部运行其他进程不一定能正常工作; but that's not likely to be a huge issue if you're just experimenting, and you can always symlink or copy the bits you need. 但是,如果您只是进行实验,那么这可能不会成为一个大问题,并且您可以始终进行符号链接或复制所需的位。

You may even prefer it that way -- the benefit is that if anything in the distribution you're trialing writes files to the home directory, it's not going to clobber your real files. 您甚至可能更喜欢这种方式-好处是,如果您正在试用的发行版中的任何内容都将文件写入主目录,则不会破坏您的真实文件。

This may also be a useful approach when upgrading Emacs to a new release (if you can run both the old and the new versions side by side) as you could set up a copy of your existing config to use with the new Emacs until you're convinced everything is working, and you can edit the new config without the risk of breaking your existing one. 当将Emacs升级到新版本时(如果可以同时运行旧版本和新版本),这也可能是一种有用的方法,因为您可以设置现有配置的副本以与新Emacs一起使用,直到确信一切正常,您可以编辑新配置而不会破坏现有配置。 Or flip that around, and instead keep the original config in the new/alternate location, in case you need it as a back-up. 或将其翻转,然后将原始配置保留在新的/备用位置,以防您需要它作为备份。

I create ~/.emacs.1.d/init.el file , and give it content: 我创建~/.emacs.1.d/init.el文件,并为其提供内容:

(setq user-emacs-directory "~/.emacs.1.d/")

then , start emacs like this emacs -q -l ~/.emacs.1.d/init.el , now emacs used new configration. 然后,像这样的emacs -q -l ~/.emacs.1.d/init.el启动emacs,现在emacs使用了新的配置。

success!! 成功!!

  • -q is means skip the default configration ~/.emacs.d/init.el -q表示跳过默认配置~/.emacs.d/init.el
  • -l is means load new configration -l表示加载新配置

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

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