tecosaur / emacs-everywhere

Mirror of https://git.tecosaur.net/tec/emacs-everywhere
GNU General Public License v3.0
554 stars 58 forks source link

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

Open arthurcgusmao opened 8 months ago

arthurcgusmao commented 8 months ago

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

tecosaur commented 7 months ago

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