5

如何让 emacs 23 在 OS X 上的多 tty 模式下正常工作?

我已经添加(server-start)到我的 .emacs 中,并且发现运行/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n ~/myfile.txt会在我的 emacs.app 中打开它,但它不会将 emacs 带到前面。

那么,当我运行 emacsclient 时,如何让 emacs.app 出现在最前面呢?(我考虑过编写一个函数,每次打开文件时将当前帧放在前面,或者可能编写一个 Applescript 来完成可以与 emacsclient 同时调用的类似工作)

emacs.app 中的 emacsclient 是最好用的吗?如果是这样,我想我会给它写一个别名,但是使用它而不是 /usr/local/bin 中的东西似乎很奇怪

有没有人有任何其他的提示或例子来让这个工作?

4

8 回答 8

6

我有一个来自 emacs 的别名

open -a /Applications/Emacs.app "$@"

如果您对它为每个文件打开一个新框架(窗口)这一事实感到恼火 - 添加

(setq ns-pop-up-frames nil)

到您的 .emacs 并修复。

于 2009-11-25T23:43:23.867 回答
5

也许这会起作用,只需在客户端附加时调用 raise-frame :

(add-hook 'server-visit-hook 'call-raise-frame)
(defun call-raise-frame ()
  (raise-frame))

(它恰好在我的 Linux 机器上是多余的。)

于 2009-06-03T16:46:24.813 回答
4

一些建议的解决方案建议使用“raise-frame”。这将提高 emacs 框架,但不会给它焦点。当您从终端窗口启动 emacs 时,由于终端窗口保留焦点,emacs 仍将位于终端窗口下方。我使用“select-frame-set-input-focus”来提升聚焦。

例子:

/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n ~/myfile.txt \
    --eval '(select-frame-set-input-focus (nth 0 (frame-list)))'

我更喜欢运行单独的 emacs 实例,所以当我使用“^X^C”退出时,我不会丢失所有窗口。为此,我有一个 shell 脚本:

#!/bin/bash
/Applications/Emacs.app/Contents/MacOS/Emacs \
    --eval '(select-frame-set-input-focus (nth 0 (frame-list)))' \
    "$@"
于 2012-11-28T04:59:56.353 回答
2

AppleScript 很简单:

tell app "Emacs" to activate
于 2009-06-03T16:35:18.307 回答
2

我在我的.emacs中使用类似的东西来仅在服务器尚未运行时调用 server-start :

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

然后对我的.zshrc进行一些更改,以便我可以ec在 shell 中无意识地作为编辑器命令运行:

# 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'
于 2011-03-11T04:22:42.757 回答
1

扩展 Trey Jackson 给出的答案和 Singletoned 的评论:我的 .emacs 文件中有以下内容

;;;
;;; Run in server-mode so other sessions can connet
;;;
(defun call-raise-frame ()
   (raise-frame))
(defun end-server-edit ()
   (shell-command "osascript -e \"tell application \\\"System Events\\\" to keystroke tab using command down\""))
(add-hook 'server-visit-hook 'call-raise-frame)
(add-hook 'server-done-hook 'end-server-edit)
(server-start)

在我的 shell 初始化文件中,我有以下别名:

alias e='emacsclient'      # edit
alias enw='emacsclient -n' #edit (no wait)

现在我可以与我的 CocoaEmacs 实例并排打开一个 shell,并无缝地一起使用这两者。我可以使用e别名在当前终端流程中调用编辑器“内联”,一旦我在 emacs 中完成编辑,焦点将返回到调用终端。

于 2010-10-19T10:17:17.400 回答
0

我在我的 .emacs 中定义了这个函数

(defun ns-raise-emacs ()
  (ns-do-applescript "tell application \"Emacs\" to activate"))

然后用它来提升框架:

emacsclient -e '(ns-raise-emacs)'

我建议这样做而不是调用 osascript。它似乎比使用 osascript 响应更快(有时明显更快)。

于 2010-01-10T23:41:15.303 回答
0

fwiw,这是我的解决方案:
步骤 1:在 /usr/local/bin/emacs 创建一个脚本,其内容如下:

#!/usr/bin/bash
emacsclient -c --alternate-editor='/Applications/Emacs.app/Contents/MacOS/Emacs'  "$@" 2>/dev/null

步骤 2. 通过以下方式使其可执行: chmod +x /usr/local/bin/emacs

步骤 3. 在您的 ~/.emacs 文件中添加以下内容:

(server-start)  

(defun ns-raise-emacs ()  
(ns-do-applescript "tell application \"Emacs\" to activate"))  

(ns-raise-emacs)  

(add-hook 'server-visit-hook 'raise-frame)  
;;(add-hook 'server-visit-hook 'ns-raise-emacs)

解释:

如果调用 /usr/local/bin/emacs 的 emacs 脚本并且当前没有运行 emacs 服务器,则 emacsclient 将调用备用编辑器,在这种情况下是 Emacs 编辑器 (/Applications/Emacs.app/Contents/MacOS /Emacs)。

在第 3 步中,初始调用(ns-raise-emacs)似乎对于将初始 Emacs 窗口显示在其他所有内容之前是必要的。

这样(add-hook 'server-visit-hook 'raise-frame)做是为了使后续帧显示在其他所有内容之前。

或者,如果您希望每次从命令行调用 emacs 时所有 Emacs 框架都显示在其他所有内容的前面,您可以取消注释该(add-hook 'server-visit-hook 'ns-raise-emacs)行。

于 2013-10-28T10:27:25.970 回答