[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Getting X selection reliably (Re: idea for capture anywhere in x)
From: |
Max Nikulin |
Subject: |
Getting X selection reliably (Re: idea for capture anywhere in x) |
Date: |
Thu, 27 Oct 2022 13:33:30 +0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 |
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.
- Re: idea for capture anywhere in x, (continued)
- Re: idea for capture anywhere in x, Samuel Wales, 2022/10/11
- Re: idea for capture anywhere in x, Max Nikulin, 2022/10/14
- Re: idea for capture anywhere in x, Samuel Wales, 2022/10/26
- Re: idea for capture anywhere in x, Ihor Radchenko, 2022/10/26
- Re: idea for capture anywhere in x, Samuel Wales, 2022/10/26
- desktop notifications (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/26
- Re: desktop notifications (Re: idea for capture anywhere in x), Samuel Wales, 2022/10/26
- Re: desktop notifications (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/26
- Re: desktop notifications (Re: idea for capture anywhere in x), Samuel Wales, 2022/10/26
- Re: desktop notifications (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/26
- Getting X selection reliably (Re: idea for capture anywhere in x),
Max Nikulin <=
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Samuel Wales, 2022/10/28
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/28
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Dr. Arne Babenhauserheide, 2022/10/28
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/28
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Samuel Wales, 2022/10/28
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/29
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Ihor Radchenko, 2022/10/28
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/29
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Samuel Wales, 2022/10/29
- Re: Getting X selection reliably (Re: idea for capture anywhere in x), Max Nikulin, 2022/10/29