From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8CxnK74mWmO0bgEAbAwnHQ (envelope-from ) for ; Thu, 27 Oct 2022 08:35:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id QDoyK74mWmMXfwEAauVa8A (envelope-from ) for ; Thu, 27 Oct 2022 08:35:42 +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 610D6E48E for ; Thu, 27 Oct 2022 08:35:42 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onwTI-00070z-Lw; Thu, 27 Oct 2022 02:34:33 -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 1onwTB-0006Pd-LV for emacs-orgmode@gnu.org; Thu, 27 Oct 2022 02:34:28 -0400 Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onwT7-0002dZ-QO for emacs-orgmode@gnu.org; Thu, 27 Oct 2022 02:34:24 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1onwT3-0001SQ-By for emacs-orgmode@gnu.org; Thu, 27 Oct 2022 08:34:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Getting X selection reliably (Re: idea for capture anywhere in x) Date: Thu, 27 Oct 2022 13:33:30 +0700 Message-ID: References: <87tuw31iub.fsf@mm.st> <87r0zelo7e.fsf@posteo.net> <875yg7qiyb.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Content-Language: en-US In-Reply-To: <875yg7qiyb.fsf@localhost> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 26 X-Spam_score: 2.6 X-Spam_bar: ++ X-Spam_report: (2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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=1666852542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EhTyjngLGfpQZi3rqswmZdEVDEf1cdJ8XMiLXAN5ttk=; b=FZXvLIQAU8NKRQMdVxcQO0jBJwsu7q/9c70loDQZk4YLZ2SDOABlKqYb5InY0Vrj6nOPrs Y5qLk68WDpCEPwAxSAZnVZ4quf+lmNotjOuOa6rYGS2qVCccFxRrYGw/ZZjzXG0bdhHPXy RNrHY8bjlDrSjVQ6nJdzgmlkASY8V3IMiBSZPRuzgLOUOBdqLX+2nxuHlX3a/A74gU90R3 3sv6n/5V78HFwqbNJJKkXWs6nOqzq1NMpG5bgbsdlzscrMMyYgXFQ02RTiIkzCuCWkL2ud ycHdSaqhOUjj/8gRpfY7xDQms6RmrYKFoh9BmRcGOAJFq/BNQk7gcoWBRlZQIg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666852542; a=rsa-sha256; cv=none; b=uGAH+rdoIWJmrr1P2bX/B9rSOHu7J7RumaktrJF/j9EJHGJyMjlVjZUTHUkgS8bjAM7eG3 +xxnkVFcGP1f8Re4ZVIp5bRcygBbTVJIHHR8yVqypb1U3hGf/htVRnC7K3vkFTCSv4l7wy Up6YFKoPUodorj6FId0r50YbJos4hkQX+O/jfNloRfJsJMEobqFXkBdsNsq1W+UxRe4onI 74f/dbVwi9q8wiDI1LW7dv2gcdHPAcGR5ipHuT2GgZoiWqM0NduqviQCyPqx7Bcs0yOXwb vg6KU4YLPQCskeg0ye3IVA7bxLDRYGlRMNTVska8SaaXI8/H3c6+i2/9Hhuxwg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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: 3.78 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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: 610D6E48E X-Spam-Score: 3.78 X-Migadu-Scanner: scn0.migadu.com X-TUID: OcblA7g0jOsS 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.