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

Populate the buffer with the current contents of the textarea #64

Open
awkspace opened this issue Nov 13, 2019 · 6 comments
Open

Populate the buffer with the current contents of the textarea #64

awkspace opened this issue Nov 13, 2019 · 6 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@awkspace
Copy link

This project is awesome for writing new text, but I'd like to be able to edit text that's already present. Right now I just copy/paste it into Emacs when invoking emacs-anywhere, but I was wondering if this was possible to get automated?

@zachcurry
Copy link
Owner

Hi @awkspace,

There is no option for automating this use case via the package. We've had discussions about this use case in the past and decided that selecting, copying, and pasting was preferable to automation because it gives the user more control over how text is edited, but If you can think of a clever way of providing this feature in such a way that the hook function(s) have a say in whether or not to select and copy the text to the buffer, then I'd be open to adding this feature to the package.

The path of least resistance for your purposes might be to just wrap the shell script from this package with a tiny script of your own to do the select and copy steps. Then, paste to your Emacs buffer using the hook function.

@zachcurry zachcurry added enhancement New feature or request question Further information is requested labels Nov 15, 2019
@tecosaur
Copy link
Contributor

I thought I might just contribute my approach here. I also run into the situation where I want to over-write some text, and populate emacs-anywhere with it. I do this by selecting the text, which if you want to do in say a textbox is of course as easy as Ctrl A, then add the following into my ea-popup-handler hook:

(if (x-selection-exists-p 'PRIMARY)
    (insert (x-selection)))        

When exiting emacs, via default OS behaviour, the selection is overwritten 🎉.

@d1egoaz
Copy link

d1egoaz commented Mar 2, 2020

not sure if its' because I'm on OSX but your idea @tecosaur doesn't work for me.

I've tried:

(insert (gui-selection-value))
(insert (gui-get-selection 'PRIMARY))
(insert (x-get-selection 'PRIMARY))

even with the when clause:

(when (gui-get-primary-selection)
   (insert (gui-get-selection 'PRIMARY)))

it doesn't work, my doom-emacs closes the window immediately, not sure why apparently the call to (gui-get-selection 'PRIMARY) makes the frame to close

@tecosaur
Copy link
Contributor

tecosaur commented Mar 3, 2020

@d1egoaz I went through a few iterations after that initial comment, I now have

(when (gui-get-selection 'PRIMARY)
  (insert (gui-get-selection 'PRIMARY)))

Which works for me. I'm on linux though so...

@d1egoaz
Copy link

d1egoaz commented Mar 3, 2020

yeah, it doesn't work for OSX 😞

@tecosaur
Copy link
Contributor

I've got another iteration of this to make up for (gui-get-selection 'PRIMARY) often giving a bogus non-active selection, thanks to some help I got.

(defun ea-popup-handler (app-name window-title x y w h)
  ;; other stuff here
  (when (gui-get-selection 'PRIMARY) (insert (gui-get-selection 'PRIMARY)))
  (set-transient-map (let ((keymap (make-sparse-keymap)))
                          (define-key keymap (kbd "DEL")   (lambda! (delete-region (point-min) (point-max))))
                          (define-key keymap (kbd "C-SPC") (lambda! (delete-region (point-min) (point-max))))
                          keymap)))

Press DEL or C-SPC immidiately after pulling up EmacsAnywhere and it will clear the buffer.

You can find my complete config for EA here if it's of any use to anyone,
https://github.com/tecosaur/emacs-config/blob/e9a8ce2bff967436def88a75135fa4bbe6c86224/config.el#L155-L215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants