emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting X selection reliably (Re: idea for capture anywhere in x)


From: Max Nikulin
Subject: Re: Getting X selection reliably (Re: idea for capture anywhere in x)
Date: Sun, 13 Nov 2022 18:03:22 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

On 13/11/2022 11:54, Ihor Radchenko wrote:
Max Nikulin writes:
On 26/10/2022 11:58, Ihor Radchenko wrote:

Yes. From org-capture-templates docstring:

    %x          Content of the X clipboard.

Ihor, I am afraid there are a couple of pitfalls with "%x" for Samuel
since he prefers to keep Emacs hidden so can not check result.

1. If something goes wrong, e.g. some application does not put
highlighted text to PRIMARY selection then wrong source (CLIPBOARD) or
empty string may be silently captured. I would prefer explicit source
however it will not protect against stale selection from the same source.

Simulate empty selection:
echo | xsel -bi ; echo | xsel -i ; killall xsel

I am unsure what can be done here. AFAIU, Org just follows the %x
description. Nothing wrong on Org side.

The best we can do is alternative %?? that will do something more
reliable. But I am unsure what it can be.

Depending of particular capture template (even with :immediate-finish t) empty selection may or may not be an error. In Samuel's case it is an error. Unfortunately, while the template is processed, signaled errors are caught and their text is inserted into the text. That is why in my example I put checks outside of `org-capture'.

We may:
- Add a capture template option that allows errors to pass through to the caller. Then a user may add %(...) expression with all necessary checks. - Add a warning note to "%x" or :immediate-finish docs to make users aware of possible pitfall.

2. Jean pointed out that Emacs ignores X selection if it does not have
an X frame. It was almost buried in the haystack of "SQL instead of Org"
noise. It happens if Emacs is running as a daemon. I am unsure which way
Samuel starts Emacs (xinit, systemd user session, systemd socket
activation, manually, etc.)

May we modify org-get-x-clipboard adding
(server-select-display (getenv \"DISPLAY\")) ?
Will it be enough?

It will work for most of users, however sometimes it is incorrect. There are a number of options that should have higher priority than emacs server DISPLAY environment
- emacsclient -display command line option,
- emacsclient process DISPLAY environment,
- emacs -display server argument.

I have no idea how to get "emacs -display" argument and I need to look into emacsclient source and server.el to figure out which way client's display argument is passed to the server process.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]