<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>@Lathi.net: Sharing the Mac Clipboard with Emacs</title>
    <link>http://blog.lathi.net/articles/2007/11/07/sharing-the-mac-clipboard-with-emacs</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>Sharing the Mac Clipboard with Emacs</title>
      <description>&lt;p&gt;While I&amp;#8217;m sharing emacs hacks, I finally got around to researching this and/or figuring it out.  I almost always run emacs inside the terminal in a &amp;#8220;no window&amp;#8221; mode.  It&amp;#8217;s pretty natural for me to use M-w to copy something from emacs and then try to Cmd-V it in another Terminal window or likewise Cmd-C something in Terminal and then try paste it into emacs with C-y.  Until now, I haven&amp;#8217;t known how to share the clipboard with emacs.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;(defun copy-from-osx ()
  (shell-command-to-string &amp;quot;pbpaste&amp;quot;))

(defun paste-to-osx (text &amp;amp;optional push)
  (let ((process-connection-type nil)) 
      (let ((proc (start-process &amp;quot;pbcopy&amp;quot; &amp;quot;*Messages*&amp;quot; &amp;quot;pbcopy&amp;quot;)))
        (process-send-string proc text)
        (process-send-eof proc))))

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This takes advantage of the &lt;code&gt;pbcopy&lt;/code&gt; and &lt;code&gt;pbpaste&lt;/code&gt; command line programs to access the clipboard and offers them up as elisp method for emacs&amp;#8217; &lt;code&gt;interprogram-*-functions&lt;/code&gt;.  Easy, peasy, pumkin weasy.&lt;/p&gt;


	&lt;p&gt;I need to give some props to Mark Aufflick for his post on &lt;a href="http://mark.aufflick.com/blog/2006/10/30/automatic-copy-from-x11-app-to-macos-clipboard"&gt;Automatic Copy from &lt;span class="caps"&gt;X11&lt;/span&gt; App to Mac OS Clipboard&lt;/a&gt;.  My &lt;code&gt;paste-to-osx&lt;/code&gt; is pretty much a straight rip from him.&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 20:09:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d76e1e03-86bc-423e-95ce-eca0874b9166</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/11/07/sharing-the-mac-clipboard-with-emacs</link>
      <category>Emacs</category>
      <category>Mac OS X</category>
      <category>pbcopy</category>
      <category>pbpaste</category>
      <category>mac</category>
      <category>clipboard</category>
      <category>emacs</category>
    </item>
  </channel>
</rss>
