简体   繁体   English

什么是打包我的Emacs安装(包和配置)的最佳方式,以便可以快速安装到任何地方?

[英]Whats the best way to package my Emacs installation (packages and config) so that it can quickly be installed anywhere?

I generally write code by logging on to a remote machine (typically AWS). 我通常通过登录到远程计算机(通常是AWS)来编写代码。 I have a fairly big list of packages that I use and a fairly large .emacs.el. 我有一个相当大的包列表,我使用的和一个相当大的.emacs.el。 While I can quickly install emacs on nay remote machine, I am looking for a way to "package" my emacs and house it somewhere so that I can quickly install it on any machine I login to. 虽然我可以在nay远程计算机上快速安装emacs,但我正在寻找一种方法来“打包”我的emacs并将其存放在某处,以便我可以在我登录的任何计算机上快速安装它。 Whats the best way to do this? 什么是最好的方法呢?

First you would obviously bundle everything into source control (except for a private file). 首先,您显然会将所有内容捆绑到源代码控制中(私有文件除外)。 Bitbucket and Gitlab offer private repos. Bitbucket和Gitlab提供私人回购。

You can see this wiki for a way to list all the needed packages in your init file. 您可以看到此wiki ,以便列出init文件中所有需要的包。 (this is actually used by Prelude) (这实际上是Prelude使用的)

Then I see some options. 然后我看到了一些选择。

Use Cask 使用Cask

Some use Cask to manage package dependencies, some do not 有些人使用Cask来管理包依赖,有些则不然

The Cask file lists all dependencies: Cask文件列出了所有依赖项:

(depends-on "cask")
(depends-on "dash")
(depends-on "evil")

Use org-mode 使用组织模式

Some write their config in org-mode and load it with a call to org-babel, which is doable in one line in ~/.emacs.d/init.el : 有些人在org-mode中编写配置并通过调用org-babel来加载它,这在~/.emacs.d/init.el一行中是可行的:

(require 'org)
(require 'ob-tangle)
(org-babel-load-file (expand-file-name "~/.emacs.d/myemacs.org"))

Split your config in multiple files 将配置拆分为多个文件

and some split it in multiple elisp files. 有些人将它分成多个elisp文件。

Here some nice configs worth taking inspiration from: 这里有一些很好的配置值得灵感来自:

In init-elpa.el , he defines a function that takes a package in argument and installs it if it is not present: init-elpa.el ,他定义了一个函数,该函数在参数中包含一个包,如果它不存在则安装它:

 (defun require-package (package &optional min-version no-refresh)
    "Install given PACKAGE, optionally requiring MIN-VERSION.
    If NO-REFRESH is non-nil, the available package lists will not be
     re-downloaded in order to locate PACKAGE."
  (if (package-installed-p package min-version)
  t
  (if (or (assoc package package-archive-contents) no-refresh)
  (package-install package)
  (progn
  (package-refresh-contents)
  (require-package package min-version t)))))

and in every file, he uses: 在每个文件中,他使用:

(require-package 'dired+)

Also commit the installed packages 还提交已安装的软件包

And for your config to install quicker, you may add the installed packages into source control too. 为了使您的配置更快安装,您也可以将已安装的软件包添加到源代码管理中。 That way you can also ensure to have identical environments. 这样,您还可以确保拥有相同的环境。

I always recommend putting the entire ~/.emacs.d under version control, including all packages and other libraries. 我总是建议将整个 ~/.emacs.d置于版本控制之下,包括所有包和其他库。

It's a bit more hassle, and maybe a bit messier, but if you want to guarantee the state of the configuration every time you install it somewhere new, you need to have a complete copy. 这有点麻烦,也许有点麻烦,但如果你想保证配置的状态,每次你在新的地方安装它,你需要有一个完整的副本。

Using version control is my firm preference, because that makes it trivial to revert changes to packages, etc. So if you upgrade a package and Emacs breaks, it's a single step to put things back they way they were (and doing so doesn't require you to remember how they were). 使用版本控制是我的公司偏好,因为这使得恢复包等更改变得微不足道。因此,如果你升级包并且Emacs中断,那么将它们放回原处就是一步(并且这样做不会要求你记住他们是怎么回事。

With this approach the act of cloning a single repository is all that is required to obtain a working system in a known state; 使用这种方法,克隆单个存储库的行为就是获得已知状态的工作系统所需的全部操作; and it limits your dependence upon the availability, consistency, and permanence of remote sources to just that one repository (and if you have it locally, or even carry a copy with you, you have no remote dependencies at all). 并且它限制了您对远程源的可用性,一致性和持久性的依赖,只有一个存储库(如果您在本地拥有它,或者甚至随身携带一个副本,则根本没有远程依赖项)。

That said, lots of people don't bother and don't experience any issues, so it's not a critical point for most people. 也就是说,很多人不打扰也不会遇到任何问题,所以对大多数人来说这不是一个关键点。

It would be helpful if you clarified a little more what you mean by "any" computer. 如果您通过“任何”计算机澄清一点你的意思,那将会很有帮助。 It sounds like emacs already installed on the machine and you just want to configure emacs to use your packages and settings. 听起来好像emacs已经安装在机器上,你只想配置emacs来使用你的软件包和设置。 Do you have physical access to the machine or network from which you could load files from a memory stick? 您是否可以物理访问可以从记忆棒加载文件的机器或网络? If not, can you access cloud storage? 如果没有,您可以访问云存储吗?

My own setup looks like this: 我自己的设置如下:

I have a Windows 7 machine at work and Linux Mint at home. 我有一台Windows 7机器在工作,而Linux Mint在家。 I have a dropbox account that holds all my emacs configuration files and packages. 我有一个Dropbox帐户,可以保存我所有的emacs配置文件和包。 This dropbox account is synchronized to a local folder on each machine and my .emacs file on each computer is only one line: (load-file "~/Dropbox/dotemacs.el") I often tweak package files and configurations. 此保管箱帐户同步到每台计算机上的本地文件夹,每台计算机上的.emacs文件只有一行:(load-file“〜/ Dropbox / dotemacs.el”)我经常调整包文件和配置。 Using dropbox keeps my settings synchronized across all computers. 使用Dropbox可以在所有计算机上同步我的设置。

If you can't install Dropbox, you could manually sync to cloud storage like git. 如果您无法安装Dropbox,您可以像git一样手动同步到云存储。

check https://github.com/redguardtoo/elpa-mirror , 检查https://github.com/redguardtoo/elpa-mirror

create your own repository on a usb memory stick, it's stable because all the package versions are the version you are already using for a very long time. 在USB记忆棒上创建自己的存储库,它很稳定,因为所有软件包版本都是您已经使用很长时间的版本。

That's the quickest way, basically you can get your setup on any machine in 1 min. 这是最快捷的方式,基本上你可以在1分钟内在任何机器上进行设置。

As the README for my repo emacs for rails devs says it is as easy as pushing your ~/.emacs.d contents to github and on the target machine: 因为我的repo emacs for rails devs的README说它就像把你的~/.emacs.d内容推送到github和目标机器一样简单:

  1. Install emacs using homebrew (chances are you are on OS X) brew install emacs --HEAD --use-git-head --cocoa --srgb 使用自制软件安装emacs(你可能在OS X上) brew install emacs --HEAD --use-git-head --cocoa --srgb
  2. Git clone your repo to ~/.emacs.d/ Git克隆你的回购〜/ .emacs.d /
  3. Boot emacs 启动emacs

If there is magic, it's using the built in package manager with ELPA and marmalade and having that check to see if packages are installed and if not, install them. 如果有魔法,它会使用带有ELPA和橘子酱的内置包管理器,并检查是否安装了包,如果没有,请安装它们。

Works for me and my boxes & servers. 适用于我和我的盒子和服务器。

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

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