-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yank to system clipboard #2222
Comments
emacs 24.5 |
sorry but, is there any progress in yank context into X-clipboard? |
@dzhwinter Are you more lucky with the last spacemacs release about this? Normally |
i have solved that.
|
It works fine for me without this change... |
@dzhwinter sorry for that silly question, Emacs noob here. |
Ok, I think I can answer this myself now: (defun dotspacemacs/user-config ()
; ...
(defun copy-to-clipboard ()
"Copies selection to x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "xsel -i -b")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-from-clipboard ()
"Pastes from x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "xsel -o -b"))
)
)
(evil-leader/set-key "o y" 'copy-to-clipboard)
(evil-leader/set-key "o p" 'paste-from-clipboard)
) Now when I press |
@nightscape 's code snippets work great for me. I only need to use pbcopy/pbpaste instead of xsel to make it work on a Mac. Thanks. |
@qiuwei have you managed to integrate pbcopy within the above snippet? thanks in advance. |
@ninrod yes, pbcopy and pbpaste work great on my mac. |
nice. just for posterity's sake, if you want to make it work for mac, it is easy enough: (you could even query the system type and make it work anywhere). (defun dotspacemacs/user-config ()
; ...
(defun copy-to-clipboard ()
"Copies selection to x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "pbpaste")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-from-clipboard ()
"Pastes from x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "pbpaste"))
)
)
(evil-leader/set-key "o y" 'copy-to-clipboard)
(evil-leader/set-key "o p" 'paste-from-clipboard)
) |
Can this be added to Spacemacs? I think this should be a builtin feature. |
This feature is a basic need for sure. |
Just make a PR! |
The snippet @ninrod posted has a little error in the (defun dotspacemacs/user-config ()
; ...
(defun copy-to-clipboard ()
"Copies selection to x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "pbcopy")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-from-clipboard ()
"Pastes from x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "pbpaste"))
)
)
(evil-leader/set-key "o y" 'copy-to-clipboard)
(evil-leader/set-key "o p" 'paste-from-clipboard)
) |
it already yanks to my system clipboard without this...
…On 12/26/2016 11:47 PM, James Kolce wrote:
The snippet @ninrod <https://github.com/ninrod> posted has a little
error in the |copy-to-clipboard| function, it calls |pbpaste| instead of
|pbcopy|. The fixed version would be:
(defun dotspacemacs/user-config ()
; ...
(defun copy-to-clipboard ()
"Copies selection to x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "pbcopy")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-from-clipboard ()
"Pastes from x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "pbpaste"))
)
)
(evil-leader/set-key "o y" 'copy-to-clipboard)
(evil-leader/set-key "o p" 'paste-from-clipboard)
)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2222 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABaMMOMj1Nej9aZO8hgmJIS_BlVkG9cks5rMJh-gaJpZM4FR7eF>.
|
That's weird, I don't know how that can be possible if it is calling I changed this: (shell-command-on-region (region-beginning) (region-end) "pbpaste") to this: (shell-command-on-region (region-beginning) (region-end) "pbcopy") Just in case someone else has the same problem. I needed this for me because I was unable to copy/paste and the solution posted before wasn't working. |
I didn't have to do anything... What OS? |
MacOS using Terminal. Here is the story: Previously, using plain Emacs I just used cmd+c to copy from Emacs to other applications and cmd+v to paste from other applications, that was possible because of Terminal and not Emacs itself. But those weren't working with Spacemacs. c-y and m-y work only within Spacemacs but not with other applications. I think it would work as before by disabling (global-set-key (kbd "M-w") 'copy-to-clipboard)
(global-set-key (kbd "C-y") 'paste-from-clipboard) Since I just started to use Emacs I don't know if that will have side-effects, but is working well so far. But maybe all this is because I'm doing something wrong, how do you do copy and paste usually? |
That'd be why it works for me -- I use the gui
…On 12/27/2016 01:05 AM, James Kolce wrote:
MacOS using Terminal.
------------------------------------------------------------------------
Here is the story:
Previously, using plain Emacs I just used cmd+c to copy from Emacs to
other applications and cmd+v to paste from other applications, that was
possible because of Terminal and not Emacs itself. But those weren't
working with Spacemacs. c-y and m-y work only within Spacemacs but not
with other applications.
I think it would work as before by disabling |xterm-mouse-mode| but I
kind of like that feature now. So I had to find a way to copy/paste
to/from other applications, and this is the thing that worked after
changing the command mentioned in my previous comment. I also changed
the keybindings to:
(global-set-key (kbd "M-w") 'copy-to-clipboard)
(global-set-key (kbd "C-y") 'paste-from-clipboard)
Since I just started to use Emacs I don't know if that will have
side-effects, but is working well so far.
------------------------------------------------------------------------
But maybe all this is because I'm doing something wrong, how do you do
copy and paste usually?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2222 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABaMMHyKnWYPG6rBATdDDLmTGPwqLiNks5rMKqNgaJpZM4FR7eF>.
|
@jameskolce M-w and C-y seem totally non-intuitive. Y is associated with yank (copy) not paste and you have M- and C- for copy and paste why not C-M-c and C-M-p? Control+alt+c/p from copy/paste? |
@andreicristianpetcu I got those from this table of EmacsWiki: Also, those are the commands I have been using in Emacs before installing Spacemacs. I just checked the Yank term and Wikipedia says:
So perhaps you are associating it with Vi (or Vi mode) instead of Emacs? C-M-c and C-M-P also make sense to me though, so I might consider changing at some point, although I also like that the default key combinations of Emacs work with the clipboard. But as I said, I'm just starting to use Emacs and I still have a lot to learn, so I appreciate the suggestions. |
Sorry for the misinformation. I never used vanilla Emacs and I started using Spacemacs from the start. I used Vim and Neovim before Spacemacs and that's where the confusion over yank comes from :) I see your point and your proposal sounds fine. |
Alright thanks, and no worries! |
Code snippet taken from syl20bnr/spacemacs#2222 (comment)
fyi I could not get above to work (using Xshell on Windows 10, connecting to Ubuntu) But this worked for me.
https://stackoverflow.com/questions/37631440/spacemacs-using-the-mouse-to-copy-paste |
There is this other option from @gelisam, which works great: |
Try the |
I wasn't able to 'copy' (in emacs lingo: |
in Ubuntu, in .spacemacs, I added 'xclip' package to list of additional packages, & Now I can paste into emacs buffer from system clipboard with 'p' in evil mode (normal). |
Finally this itching problem is solved. This is working code with OS check for Linux and MacOS. I don't use Windows so I don't know how it works (cond
;; OS X
((string-equal system-type "darwin") ; Mac OS X
(progn
(setq save-to-clipboard-cmd "pbcopy")
(setq paste-from-clipboard-cmd "pbpaste")
)
)
;; Linux
((string-equal system-type "gnu/linux") ; linux
(progn
(setq save-to-clipboard-cmd "xsel -i -b")
(setq paste-from-clipboard-cmd "xsel -o -b")
)
)
)
(defun copy-to-clipboard ()
"Copies selection to x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) save-to-clipboard-cmd)
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-from-clipboard ()
"Pastes from x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string paste-from-clipboard-cmd))
)
)
(evil-leader/set-key "o y" 'copy-to-clipboard)
(evil-leader/set-key "o p" 'paste-from-clipboard) |
I've done this integration in a different way, dropping it here for posterity (also, I can't remember if I wrote this many years ago or got it from someone else). I want any cutting and yanking to work with pbcopy/pbpaste (on my mac). I'm new to Spacemacs, but I've used this with emacs (in tty mode) on my mac for years. YMMV. I prefer this to be seamless without my thinking about it. Obviously, you can just wire up copy or paste if you don't want both. And I leave it as an exercise for the ready to extend this with
|
i use suggestion in #1504 , "*y for cut text into system clipboard, but it run in wrong behaviour. And pop up an message "x-set-selection: Symbol's funtion definition is void: x-own-selection-internal "
anyone have ideas?
The text was updated successfully, but these errors were encountered: