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

Built-in clipboard integration #3935

Open
lenormf opened this issue Dec 14, 2020 · 4 comments · May be fixed by #4016
Open

Built-in clipboard integration #3935

lenormf opened this issue Dec 14, 2020 · 4 comments · May be fixed by #4016

Comments

@lenormf
Copy link
Contributor

lenormf commented Dec 14, 2020

Feature

A substantial amount of users complains that the editor doesn't integrate with their system's clipboard out of the box.

If that's not going to happen, is there anything we can do to meet them halfway? I was thinking that the editor hardcodes multiple commands already (for example, to interact with window managers like Tmux, Kitty…), and has some selection logic (termcmd).

Could we not provide users with a command (or user mode? other?) based API that works along the same lines, so that they at least wouldn't have to look for the right xclip/xsel/… command? It would then be up to them to declare mapping in their user configuration.

HTH.

@NotAFile
Copy link

I'm currently experimenting with kakoune and this was my first real stumble.

I had expected to have the system clipboard available via the "* and "+ registers as in vim. I think this is my far the most elegant way to handle it.

@lenormf
Copy link
Contributor Author

lenormf commented Dec 15, 2020

How about a command that sets a global NormalIdle hook which populates a register (* or + or other) with the contents of the system clipboard?

The user calls the command in their configuration, and the editor does everything else.

lenormf added a commit to lenormf/kakoune that referenced this issue Jan 8, 2021
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 `c` 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.
@lenormf lenormf linked a pull request Jan 8, 2021 that will close this issue
lenormf added a commit to lenormf/kakoune that referenced this issue Jan 8, 2021
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 `c` 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.
lenormf added a commit to lenormf/kakoune that referenced this issue Jan 8, 2021
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 `c` 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.
lenormf added a commit to lenormf/kakoune that referenced this issue Jan 8, 2021
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 `c` 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.
lenormf added a commit to lenormf/kakoune that referenced this issue Jan 9, 2021
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 `c` 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.
lenormf added a commit to lenormf/kakoune that referenced this issue Jan 10, 2021
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.
@NotAFile
Copy link

NotAFile commented Mar 28, 2021

@lenormf

How about a command that sets a global NormalIdle hook which populates a register (* or + or other) with the contents of the system clipboard?

If my assumptions about NormalIdle are correct, this wouldn't be a good idea. Counterintuitively, the content of the clipboard is not fetched when you copy, but when you paste. The act of copying merely tells the OS to notify that window the next time something is pasted. It sounds with this solution, if you copied (or selected) something large, kakoune would be constantly requesting that process to send over the contents of the clipboard. Furthermore, if you accessed the register from another mode, it would be outdated.

I think a solution where you can specify a hook to populate a register when it is accessed would be better there, if you want to avoid special casing the clipboard.

@Screwtapello
Copy link
Contributor

#859 was about register hooks. mawww implemented the RegisterModified hook, but I guess the corresponding "about to read register value" hook was too intrusive.

lenormf added a commit to lenormf/kakoune that referenced this issue Nov 7, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants