views:

87

answers:

2

I'm trying to code up an Emacs script that has to manipulate the clipboard (just getting the last entry and manipulating it as a string). The problem is that I work on Linux (at home) and Windows (at work). In Windows, I have to use the function (w32-get-clipboard-data), whereas Linux uses (x-get-clipboard) for the same purpose (and each OS helpfully errors out when you use the others' equivalent function).

I really don't want to keep two separate files with the same mode definition; is there any way to check, via elisp, which OS Emacs is currently running, so I can use the appropriate function?

PS. Yes, a reasonable solution is "Stop using Windows at work", and I'm working on it, but I'll need to put up with the thing for at least a month or two yet.

+4  A: 

You could check if the functions are bound (if they exist) using fboundp. Then if you want to get really clever you could create your own alias that points at the right one. For example:

(defalias 'my-get-clipboard-data                                                                                                                                                                                                   
  (cond ((fboundp 'w32-get-clipboard-data) 'w32-get-clipboard-data)                                                                                                                                                                
        ((fboundp 'x-get-clipboard) 'x-get-clipboard)                                                                                                                                                                              
        (t nil)))
Eric Warmenhoven
+2  A: 

See the system-type variable.

pheaver