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: Samuel Wales
Subject: Re: Getting X selection reliably (Re: idea for capture anywhere in x)
Date: Thu, 27 Oct 2022 21:59:13 -0700

i do not use emacs daemon or systemd.  have not tried running emacs
from cron i think.

i launch emacs from xinit or fluxbox menu.  sometimes from a shell.  i
run emacs as a cli batch thing from a shell.

[and i run emacs on linux console when nec.  it is inaccessible for
reasons like blinking cursor.]


On 10/26/22, Max Nikulin <manikulin@gmail.com> wrote:
> 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
>
> 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.)
>
> What I do not like that error text is captured and no error is returned
> to emacsclient, so checks must be performed in advance.
>
> My suggestion:
> ~/examples/org/capture-daemon.el
> ---- >8 ----
> (defun nm-check-selection (selection)
>    (let ((display (org-string-nw-p (getenv "DISPLAY"))))
>      (if display
>          (server-select-display display)
>        (error "No DISPLAY")))
>    (if (org-get-x-clipboard selection)
>        t
>      (error "No %S selection" selection)))
>
> (custom-set-variables
>   '(org-capture-templates
>     '(("x" "%x (test)" entry
>        (file "/tmp/capture-test.org")
>        "* Entry
> %U
>
> %x
> "
>        :immediate-finish t)
>       ("p" "primary" entry
>        (file "/tmp/capture-test.org")
>        "* Primary
> %U
>
> %(org-get-x-clipboard 'PRIMARY)
> "
>         :immediate-finish t))))
>
> (require 'org-capture)
> ---- 8< ----
>
> emacs -Q -L ~/src/org-mode/lisp/ \
>     -L /usr/share/emacs/site-lisp/elpa/htmlize-1.55/ \
>     --daemon --load ~/examples/org/capture-daemon.el
>
> emacsclient --eval "(nm-check-selection 'PRIMARY)" \
>     --eval '(org-capture nil "p")'
>
> the latter command has non-zero exit code in the case of empty selection.
>
>
>
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com



reply via email to

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