How to paste to Emacs from clipboard on OSX?

后端 未结 7 1755
谎友^
谎友^ 2021-01-31 02:52

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.

相关标签:
7条回答
  • 2021-01-31 03:18

    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)

    0 讨论(0)
  • 2021-01-31 03:26

    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.

    0 讨论(0)
  • 2021-01-31 03:26

    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.

    0 讨论(0)
  • 2021-01-31 03:27

    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)
    
    0 讨论(0)
  • 2021-01-31 03:32

    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)

    0 讨论(0)
  • 2021-01-31 03:34

    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) 
    
    0 讨论(0)
提交回复
热议问题