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

Possible addition to the README? #683

Open
apc opened this issue Nov 18, 2023 · 1 comment
Open

Possible addition to the README? #683

apc opened this issue Nov 18, 2023 · 1 comment

Comments

@apc
Copy link

apc commented Nov 18, 2023

Those of us trying to just reuse code from embark.el and adapt it to our need could use a brief mention in the README of the role that embark-multitarget-actions plays in determining how arguments are passed to embark actions.

I just spent an embarrassingly long time trying to understand why this didn't work as intended:

(defun my/embark-copy-to-clipboard (strings)
  "Join STRINGS and pass to the system clipboard using `simpleclip-set-contents'.
With a prefix argument, prompt for the separator to join the
STRINGS, which defaults to a newline."
  (simpleclip-set-contents (string-join strings (embark--separator strings))))

(define-key embark-general-map "W" #'my/embark-copy-to-clipboard)

I was looking for a way of mimicking the behavior of embark-copy-as-kill to send stuff to the system clipboard rather than the kill ring. So I figured I could just adapt embark-copy-as-kill to use simpleclip-set-contents rather than kill-new and get exactly what I was looking for.

After running into error message after error message, I discovered that the reason embark-copy-as-kill works the way it does is because it's an element of embark-multitarget-actions. Thus I could do what I wanted (mimic the behavior of embark-copy-as-kill but having the system clipboard play the role of the kill ring) I needed to add this one line of code.

(add-to-list 'embark-multitarget-actions 'my/embark-copy-to-clipboard)

Of course, if I had just read the README and understood all of it, I would have known how to define my function directly, say:

(defun my/embark-copy-to-clipboard (string)
      "Pass STRING to the system clipboard using `simpleclip-set-contents'."
      (simpleclip-set-contents string))
    
(define-key embark-general-map "W" #'my/embark-copy-to-clipboard)

But I'm probably not the only one who just tries to reuse function definitions and tweak them a little rather than start from scratch, even when I don't fully understand why the original definition works the way it does. 😜

@oantolin
Copy link
Owner

I should definitely add something about embark-multitarget-actions to the README! The only reason I haven't is that I mistakenly thought I already had!

By the way, for your last code snippet, I'd cut out the middle man and just use (define-key embark-general-map "W" #'simpleclip-set-contents).

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