How to paste to Emacs from clipboard on OSX?

帅比萌擦擦* 提交于 2021-02-05 13:10:37

问题


This might be extraordinarily simple, but I am playing with Emacs (22.1.1) and I can't get it to paste text in the clipboard using Control-Y.


回答1:


If you're using the in-built Emacs, then you're running Emacs in the terminal. The "clipboard" is a function of your windowing system. Emacs in terminal mode (-nw) does not access any windowing system specific APIs. This is true of most command line tools designed to work in the terminal.

You need to upgrade your Emacs as others have suggested, and run in graphical mode. Using Emacs 24 on Mac OS X, the behaviour you want is the default.

If you want to do this in a terminal, then this hack will make the clipboard work.

(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))

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

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx) 



回答2:


Try using the M-x clipboard-yank command. If you want to copy text to the clipboard you have to M-x clipboard-kill-region.

This works on Linux and Windows, I guess on Mac it's the same.




回答3:


I usually use Shift+insert to paste into an emacs buffer, I don't know if your keyboard has those keys though.




回答4:


That's strange.

I use command-V, and it works every time.

When you focus on the terminal window, anything you paste through command-V becomes separate keystrokes sent into the terminal.

I use Mac OS X 10.5 (Leopard) and emacs 22.1.1.




回答5:


See http://blog.binchen.org/?p=589

Here is code:

(require 'simpleclip)
(defun copy-to-clipboard ()
  (interactive)
  (let ((thing (if (region-active-p)
                   (buffer-substring-no-properties (region-beginning) (region-end))
                 (thing-at-point 'symbol))))
    (simpleclip-set-contents thing)
    (message "thing => clipboard!")))

(defun paste-from-clipboard()
  "Paste string clipboard"
  (interactive)
  (insert (simpleclip-get-contents)))

The code use simpleclip (https://github.com/rolandwalker/simpleclip)

Simpleclip requires you install some command line tool on Mac/Linux/Cygwin which . So even emacs without graphic support could also access clipboard.

This solution works on any version of Emacs, any OS. It also works when your remote ssh if the server enables X forward, the complete command is ssh -X -C -c blowfish-cbc,arcfour name@host.com)




回答6:


On Windows? I have M-ins bound to h-insert-x-selection, which I have defined as follows:

(defun h-insert-x-selection () (interactive)
  (insert (x-selection 'CLIPBOARD))) 
(global-set-key [(meta insert)] 'h-insert-x-selection)

On XEmacs it is different, where I have

(global-set-key  [(shift insert)] 'x-insert-selection)



回答7:


OS suse 12.2 - emacs default version 24.2-15.8.2 (x86_64) just ignored pasting from clipboard by ctrl-y Finally problem resolved by down grade to version 23.3-15.5.1 (x86_64)



来源:https://stackoverflow.com/questions/9985316/how-to-paste-to-emacs-from-clipboard-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!