简体   繁体   English

OS X 10.6上的emacs

[英]emacs on OS X 10.6

I am a new iMac user. 我是新的iMac用户。 I have extensive experience with Linux on a PC. 我在PC上有丰富的Linux经验。 I downloaded latest version of emacs to the Applications folder. 我将最新版本的emacs下载到Applications文件夹。 I want to invoke emacs from the command line. 我想从命令行调用emacs。 However, the default path for emacs is /usr/bin/emacs. 但是,emacs的默认路径是/ usr / bin / emacs。 what is the best practice for adding the new emacs to the path? 将新emacs添加到路径的最佳做法是什么? I am tempted to create a ~/bin directory and a link to the new emacs and adding ~/bin to the beginning of my path. 我很想创建一个〜/ bin目录和一个指向新emacs的链接,并将〜/ bin添加到我的路径的开头。 This is how we did things in our software development environment on linux PC's 这就是我们在linux PC上的软件开发环境中做的事情

Best way is to use Homebrew and use 最好的方法是使用Homebrew并使用

brew install emacs --cocoa

so you have a easy to update emacs installation. 这样您就可以轻松更新emacs安装。 The Cocoa will make sure you have your mac keybinding working before emacs. Cocoa将确保您在emacs之前使用mac keybinding。 Make the binary run at startup as a daemon (because it starts up not very fast), for instance: 使二进制在启动时作为守护进程运行(因为它启动速度不是很快),例如:

 /usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs --daemon

And make an script to the emacsclient command and saved it to /bin/emacs file (don't forget to make it executable): 并为emacsclient命令创建一个脚本并将其保存到/ bin / emacs文件中(不要忘记使其可执行):

#!/bin/bash
exec /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n -c "$@"

so when you fire up at bash "emacs something.txt" the already running emacs daemon opens it instantly. 所以当你在bash“emacs something.txt”启动时,已经运行的emacs守护程序会立即打开它。 You can also extend it to open Emacs if the daemon is not running! 如果守护程序未运行,您还可以将其扩展为打开Emacs!

I tested it on the latest emacs 23.2, some features are not present on early versions. 我在最新的emacs 23.2上测试了它,早期版本中没有一些功能。

Assuming you were still in linux land, wouldn't the canonical place to put this be in /usr/local/bin (and add that to your path?) ... I'd stick with that, if you were to go that route, but this is how I have my emacs setup: 假设你还在Linux的土地上,那么这个规范的地方不会放在/usr/local/bin (并将其添加到你的路径中吗?)...我会坚持下去,如果你去那个路线,但这就是我设置emacs的方式:

  1. I've downloaded the latest plain/vanilla Emacs from emacsforosx.com 我从emacsforosx.com下载了最新的普通/香草Emacs
  2. I've made an emacs alias that I use to fire up a terminal-based version of emacs when I don't want (or can't) run the GUI version, like so: 我做了一个emacs别名,当我不想(或不能)运行GUI版本时,我用它来启动基于终端的emacs版本,如下所示:

    alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'

  3. If you want to fire up the GUI version of Emacs from the terminal, you can just type the following (which, AFAIK, is a mac-ism, so you wouldn't have known that coming from linux): 如果你想从终端启动Emacs的GUI版本,你可以输入以下内容(其中,AFAIK,是一个mac-ism,所以你不会知道它来自linux):

    $ open -a Emacs

There's a slew of information about emacs on OS X at the emacs wiki . emacs wiki 上有关于OS X上的emacs的大量信息。

~/bin or /usr/local/bin will work fine, as will manipulating your PATH . ~/bin/usr/local/bin将正常工作,操作PATH

Assuming you're using Emacs.app, simplest thing to do is to use open -a /Applications/Emacs.app "$@" . 假设您正在使用Emacs.app,最简单的方法是使用open -a /Applications/Emacs.app "$@" open is the command line equivalent of double-clicking on something in Finder. open是命令行,相当于双击Finder中的某些内容。 Put that into a shell script, stick it into your PATH and go. 将它放入shell脚本中,将其粘贴到PATH中然后继续。

Installing emacs-app via MacPorts is probably the simplest way to get and maintain a Cocoa emacs. 通过MacPorts安装emacs-app可能是获取和维护Cocoa emacs的最简单方法。

You may wish to look into Aquamacs which is a further refinement of emacs for OS X. The emacs wiki page on Aquamacs is very helpful. 您可能希望查看Aquamacs ,这是OS X的emacs的进一步改进.Aquamacs上emacs维基页面非常有用。 It also has an option to add a little aquamacs script to your PATH that will open a file in the aquamacs GUI. 它还可以选择在PATH中添加一个小的aquamacs脚本,它将在aquamacs GUI中打开一个文件。

I create a shell script named emacs in my ~/bin directory containing: 我在〜/ bin目录中创建了一个名为emacs的shell脚本,其中包含:

open -a Emacs "$@"

Obviously, ~/bin needs to be before /usr/bin in my PATH which I set in ~/.profile so that it shadows the preinstalled emacs binary. 显然,〜/ bin需要在我的PATH中的/ usr / bin之前,我在〜/ .profile中设置它以便它隐藏预装的emacs二进制文件。

I also create a symlink via ln -s /Applications/Emacs.app/Contents/MacOS/bin/emacsclient ~/bin/emacsclient so that this also shadows the preinstalled emacsclient binary. 我还通过ln -s /Applications/Emacs.app/Contents/MacOS/bin/emacsclient ~/bin/emacsclient创建一个符号链接,这样也会影响预装的emacsclient二进制文件。

For additional connivence, I create an alias ec='emacsclient -a emacs -n ' and include (server-start) in my emacs init scripts. 为了获得额外的一致性,我在emacs init脚本中创建了一个别名ec ='emacsclient -a emacs -n'并包含(server-start)。 This enables me to open a file from the commandline using ec filename regardless if emacs is or is not already running. 这使我能够使用ec文件名从命令行打开文件,无论emacs是否已经运行。

Another tip: When you launch the emacs via Applications or open, emacs does not inherit the same path as you have in your terminal environment, so one thing I have found very useful is to run the following in my .profile after setting my path to change the PATH inherited cocoa applications: 另一个提示:当您通过应用程序启动emacs或打开时,emacs不会继承您在终端环境中的相同路径,所以我发现一件非常有用的事情是在设置我的路径之后在我的.profile中运行以下命令更改PATH继承的cocoa应用程序:

   defaults write ${HOME}/.MacOSX/environment PATH "$PATH"

That will work. 那可行。 If this is a native mac application, the binary is actually located under the application directory (not the capitalization of the binary): ... /Emacs.app/Contents/MacOS/Emacs 如果这是本机mac应用程序,则二进制文件实际位于应用程序目录下(不是二进制文件的大小写): ... / Emacs.app/Contents/MacOS/Emacs

Since you are coming from linux, you might be interested in MacPorts . 由于您来自linux,您可能对MacPorts感兴趣。 This is a large collection of packages ported from linux. 这是从linux移植的大量软件包集合。 It allows packages to be installed and upgraded from the command line, doe sdependancy management, all the stuff you would expect. 它允许从命令行,doe sdependancy管理,所有你期望的东西安装和升级包。 It includes a native version of Emacs, that can be invoked from the command line. 它包括可以从命令行调用的Emacs的本机版本。

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

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