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

Inilizationing frame with selected text on MacOS #4

Closed
seanfarley opened this issue Feb 11, 2021 · 3 comments
Closed

Inilizationing frame with selected text on MacOS #4

seanfarley opened this issue Feb 11, 2021 · 3 comments

Comments

@seanfarley
Copy link

This is more of a question than a bug report but perhaps it is buggy on osx.

In emacs-everywhere-insert-selection the behavior of gui-get-selection is a bit odd. If the app isn't emacs where emacs-everywhere was invoked, then there is no text inserted. However, if emacs has selected text, then sometimes that text is inserted into the frame's buffer.

Is the intended behavior to insert the selected text from the app where emacs-everywhere was invoked? If so, I believe the portable way to do that is to use apple script (as you do in other parts).

As a proof of concept I made this work with this code:

(defun emacs-everywhere-insert-selection ()
  "Insert the last text selection into the buffer."
  (call-process "osascript" nil nil nil
                "-e" "tell application \"System Events\" to keystroke \"c\" using command down")
  (sit-for 0.01) ; prevents weird multi-second pause, lets clipboard info propagate
  (yank)
  (when (and (eq major-mode 'org-mode)
             (emacs-everywhere-markdown-p))
    (shell-command-on-region (point-min) (point-max)
                             "pandoc -f markdown-auto_identifiers -t org" nil t)
    (deactivate-mark) (goto-char (point-max))))

It's basically the same but is hardcoded for darwin. I can make a PR if that's the intended behavior / acceptable solution (but obviously changed to only use osascript for darwin).

@tecosaur
Copy link
Owner

This seems good! If you don't mind I'll just grab your snippet and add it 🙂.

@seanfarley
Copy link
Author

Sure, go for it!

@jmhammond
Copy link

New emacs-everywhere user here. I want to follow up on this closed issue because I'm still having the original documented behavior - sometimes Emacs includes its clipboard text, other times it gets the selected text.

When I changed this line to have 0.1 second delay:

        (sleep-for 0.1) 

it works every time. Apparently I need just a little more time to propogate the clipboard - I bet emacs-everywhere loads too fast (it's pretty instantaneous. I love it!).

Is this something I should keep patching in my own custom version or would it be beneficial to share as a PR?

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

3 participants