From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kK90N6FiW2PeTAEAbAwnHQ (envelope-from ) for ; Fri, 28 Oct 2022 07:03:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 6KB7N6FiW2PVAgAA9RJhRA (envelope-from ) for ; Fri, 28 Oct 2022 07:03:29 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8AE252CDD9 for ; Fri, 28 Oct 2022 07:03:29 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooHSk-0004Et-9b; Fri, 28 Oct 2022 00:59:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooHSg-0004EJ-Lm for emacs-orgmode@gnu.org; Fri, 28 Oct 2022 00:59:19 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ooHSe-0002D8-PS for emacs-orgmode@gnu.org; Fri, 28 Oct 2022 00:59:18 -0400 Received: by mail-lf1-x12a.google.com with SMTP id d25so6039623lfb.7 for ; Thu, 27 Oct 2022 21:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Uj301TLs5+AojVMI/CBQ94rMTMjBuw+YLmU2TDdnzp4=; b=aEefADEAf0npLZvxrEWiUDb8ZMDhIubPJoxbzSnda1EW0jiOimtbMWNuMefvS63xYh UTYG5Cy3EKHYwo/ha2Wb81xOUI4aDy0br1aniJaWIRuz1t+mFUZk3oGRIRtJ93Vg2Vwt nqbuG9ZY/shM3zP0b8BL3NEIFAVSkVsljyDaYiU3vo7icU002TGUgcDhHr9puAEP/EoH C0yaBA9/LnyYxnNieMRGVxIYUTnUASwRjQ/6xVC0VyB4hak5CMdiQhqw3XXf3zW0jwvE N26kHsZDbnqLeMxMHe0VekjrtIgRZwjSy4g8eJgCGG7G55JAsZNdG4eplSR1xXoYaZff bOWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Uj301TLs5+AojVMI/CBQ94rMTMjBuw+YLmU2TDdnzp4=; b=GTFKUTtN9xWIkitfUiI7txvBEODkp6u2ZFai8DnMjpbbzRsaRW9vhWPckj7/j0BbLG glQjeF4rnx9OTFQNYyEb3ZjflbHcAwhCxKi5n+0YhgBaKsusNhqXCHg/zAsKPysSpYOc ehDToeoo4ZW3zeNEwGfR6fsxeTFpO7S0DFnM3yIbalOD99g7SUR/IESQphbrEzpBs/zD 9qBRICUfhU9GCuKjXgQ3bHTDnNcFkNyw9+Q4D0QrW4K/y2tYV+Skmy0FhRenr267pj1O KcjxHxsM56DQYyYMW1avYGEvaREI7PQpENIo/z/encOMvWFgMuzE1Q7NrjYHXz2yIEIE /+qA== X-Gm-Message-State: ACrzQf30eLMXX/hdgN6GasaCCgWQL4K49RT4u+/PbiX8ivmMIUYA5IZ5 Svlb2s1D1p5ZKkz4MrcupJ5nkgFH6a+pvZFoPcM= X-Google-Smtp-Source: AMsMyM5bvJDxXPmHTdP/HftsNxxNcUgUQmfs/7XZrfs5DpJga8Z39hloVORHK5gF8Xtw+OamngvSH4yzfPYxvlyAcK0= X-Received: by 2002:a05:6512:ba9:b0:4a2:5db3:8c4e with SMTP id b41-20020a0565120ba900b004a25db38c4emr19047933lfv.664.1666933154574; Thu, 27 Oct 2022 21:59:14 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6520:4af1:b0:22a:e96a:7f9b with HTTP; Thu, 27 Oct 2022 21:59:13 -0700 (PDT) In-Reply-To: References: <87tuw31iub.fsf@mm.st> <87r0zelo7e.fsf@posteo.net> <875yg7qiyb.fsf@localhost> From: Samuel Wales Date: Thu, 27 Oct 2022 21:59:13 -0700 Message-ID: Subject: Re: Getting X selection reliably (Re: idea for capture anywhere in x) To: Max Nikulin Cc: emacs-orgmode@gnu.org Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=samologist@gmail.com; helo=mail-lf1-x12a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Emacs-orgmode" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666933409; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Uj301TLs5+AojVMI/CBQ94rMTMjBuw+YLmU2TDdnzp4=; b=PWU9ZoXNEbKW2O8CohrxLH/A1GwndSAYFRbwXnJMul44gKeShjHQfejhuYTWluf3QdQ/qw T2vUWdsTf92UQ+GzvhmBnJxbGGJ8HKnvJRAy5VAYr+jS5HYd2iJeVvOPQ0loy7v0TqGsX/ ol5dy7DwmUdmxGEQldpIC5OW7K0IHmUvzFWc3aSHghfV0n9UJD6P/WPckdr9rcNwE02Ksa vEI8epcmKEaSky9+8QUXIII18SxPXsXHS+R2a2nD6pDR7QUbxM/J52mWFO5gsNSXmD1OFy eKo5ccMiNnaQUGItyG2kd8RnNSxuZZgQ0uwuyJAKTfZjy5ZUiZA71/buxXICxA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666933409; a=rsa-sha256; cv=none; b=fO+AxQ3rSHEDlpLi/7SrTwmbY7wLXP3IaojmhMeDz05y/2dMVKTi0FeYQcJtlM7X8zFdw2 IY9chRGw+HfjfhsCwzLRemWz8XPggyqeOblIKp/KJW1b7PbAiNRM19gxa8icc1Ek/N8rdL y7xn7GkDaW7hyaGeD1wi9cC7uN30mwLjd2blS/scMYn21sG3jwoqrccfze53yZF3Bglu5o pkRtpuaEPEOXqkThPcFEtFc0SQasABV2kFpEul1zkmwj35ajiu5Mn4oTTbSVM9EKlrdtK6 3oMajVeFTkdYFBYHRXkFw3POMPNlCQDmO3ET3MqVKzrYpG2xuaAcIdQZdTiOAA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=aEefADEA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -7.21 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=aEefADEA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 8AE252CDD9 X-Spam-Score: -7.21 X-Migadu-Scanner: scn0.migadu.com X-TUID: IjT4E5XWVKBl 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 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