Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to enable XEmacs to OS X clipboard sharing UNIX
The following emacs lisp code provides a convenient way to cut and paste between XEmacs and native Aqua applications. If you're not an XEmacs user there's nothing to see here.

Read the rest of the hint for the script...


;; osx-clipboard.el begins here.

;; k. montuori <montuori at ignavus.info>
;; 11 july 2003

;; this is free software; 
;; if you make significant improvements, let me know!

;; of all the things apple's X implementation does well, managing the
;; global/os x clipboard isn't one of them.  these functions allow the 
;; osx clipboard to be "pasted" into the buffer at point or have the
;; current region (or zmacs-region) copied (or cut) into the clipboard.  

;; C-cM-c -- copy the region to clipboard (like cmd-c)
;; C-cM-x -- cut the region into the clipboard (like cmd-x)
;; C-cM-v -- paste the clipboard into the buffer at point (like cmd-v)

;; to install, put this .el file in your load-path somewhere and call
;;   (require 'osx-clipboard) 
;; in your .emacs file.

(defvar osx-pbpaste-cmd "/usr/bin/pbpaste"
  "*command-line paste program")

(defvar osx-pbcopy-cmd "/usr/bin/pbcopy"
  "*command-line copy program")

(defun osx-pbpaste ()
  "paste the contents of the os x clipboard into the buffer at point."
  (interactive)
  (call-process osx-pbpaste-cmd nil t t))

(defun osx-pbcopy ()
  "copy the contents of the region into the os x clipboard."
  (interactive)
  (if (region-exists-p)
    (call-process-region 
     (region-beginning) (region-end) osx-pbcopy-cmd nil t t)
    (error "region not selected")))

(defun osx-pbcut ()
  "cut the contents of the region; put in os x clipboard."
  (interactive)
  (if (region-exists-p)
    (call-process-region 
     (region-beginning) (region-end) osx-pbcopy-cmd t t t)
    (error "region not selected")))

(define-key global-map "\C-c\M-v" 'osx-pbpaste)
(define-key global-map "\C-c\M-c" 'osx-pbcopy)
(define-key global-map "\C-c\M-x" 'osx-pbcut)

(provide 'osx-clipboard)

;; end osx-clipboard.el
Any questions should be directed to montuori at ignavus.info. Cheers!

[robg adds: I haven't tested this one myself...]
    •    
  • Currently 3.75 / 5
  You rated: 5 / 5 (4 votes cast)
 
[7,816 views]  

A script to enable XEmacs to OS X clipboard sharing | 2 comments | Create New Account
Click here to return to the 'A script to enable XEmacs to OS X clipboard sharing' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to enable XEmacs to OS X clipboard sharing
Authored by: merlyn on Jul 15, '03 12:00:56PM

I didn't need to do this at all. What I did notice is that if I had defined something in the cutbuffer, then hit command-C, it was also in Aqua's clipboard. And when I want to paste something from Aqua, I put it in Aqua's clipboard, then went to XEmacs, and hit middle-button (option button on a normal mac mouse).

No extra software needed. Not sure why this hint is here.



[ Reply to This | # ]
A script to enable XEmacs to OS X clipboard sharing
Authored by: montuori on Jul 15, '03 12:36:10PM

i found it useful for a couple reasons: in my X configuration the command key is mapped to meta, since physically it's located where meta should be, so command-c (now meta-c) runs capitalize-region-or-word as expected. mousing to the X11 menu to select "copy" is tedious at best. further, mousing with the trackpad on the powerbook and option-clicking to paste isn't particularly convenient either.

so although it's not strictly necessary, mapping the cut and paste to key combinations feels more emacs-ish to me. your mileage varied. cheers!



[ Reply to This | # ]