代码之家  ›  专栏  ›  技术社区  ›  Singletoned

Emacs 23、OS X、Multi-TTY和EmacClient

  •  5
  • Singletoned  · 技术社区  · 15 年前

    如何让Emacs23在OSX上以多tty模式良好工作?

    我补充说 (server-start) 我的电子邮箱,发现了 /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n ~/myfile.txt 会在我的emacs.app中打开它,但不会把emacs带到最前面。

    那么,当我运行emacsclient时,如何让emacs.app走到最前面?(我曾经考虑过编写一个函数,在每次打开文件时都将当前帧放在前面,或者编写一个applescript来执行与emacsclient同时调用的类似工作)

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

    有没有人有其他的建议或例子来让这个工作?

    8 回复  |  直到 11 年前
        1
  •  2
  •   user23743    15 年前

    小程序脚本很简单:

    tell app "Emacs" to activate
    
        2
  •  6
  •   mrflip    15 年前

    我有一个从Emacs到的别名

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

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

    (setq ns-pop-up-frames nil)
    

    到您的.emacs并修复。

        3
  •  5
  •   Trey Jackson    15 年前

    也许这会奏效,只需在客户机连接时调用raise frame:

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

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

        4
  •  4
  •   Alex Tomlinson    12 年前

    一些建议的解决方案建议使用“提升框架”。这将提升Emacs框架,但不会使其聚焦。从终端窗口启动Emacs时,由于终端窗口保持焦点,Emacs仍将位于终端窗口的下方。我使用“选择帧集输入焦点”来提升 集中注意力。

    实例:

    /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)))' \
        "$@"
    
        5
  •  2
  •   markhellewell    14 年前

    我在我的 Emacs 要仅在服务器尚未运行时调用服务器启动,请执行以下操作:

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

    然后对我的 ZSHCC 这样我就可以无意识地跑了 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'
    
        6
  •  1
  •   jkp    14 年前

    扩展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 Alias和一旦我在Emacs中完成编辑,Focus将返回到调用终端。

        7
  •  0
  •   pheaver    15 年前

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

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

    然后用这个来升起框架:

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

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

        8
  •  0
  •   Gino    11 年前

    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服务器,则EmacClient将调用备用编辑器,在本例中是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) 线。