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
rc clipboard: Support system clipboard ineractions #4016
base: master
Are you sure you want to change the base?
Conversation
I've been using this for some time (albeit occasionally), if everyone is happy with the API I would write some documentation for the plugin. It would also be great if some people could test the code, to make sure it's not broken and is not too awkward to use! |
9c61630
to
188bb55
Compare
PING |
This commit implements an API to interact with the system clipboard. Similarly to how terminals are picked by `x11.kak`, the `clipboardcmd_copy` and `clipboardcmd_paste` options detect which tool should be used to interact with the system clipboard at startup. Only `xsel` has been tested, but `pbcopy`/`pbpaste` and `wl-copy`/`wl-paste` will be used if they're installed. These options can also be overridden by the user to use `xclip` or any other tool they want. Commands allow copying, pasting before/after, replacing selections. Data to copy to the clipboard can also be passed directly to `clipboard-copy`. A convenience alias forwards `clipboard-paste` to `clipboard-paste-after` to save users, who expect pasting to always append, some brain cycles. The `clipboard-mode` user mode is also declared to accommodate user mappings, and assigned predictable key mappings. Savvier users can enable register integration with `clipboard-enable-register`, which currently only works one way: all contents assigned to the given register is automatically forwarded to the system clipboard. Vim uses the `*` and `+` registers, but punctuation signs are generally associated with “core” primitives in Kakoune, so using a letter register for this opt-in layer of abstraction seemed more fitting. Implementing the register integration in the opposite direction in a portable way is not self-evident, and thus not implemented by this patch. Fixes mawww#3935.
Drop the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As much as I'd love to have real native clipboard integration in Kakoune, or the hooks required to implement such a thing (a RegisterReadPre
hook, for example, or some kind of "paste" and "paste request" events in the JSON UI protocol), that would take a bunch of thought and design and implementation work.
On the other hand, this PR solves 80% of the problem and is here now.
Given how often new users get confused or frustrated with clipboard integration, I think this is worth merging.
dquote) reg='"';; | ||
esac | ||
|
||
# NOTE: The following will break with the closing-brace register |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to worry, there is no closing-brace register
define-command -docstring %{ | ||
Paste the contents of the system clipboard before the selection | ||
} clipboard-paste-before %{ | ||
execute-keys ! <space> %opt{clipboardcmd_paste} <ret> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the space is not necessary, everything that's run inside a command or mapping does not add to history.
Same for the mappings at the bottom of the file.
declare-option -docstring %{ | ||
The shell command which will paste the system clipboard into the current buffer | ||
} str clipboardcmd_paste %sh{ | ||
for cmd in "xsel -o 2>/dev/null" "pbpaste" "wl-paste -p"; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wl-paste needs the --no-newline
switch to print the clipboard as-is
bump? |
I think Kakoune should, as Tmux does, support the |
This commit implements an API to interact with the system clipboard.
Similarly to how terminals are picked by
x11.kak
, theclipboardcmd_copy
andclipboardcmd_paste
options detect which toolshould be used to interact with the system clipboard at startup. Only
xsel
has been tested, butpbcopy
/pbpaste
andwl-copy
/wl-paste
will be used if they're installed. These options can also be overridden
by the user to use
xclip
or any other tool they want.Commands allow copying, pasting before/after, replacing
selections. Data to copy to the clipboard can also be passed directly
to
clipboard-copy
.A convenience alias forwards
clipboard-paste
toclipboard-paste-after
to save users, who expect pasting to alwaysappend, some brain cycles.
The
clipboard-mode
user mode is also declared to accommodate usermappings, and assigned predictable key mappings.
Savvier users can enable register integration with
clipboard-enable-register
, which currently only works one way: allcontents assigned to the
c
register is automatically forwarded tothe system clipboard. Vim uses the
*
and+
registers, butpunctuation signs are generally associated with “core” primitives
in Kakoune, so using a letter register for this opt-in layer of
abstraction seemed more fitting.
Implementing the register integration in the opposite direction
in a portable way is not self-evident, and thus not implemented by
this patch.
Fixes #3935.