如何在OS X上以多tty模式使emacs 23正常工作?
我已将(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中的东西似乎很奇怪
有没有人有任何其他提示或示例让这个工作?
答案 0 :(得分:6)
我有一个来自emacs的别名
open -a /Applications/Emacs.app "$@"
如果您为每个文件打开一个新框架(窗口)这一事实感到恼火 - 添加
(setq ns-pop-up-frames nil)
到.emacs并修复。
答案 1 :(得分:5)
也许这会起作用,只需在客户端附加时调用raise-frame:
(add-hook 'server-visit-hook 'call-raise-frame)
(defun call-raise-frame ()
(raise-frame))
(在我的Linux机器上碰巧是多余的。)
答案 2 :(得分: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)))' \
"$@"
答案 3 :(得分:2)
AppleScript很简单:
tell app "Emacs" to activate
答案 4 :(得分:2)
我在 .emacs 中使用类似的东西,只在服务器尚未运行时才调用server-start:
(if (file-exists-p
(concat (getenv "TMPDIR") "emacs"
(number-to-string
(user-real-uid)) "/server"))
nil (server-start))
然后对我的 .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'
答案 5 :(得分: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 init文件中,我有以下别名:
alias e='emacsclient' # edit
alias enw='emacsclient -n' #edit (no wait)
现在我可以将一个shell与我的CocoaEmacs实例并排打开,并将两者无缝地结合使用。我可以使用e
别名使用我当前的终端流程“编辑”编辑器“内联”,一旦我在emacs中完成编辑,焦点将返回到主叫终端。
答案 6 :(得分:0)
我在.emacs中定义了这个函数
(defun ns-raise-emacs ()
(ns-do-applescript "tell application \"Emacs\" to activate"))
然后用它来抬起框架:
emacsclient -e '(ns-raise-emacs)'
我建议这样做,而不是调用osascript。它似乎比使用osascript响应更快(有时显着更快)。
答案 7 :(得分: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/)内容/ MacOS的/ Emacs的)。
在第3步中,初始调用(ns-raise-emacs)
似乎需要初始Emacs窗口显示在其他所有内容之前。
(add-hook 'server-visit-hook 'raise-frame)
使得后续帧显示在其他所有内容之前。
或者,如果您希望每次从命令行调用emacs时都显示所有其他Emacs帧,则可以取消注释(add-hook 'server-visit-hook 'ns-raise-emacs)
行。