简体   繁体   English

OS X上的Emacs 23 - 使用多个实例还是emacsclient?

[英]Emacs 23 on OS X - use multiple instances or emacsclient?

I wonder if anyone has any recommendations as to setup of emacs 23 on OS X. I have been using Linux/Windows for a while and there, I would just open many instances of emacs and they were self-contained - for instance, I could have two separate files in separate frames, each with their own R, Python, and/or shell running. 我想知道是否有人对OS X上的emacs 23的设置有任何建议。我已经使用Linux / Windows一段时间了,我只打开了很多emacs实例,它们是自包含的 - 例如,我可以在单独的框架中有两个单独的文件,每个文件都有自己的R,Python和/或shell运行。 I think this is frowned upon(?) - but it kept the working directory for each script file separate, which I loved. 我认为这是不赞成的(?) - 但它保持每个脚本文件的工作目录分开,我喜欢。

I understand there is some advantage to setting (server-start) in my .emacs file and calling 'emacsclient' rather than 'Emacs' is now the preferred way(?). 我知道在我的.emacs文件中设置(server-start)并调用'emacsclient'而不是'Emacs'现在是首选方式(?)有一些优点。 I found this thread which facilitates this to occur through an Applescript: Emacs 23, OS X, multi-tty and emacsclient 我发现这个线程通过Applescript促进了这一点: Emacs 23,OS X,multi-tty和emacsclient

But I wonder if this the only way to go about it - when I open two emacs instances on OS X it gives me the error: 但我想知道这是否是唯一可行的方法 - 当我在OS X上打开两个emacs实例时它会给我错误:

** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x3803, name = 'org.gnu.Emacs.ServiceProvider'

but opens a new frame allows me to edit files. 但打开一个新框架允许我编辑文件。 I understand that for vim on OS X there is something called 'mvim' which allows multiple instances of vim to be launched, but is there something similar for emacs? 据我所知,对于OS X上的vim,有一个名为'mvim'的东西允许启动多个vim实例,但是对于emacs有类似的东西吗? Sorry for the long-winded question - in summary, I guess these are the questions for which I would like to solicit your expertise: 很抱歉这个冗长的问题 - 总之,我想这些是我想征求你的专业知识的问题:

(1) Is 'emacsclient' the way of the experts, and (2) if not necessarily, is there a way to get multiple instances of emacs 23 (not just frames) running on OS X? (1)'emacsclient'是专家的方式,(2)如果不一定,是否有办法在OS X上运行多个emacs 23(不仅仅是帧)实例?

Thanks! 谢谢!

If you want multiple instances (and not frames) of emacs use the following at the terminal prompt: 如果您想要emacs的多个实例 (而不是帧),请在终端提示符处使用以下内容:

/Applications/Emacs.app/Contents/MacOS/Emacs &

(Generic form for any app) /Path_To_Application.app/Contents/MacOS/Application &

Let me answer your questions indirectly. 让我间接回答你的问题。

As you know, emacsclient provides a service, allowing users to open documents from outside Emacs in an existing Emacs. 如您所知, emacsclient提供了一项服务,允许用户在现有的 Emacs中从外部Emacs打开文档。 Is this "the way" of the experts? 这是专家的“方式”吗? Depends on the expert. 取决于专家。 I'm a heavy user of Emacs, but never use emacsclient . 我是Emacs的重度用户,但从不使用emacsclient Why? 为什么? Because I never leave Emacs in the first place. 因为我从不首先离开 Emacs。 All the shells I run are inside Emacs (using a home-brewed screen package), I read mail in Emacs, etc. There's never a reason for me to type emacsclient at a command line. 我运行的所有shell都在Emacs中(使用自制的屏幕包),我在Emacs中读过邮件等等。我从来没有理由在命令行输入emacsclient

Your usage model seems to be that you prefer having multiple Emacsen running, making it easier to keep track of which processes and files are being used together. 您的使用模式似乎是您希望运行多个Emacsen,从而更容易跟踪哪些进程和文件一起使用。 And that makes sense. 这是有道理的。 You could do it all in one Emacs if you wish, but it might take some changes in your usage model, or some customizations to help manage multiple interpreters/shells/whatever to your liking. 如果您愿意,可以在一个 Emacs中完成所有操作,但可能需要对您的使用模型进行一些更改,或者根据您的喜好帮助管理多个解释器/ shell /。

