Skip to content
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

Why not copy to clipboard directly from buffer (instead of file)? #77

Open
arthurcgusmao opened this issue Mar 5, 2024 · 1 comment

Comments

@arthurcgusmao
Copy link

arthurcgusmao commented Mar 5, 2024

Hi @tecosaur,

First of all, thanks a lot for this super useful package.

I have been taking a look at the source code and I see the current flow emacs-everywhere-finish:

  1. Write buffer contents to file
  2. Copy from file to clipboard
  3. Paste from clipboard to app

Why don't we shortcircuit (1) and (2) and directly copy the buffer contents to the clipboard?

From my understanding, that would make the application more robust across OSs, since Emacs already has the capability of copying to the system's clipboard...

@arthurcgusmao arthurcgusmao changed the title Why not copy to from clipboard from buffer (instead of file)? Why not copy to clipboard directly from buffer (instead of file)? Mar 5, 2024
@tecosaur
Copy link
Owner

tecosaur commented Apr 7, 2024

We do actually directly copy the buffer content to the clipboard, but during development I found that just using gui-select-text wasn't actually 100% successful, as hinted in the code comment here:

;; In `emacs-everywhere-finish'
(gui-select-text (buffer-string))
(gui-backend-set-selection 'PRIMARY (buffer-string))
(when emacs-everywhere-copy-command ; handle clipboard finicklyness
  (let ((inhibit-message t)
        (require-final-newline nil)
        write-file-functions)
    (write-file buffer-file-name)
    (apply #'call-process (car emacs-everywhere-copy-command)
           nil nil nil
           (mapcar (lambda (arg)
                     (replace-regexp-in-string "%f" buffer-file-name arg))
                   (cdr emacs-everywhere-copy-command)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants