From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: klebsiella Newsgroups: gmane.emacs.help Subject: Re: send selection or current line to Terminal/iTerm Date: Fri, 13 Jun 2014 06:39:36 -0700 (PDT) Message-ID: <1402666776993-324448.post@n5.nabble.com> References: <1402261104327-324145.post@n5.nabble.com> <1402586029056-324374.post@n5.nabble.com> <87r42tvpkr.fsf@debian.uxu> <87k38lvp9r.fsf@debian.uxu> <87d2edvnog.fsf@debian.uxu> <1402609430389-324400.post@n5.nabble.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1402666809 23930 80.91.229.3 (13 Jun 2014 13:40:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 13 Jun 2014 13:40:09 +0000 (UTC) To: Help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 13 15:40:03 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WvRi5-0003gS-8n for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Jun 2014 15:40:01 +0200 Original-Received: from localhost ([::1]:59146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvRi4-0006Zo-TB for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Jun 2014 09:40:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvRhp-0006Y6-2I for Help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 09:39:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WvRhi-0000ms-An for Help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 09:39:45 -0400 Original-Received: from sam.nabble.com ([216.139.236.26]:42177) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvRhi-0000mZ-5c for Help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 09:39:38 -0400 Original-Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1WvRhg-0004XW-WE for Help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 06:39:37 -0700 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 216.139.236.26 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:98203 Archived-At: So guys, First thank you all for your time. Here is the code in my .emacs (see below) that is supposed to do the job (Thanks go to @JordonBiondo - Stackoverflow and also to you John Mastro) I am now working on emacs (not Aquamacs) and the code is still not working. Again, as I do not know Lisp, it was hard for me to debug !!! The error message given is I guess thrown by osascript, but may be linked to a syntax problem in lisp: 100:100: syntax error: Expected string but found end of script. (-2741) Process send-text-iterm2-proc exited abnormally with code 1 Osascript itself is working. For instance the following line runs correctly on the terminal: $ osascript -e 'tell application "iTerm" ' -e 'set mysession to current session of current terminal' -e 'tell mysession to write text "ls"' -e 'end tell' It would be great to make it run (For everybody I believe) .emacs related chunk (defun sendtext:escape-text(s): (with-temp-buffer (insert s) (replace-string "\\" "\\\\" nil (point-min) (point-max)) (replace-string "\"" "\\\"" nil (point-min) (point-max)) (buffer-substring-no-properties (point-min) (point-max)))) (defun sendtext:send-iterm2(beg end) (interactive "r") (let ((text (buffer-substring-no-properties beg end))) (start-process "send-text-iterm2-proc" "*sendtext:output*" "osascript" "-e" "tell app \"iTerm\"" "-e" "set mysession to current session of current terminal" "-e" "tell mysession to write text \"" (sendtext:escape-text text) "\"" "-e" "end tell"))) John Mastro wrote > Hi klebsiella, > > John Mastro < > john.b.mastro@ > > wrote: >> This is totally untested (sorry, still not around a Mac), but I think >> something along these lines should work. Assuming that SublimeText >> extension works anyway. > > By the way, if the code I posted does do approximately want you want, > I'd be happy to improve it a bit for you (e.g. handling escaping, as the > SublimeText version seems to). > > If you try it, let me know if/how it works for you. > > - John -- View this message in context: http://emacs.1067599.n5.nabble.com/send-selection-or-current-line-to-Terminal-iTerm-tp324145p324448.html Sent from the Emacs - Help mailing list archive at Nabble.com.