So, if you like multiple instances of Emacs running, then by all means, continue doing so. 因此,如果您喜欢运行多个Emacs实例,那么请务必继续这样做。

Regarding the second question, it appears as though having (server-start) in your .emacs is causing problems - likely because there's a conflict with two Emacsen trying to use the same port. 关于第二个问题,似乎你的.emacs中有(server-start)导致问题 - 可能是因为与两个Emacsen试图使用同一个端口发生冲突。 Check out the documentation for starting the server, and perhaps remove that line from your .emacs, and instead start the server once by using the --daemon command line option. 查看启动服务器的文档 ,或者从.emacs中删除该行,然后使用--daemon命令行选项启动服务器一次。

Then, at the command line, you have the choice of whether you want to start a new emacs (by typing emacs ) or connect to the server you started (by typing emacsclient ). 然后,在命令行中,您可以选择是否要启动新的emacs(通过键入emacs )或连接到您启动的服务器(通过键入emacsclient )。

Here's a simple shell script that will start a separate instance, raise the Emacs window and give it focus: 这是一个简单的shell脚本,它将启动一个单独的实例,引发Emacs窗口并为其提供焦点:

#!/bin/bash

/Applications/Emacs.app/Contents/MacOS/Emacs \
    --eval '(select-frame-set-input-focus (nth 0 (frame-list)))' \
    "$@"

Notes: 笔记:

  • This script makes emacs behave like the emacs on Linux that I'm used to. 这个脚本使得emacs的行为就像我以前在Linux上的emacs一样。
  • There is probably a better way than '(nth 0 (frame-list))' to identify the frame to activate, but the above script does the right thing for me. 可能有一种比'(第n 0(帧列表))'更好的方法来识别要激活的帧,但上面的脚本对我来说是正确的。
  • I do not have '(server-start)' in my .emacs file. 我的.emacs文件中没有'(server-start)'。

I have created this shell script , which will allow you to open multiple emacs instances simultaneously. 我创建了这个shell脚本 ,它允许您同时打开多个emacs实例。

To install, just copy the emacs-ide script to /usr/local/bin/ or any directory on your $PATH . 要安装,只需将emacs-ide脚本复制到/usr/local/bin/$PATH上的任何目录。

You can run multiple Emacs instances with multiple files or directories, as such: 您可以使用多个文件或目录运行多个Emacs实例,如下所示:

emacs-ide ~/Projects/project-1
emacs-ide ~/Projects/project-2

The script also sets the name of the window to match the directory (project) or file being edited. 该脚本还设置窗口的名称以匹配正在编辑的目录(项目)或文件。

I use something like this in my .emacs to only call server-start if the server isn't already running: 我在.emacs中使用类似的东西,如果服务器尚未运行,则只调用server-start:

(if (file-exists-p
 (concat (getenv "TMPDIR") "emacs"
         (number-to-string
          (user-real-uid)) "/server"))
nil (server-start))

Then a couple of changes to my .zshrc so that I can mindlessly run ec as my editor command from the shell: 然后对我的.zshrc进行了一些更改,以便我可以盲目地从shell运行ec作为我的编辑器命令:

# I use the Emacs package from emacsformacosx.com
alias emacs='open -a emacs'
alias emacsclient='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'
alias ec='emacsclient -a /Applications/Emacs.app/Contents/MacOS/Emacs'
export EDITOR='ec'

Using 运用

open -a -n /Applications/Emacs.app

failed for me with a popup "Emacs quit unexpectedly." 弹出窗口“Emacs意外退出”对我失败了。 (OS X Yosemite 10.10.3, Emacs 24.3.1 x86_64-apple-darwin) (OS X Yosemite 10.10.3,Emacs 24.3.1 x86_64-apple-darwin)

As a workaround, I installed Aquamacs as well as Emacs, so at least I can have two copies running. 作为一种解决方法,我安装了Aquamacs以及Emacs,所以至少我可以运行两个副本。

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

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