开发者

Cross-platform Emacs Script

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), whe开发者_高级运维reas 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.


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)))


See the system-type variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