【问题标题】:emacs/aquamacs - send current line or selection to active terminalemacs/aquamacs - 将当前行或选择发送到活动终端
【发布时间】:2014-05-15 03:48:12
【问题描述】:

我一直在努力在我的 aquamacs 上完成一项简单的任务。

我有一个通过 ssh 在远程服务器上运行的 R 会话。

我的 Aquamacs 在我的机器上本地运行。

我想要的是能够将当前行或当前选择发送到 iterm2 上的活动 R 会话。这可以通过带有插件 sendText 的命令“Cmd-Enter”在 sublime text 2 上轻松完成。

我们怎样才能完成这个简单的任务?

最好的,

【问题讨论】:

  • 您是否有理由不只是从 emacs 中连接到您的 R 会话?看起来 SendText 使用苹果脚本来自动化其他正在运行的应用程序的行为,这可以在 Emacs 中完成,但这确实不是一个好的解决方案。最好的解决方案是通过 shell 缓冲区或可能的远程 slime 连接从 emacs 中连接到您的 R 会话。然后使用内置的 Emacs 函数发送进程文本。
  • 嗯,有几个原因:1) 因为我喜欢在 iterm2 上工作 2) 我尝试按照来自“github.com/laco/emacs-starter-kit/blob/master/…”的帖子的说明按照您的建议进行操作。这里的“M-x ess-remote”步骤因“没有与此缓冲区关联的进程”而失败,我个人发现这个过程很复杂。为什么不像 ST2 sendText 那样向活动终端发送“eval”?
  • SendText 源代码非常简单,真正重要的部分就在这里:github.com/wch/SendText/blob/master/SendText.py#L40-L43 您可以轻松地将其移植到 Emacs 中对start-process 的调用,如果我可以自己尝试得到时间。事实上,我开始使用它,但我不在 osx 机器上,所以我无法测试它:gist.github.com/9981411
  • 感谢您的快速回复。这开始看起来很有希望。我将“gist”代码插入到我的 .emacs 中,并尝试通过M-x sendtext:send-iterm2 将当前行发送到我的活动 iterm。这给出了以下错误“现在没有设置标记,所以没有区域”。由于我不知道 lisp 和 python,所以我很难调试。它在你手中有用吗?
  • 对于信息,我通过从 emacs 中连接到我的 R 会话(首先连接到远程服务器并在那里启动 R)并使用 isend-mode 找到了一个解决方案。主要是按照(github.com/ffevotte/isend-mode.el)上的说明,将发送键绑定到:(eval-after-load "isend-mode" '(define-key isend-mode-map (kbd "C-c RET") 'isend-send))。希望这对其他人有所帮助...谢谢 JordonBiondo

标签: emacs remote-server aquamacs iterm2


【解决方案1】:

我遇到了同样的问题,并找到了以下解决方案。我修改(非常轻微)this gist,并将其作为一个包添加到 Aquamacs。

以下是基本步骤:

将上述要点复制到一个新文件中,然后将函数iterm-send-string更改为以下内容:

(defun iterm-send-string (str)   
  "Send STR to a running iTerm instance."
  (let* ((str (iterm-maybe-remove-empty-lines str))
         (str (iterm-handle-newline str))
         (str (iterm-escape-string str)))
    (shell-command (concat "osascript "
                          "-e 'tell app \"iTerm2\"' "
                          "-e 'tell current window' "
                          "-e 'tell current session' "
                          "-e 'write text \"" str "\"' "
                          "-e 'end tell' "
                          "-e 'end tell' "
                          "-e 'end tell' "))))

要使其成为一个包,您可以在文件顶部添加以下内容

;;; iterm.el --- sends selections to iTerm.app -*- lexical-binding: t; -*-

;; modified from: https://gist.github.com/johnmastro/88cc318f4ce33b626c9d

;; Author: David Little <david.frank.little@gmail.com>
;; Keywords: lisp
;; Version: 0.0.1

;;; Commentary:

;; Works on Mac OS X: sends a selction to iTerm
;; To match SublimeText's key binding:
;; (global-set-key (kbd "<C-return>") 'iterm-send-text)

;;; Code:

那么您只需致电M-x package-install-file。一旦你将iterm-send-text 函数绑定到一个快捷方式(例如上面 cmets 中的C-return),你就应该开始做生意了!

【讨论】:

    猜你喜欢
    • 2011-04-01
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多