如何从命令行启动Emacs对于Mac OS X而不阻塞?

时间:2015-06-06 00:11:32

标签: macos emacs

来自Emacs网站的

A tip对于Mac OS X,建议执行以下脚本从命令行启动它:

#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$@"

但是,这将阻止命令行,直到Emacs.app存在。

有没有办法从命令行启动它而不会阻塞?

3 个答案:

答案 0 :(得分:2)

我终于明白了:

#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs --chdir $PWD "$@" &

或者:

#!/bin/sh
open -a Emacs --args --chdir $PWD "$@"

如果我们想要将相对路径传递给Emacs,则需要--chdir参数。

我不知道是否有更多惯用的方法可以做到这一点。

答案 1 :(得分:0)

这是我多年来一直使用的shell函数。如果Emacs尚未运行,它将启动Emacs,否则它将使用Emacs服务器编辑您在现有的Emacs副本中传递给它的任何文件。它的工作方式与其他Mac编辑器(如BBEdit,TextMate和Sublime Text)的命令行工具类似。

render: function () {
    var $ul = $('<ul>').addClass('student-list');

    _.each(this.group.model, function (element, i) { // here
        var studentView = new StudentView({
            model: this.group.model[i] // and here
        });
        $ul.append(studentView.render().el);
    });
    this.$el.append($ul); // also "this" was mistyped
}

一些注意事项:

如果你没有安装e () { ( (( $# == 0 )) && emacsclient -ne 1 || emacsclient -n $@ >&/dev/null ) || ( launch -b ~/Applications/Emacs.app && until { emacsclient -n $@ >&/dev/null } do sleep 1 done ) export EDITOR=emacsclient } (我写了,所以我有点偏颇:-)你可以使用launch代替open -g - 想法是在后台启动Emacs,直到它准备好使用。

如果您未将Emacs服务器设置为使用Emacs自动启动,则可以将launch -b添加到(server-start)或自定义~/.emacs

您需要使用与您的Emacs匹配的server-mode版本,例如我的emacsclient。 (我刚刚将~/Applications/Emacs.app/Contents/bin/emacsclient添加到我的~/Applications/Emacs.app/Contents/bin)。

答案 2 :(得分:-1)

open -a "Emacs" --args --chdir $PWD "$@"

我希望这就是诀窍

相关问题