From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Max Nikulin Newsgroups: gmane.emacs.devel Subject: Re: How to get DISPLAY of emacsclient? Date: Wed, 30 Nov 2022 19:47:17 +0700 Message-ID: References: <973588ef-d931-47a0-66d3-f8d70d92bd57@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19606"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 30 15:23:16 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0NzY-0004tt-4R for ged-emacs-devel@m.gmane-mx.org; Wed, 30 Nov 2022 15:23:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0Nyp-0000YS-Ca; Wed, 30 Nov 2022 09:22:31 -0500 Original-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 1p0MUs-00012m-1F for emacs-devel@gnu.org; Wed, 30 Nov 2022 07:47:30 -0500 Original-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 1p0MUq-0006a4-9l for emacs-devel@gnu.org; Wed, 30 Nov 2022 07:47:29 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1p0MUo-000AJw-4L for emacs-devel@gnu.org; Wed, 30 Nov 2022 13:47:26 +0100 X-Injected-Via-Gmane: http://gmane.org/ Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 23 X-Spam_score: 2.3 X-Spam_bar: ++ X-Spam_report: (2.3 / 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, NICE_REPLY_A=-0.257, 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-Mailman-Approved-At: Wed, 30 Nov 2022 09:22:30 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300769 Archived-At: To avoid misunderstanding, emacsclient --display "$DISPLAY" --eval ... solves the problem (on Linux). For me, reasons to continue the discussion is that Stefan considered changes in Emacs code and that some suggestions was oversimplified. On 30/11/2022 09:44, Stefan Monnier wrote: > chad [2022-11-29 19:41:11] wrote: >> On Tue, Nov 29, 2022 at 1:11 PM Max Nikulin wrote: >>> [...] >>> Add to user notes content of X selection when emacs is started as >>> daemong with no frames and the user prefers to avoid distraction due to >>> creation of a new frame. >> In general, you seem to assume that there's no way for emacs to create a >> new X11 frame object without it being immediately visible to the user. In >> my experience, that's only true in the limited subset of cases where the >> user has chosen a window manager that enforces that choice. No, I did not assume it, it the starting message I mentioned `server-select-display' that creates a hidden frame. I have not tested various window managers though, I hope it just works. I was aware of info "(elisp) Visibility of Frames" https://www.gnu.org/software/emacs/manual/html_node/elisp/Visibility-of-Frames.html The problem is how to determine proper display from an expression passed to emacsclient --eval. > `xclip.el` (from GNU ELPA) uses: Interesting, I had an impression that the main reason to invoke xclip/pbcopy/etc from Emacs is an alternative MIME type (selection target), e.g. text/html in the case of https://github.com/jkitchin/ox-clip > (setq xclip--hidden-frame > (make-frame-on-display (getenv "DISPLAY") It is appropriate for Emacs compiled with no X11 support, but in general, when overridden by --display, it may cause connection to a wrong display. Another case DISPLAY= emacs --daemon --display :0 > '((visibility . nil) > (user-position . t) > (left . 0) > (top . 0) > (no-other-frame . t)))))) I consider it as another argument that `x-open-connection' is not enough to get selection and a frame is required. > I haven't heard of a problem with that yet, but it probably hasn't been > widely tested (and it is specific to X11). I would say that, accordingly to the code, it is specific to (eq xclip-method 'emacs), not to X11. >> This is a fundamentally different case from "the user wants to use a >> non-graphical X11-based mechanism that emacs normally doesn't enable until >> emacs actually connects to a working X11 display" I never expected getting selection without opening of an X connection. I think an X11 window (frame in Emacs parlance) is not strictly necessary, but I am quite happy with a hidden frame. > server.el also does something similar to xclip-mode, tho with simpler > code: Despite server.el sets less frame properties, it skips creation a frame if another one already exists on the specified display. That is why I would not call its code simpler. > This code has been used a lot more widely, but in many/most cases we end > up making that frame visible soon after, so there might be cases where > it is not 100% unobtrusive but users don't notice it. I have not noticed any problem with this code (besides tightly encapsulated value of display), but I have tried only Linux. chad [2022-11-29 19:41:11] wrote: > On Tue, Nov 29, 2022 at 1:11 PM Max Nikulin wrote: > >> User connected to another machine through ssh (e.g. from a laptop to a >> desktop). In this case DISPLAY is different for the client and for the >> server process. (gui-get-selection) should be executed for client's DISPLAY. > > In the past, I have regularly seen both varieties of this: where the > user was logged into two machines, with an emacs server running on one, > X displays on both, and wanted a new emacs frame on either one, > depending on circumstances. As near as I can tell, there is no "right" > choice here; the user needs to (be able to) provide input on which > display to use. I agree with you in general but in the case of accessing selected text it is almost certainly display where emacsclient is called. Such choice is a reason that I did not consider the --display option at first. Usually its purpose is solely to override "$DISPLAY" value without additional effects.