如何从命令行启动GUI的Emacs在OSX?(How to launch GUI Emacs fro

2019-06-23 16:35发布

如何在OSX从命令行启动GUI的Emacs?

我已经下载并安装从Emacs的http://emacsformacosx.com/ 。

我会接受一个答案满足所有下列条件:

  1. Emacs窗口我的终端窗口的前面打开。
  2. 键入“emacs”能启动一个GUI Emacs窗口。 发现在该窗口中的文件将默认为寻找从我开始的Emacs的目录。
  3. 键入“emacs的foo.txt的”当存在foo.txt的启动一个GUI的Emacs窗口加载foo.txt的。
  4. 键入“emacs的foo.txt的”当foo.txt的存在与推出名为“foo.txt的”空文本缓冲的GUI Emacs窗口。 在缓冲区做^ X ^ S将节省foo.txt的从我开始的Emacs的目录。

Answer 1:

调用下面的脚本“Emacs的”,并把它在你的PATH的地方:

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

这包括#2,#3,#4。

对于1号,把这个地方你.emacs文件:

(x-focus-frame nil)

该emacsformacosx.com网站现在有一个操作方法页 ,这哪里是顶片段的来源。 有一个关于运行更多资讯emacsclient和挂钩的Emacs高达git mergetool



Answer 2:

在你的shell,别名命令“emacs的指向OSX emacs的应用

在我的壳(运行默认的bash),我有以下的(在我的.bashrc)

alias emacs='open -a /Applications/Emacs.app $1'

然后,在命令行上键入emacs,启动Emacs的应用程序。

我会,不过,建议您打开的Emacs的副本,只是不停地启动和运行。 如果是这样的话,你希望将文件加载到Emacs的现有副本,您可以通过放置在你的.bashrc以下使用emacsclient:

alias ec='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'

然后添加以下到你的.emacs文件来启动Emacs的服务器(接收emacsclient调用)

;;========================================
;; start the emacsserver that listens to emacsclient
(server-start)

然后,你可以键入

ec .bashrc

对.bashrc中的副本加载到现有Emacs会话!



Answer 3:

这提高了对大卫·考德威尔的答案通过在后台启动Emacs的:

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

正如其他回答说,这包括#2,#3,#4。 对于1号,把这个地方你.emacs文件: (x-focus-frame nil)

请注意,以下为我工作-它不会在命令行上指定的目录启动Emacs(如emacs .

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


Answer 4:

我想你可以:

  • 开始在登录emacs的守护进程
  • 有(服务器启动)在你的.emacs
  • 不要介意有很多运行的emacs的单独副本

如果是这样,那么我认为这符合原来的四个标准,再加上多了一个:

  1. Emacs窗口在我的终端窗口的前面打开。

它将总是打开到前景(具有x-焦点帧)。

  1. 键入“emacs”能启动一个GUI Emacs窗口。 发现在该窗口中的文件将默认为寻找从我开始的Emacs的目录。

它将在dired模式打开现有的Emacs窗口。

  1. 键入“emacs的foo.txt的”当存在foo.txt的启动一个GUI的Emacs窗口加载foo.txt的。

如果Emacs是已经运行,并且有一台服务器,那么它将在现有的窗口中打开,并到达前台。

  1. 键入“emacs的foo.txt的”当foo.txt的不存在与推出名为“foo.txt的”空文本缓冲的GUI Emacs窗口。 在缓冲区做^ X ^ S将节省foo.txt的从我开始的Emacs的目录。

正确。

一个额外的:

控制输入​​命令之后立即返回到终端会话。

〜/斌/ emacs的

#!/bin/bash
EMACSPATH=/Applications/Emacs.app/Contents/MacOS

# Check if an emacs server is available 
# (by checking to see if it will evaluate a lisp statement)

if ! (${EMACSPATH}/bin/emacsclient --eval "t"  2> /dev/null > /dev/null )
then
    # There is no server available so,
    # Start Emacs.app detached from the terminal 
    # and change Emac's directory to PWD

    nohup ${EMACSPATH}/Emacs --chdir "${PWD}" "${@}" 2>&1 > /dev/null &
else
    # The emacs server is available so use emacsclient

    if [ -z "${@}" ]
    then
        # There are no arguments, so
        # tell emacs to open a new window

        ${EMACSPATH}/bin/emacsclient --eval "(list-directory \"${PWD}\")"
    else    
        # There are arguments, so
        # tell emacs to open them

        ${EMACSPATH}/bin/emacsclient --no-wait "${@}"
    fi

    # Bring emacs to the foreground

    ${EMACSPATH}/bin/emacsclient --eval "(x-focus-frame nil)"
fi


Answer 5:

在山狮,我使用山本光晴的港口https://github.com/railwaycat/emacs-mac-port有以下别名:

alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs

而且它满足您的所有标准。



Answer 6:

根据本指南与自制程序包管理器刚刚建成的emacs: http://www.emacswiki.org/emacs/EmacsForMacOS与冲泡安装--cocoa的Emacs后,一要推出的.app版本,以获得图形用户界面,这在我的情况是/usr/local/Cellar/emacs/24.3/Emacs.app/Contents/MacOS/Emacs



Answer 7:

在大卫·詹姆斯的回应进一步改善我以下工作:

每说明,从终端打开一个文件时发现http://www.emacswiki.org/emacs/EmacsForMacOS#toc20

open -a /Applications/Emacs.app <file-name>

与我创建了以下EMAX bash脚本并把它放在我的路径在〜/斌大卫詹姆斯的回应结合本

#!/bin/bash
(open -a /Applications/Emacs.app "$@") &

警告 :为了得到emacs的通过名称模式Dired打开当前目录下,你需要使用

emax .

环境:

  • OS X版本约塞米蒂10.10.2
  • GNU Emacs的24.4.2(x86_64的 - 苹果darwin14.0.0,NS苹果了AppKit-1343.14)的2014-11-13


Answer 8:

其他答案在这里并没有完全为我工作。 特别是,我的机器上,在bash脚本

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

始终打开主目录中的emacs。 为了得到它在当前工作目录中打开,我不得不这样做

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

代替。



Answer 9:

简单的解决方案...

很多非常复杂的解决方案,这个问题张贴在这里。 这是公平的,因为它似乎是不平凡的。

然而,这种解决方案的工作对我很好。

ec() {
  emacsclient -n $@ 2> /dev/null
  if [[ $? == 1 ]]; then
    open -a Emacs.app  -- $@
  fi
}

用法

ec file [...]

让我们来解开发生了什么:

  1. 通过所有ec参数emacsclient和不( -n继续之前)等emacs的。
    1. 如果Emacs的已经在运行,我们都做了,你正在编辑。
  2. 吞了张贴emacsclient错误消息时,有没有运行的emacs。 ( 2> /dev/null
  3. 手动处理退出代码1 [[ $? == 1 ]]
    1. 打开Emacs.app和传递文件的参数给它(的路径将被正确打开。)
    2. 大功告成,和Emacs已经打开你的文件。


Answer 10:

根据以下步骤的Emacs编译:

./configure --with-x --prefix=/usr
make
sudo make install

和你做! 它可以帮助下载并安装XQuartz,不过这只是我的看法。



Answer 11:

这是我在OSX上打开的Emacs / emacsclient脚本。

#!/bin/bash

# Ensure (server-start) is added in your emacs init script.

EMACS=/Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs
EMACSCLIENT=/Applications/Macports/Emacs.app/\
Contents/MacOS/bin/emacsclient

# test if client already exsit.
$EMACSCLIENT -e "(frames-on-display-list)" &>/dev/null

# use emacsclient to connect existing server.
if [ $? -eq 0 ]; then
    $EMACSCLIENT -n "$@"
# open emacs.app instead.
else
    `$EMACS "$@"` &
fi


文章来源: How to launch GUI Emacs from command line in OSX?