From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Eglen Newsgroups: gmane.emacs.devel Subject: Re: Emacs support for --hyperlink in ls? Date: Tue, 03 May 2022 21:38:47 +0100 Message-ID: <87zgjy9w5z.fsf@cam.ac.uk> References: <8735hqdflj.fsf@cam.ac.uk> <83mtfy4znf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15252"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.10; emacs 28.1 Cc: Stephen Eglen , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 04 07:36:36 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 1nm7gh-0003nn-BV for ged-emacs-devel@m.gmane-mx.org; Wed, 04 May 2022 07:36:35 +0200 Original-Received: from localhost ([::1]:41830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nm7gf-0007tx-T0 for ged-emacs-devel@m.gmane-mx.org; Wed, 04 May 2022 01:36:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlzV1-0006rv-Lj for emacs-devel@gnu.org; Tue, 03 May 2022 16:52:00 -0400 Original-Received: from ppsw-40.csi.cam.ac.uk ([131.111.8.140]:36996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlzUy-0004Pn-Mt; Tue, 03 May 2022 16:51:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cam.ac.uk; s=20210802.ppsw; h=Content-Type:MIME-Version:Message-ID:In-reply-to:Date: Subject:Cc:To:From:References:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=DFUKVu0o/5Omg8NfIeH8A/PqeHiX9Wy0csP0RzudoOQ=; b=PgqjuQ9L/z8BAapt4baV4TEmgX /WBf6b1qnnwDPQDpUoCB9bbCiF4/OUo2MajTBt42p9KttXLZ+Gl8RHnJ2Z7s09OGcUqgdAHddALTJ nKlVM8sq0Yn++TW9PBjuFifPa2IzhAlmiNocuVBkafqZt2irGc9p7zC7bQTGvBbp/I/s=; X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: https://help.uis.cam.ac.uk/email-scanner-virus Original-Received: from smtp.maths.cam.ac.uk ([131.111.20.158]:53693 helo=evander.maths.cam.ac.uk) by ppsw-40.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.138]:25) with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nlzUv-000Bth-mM (Exim 4.95) (return-path ); Tue, 03 May 2022 21:51:54 +0100 Original-Received: from 36.224.115.87.dyn.plus.net ([87.115.224.36] helo=localhost) by evander.maths.cam.ac.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nlzUv-009pKZ-Ce; Tue, 03 May 2022 21:51:53 +0100 In-reply-to: <83mtfy4znf.fsf@gnu.org> Received-SPF: pass client-ip=131.111.8.140; envelope-from=sje30@cam.ac.uk; helo=ppsw-40.csi.cam.ac.uk X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 04 May 2022 01:33:50 -0400 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" Xref: news.gmane.io gmane.emacs.devel:289143 Archived-At: > comint.el already supports OSC 8, since Emacs 28. Thank you! I should have checked NEWS closer. I have added this: (add-to-list 'comint-output-filter-functions 'comint-osc-process-output) and confirm that in *shell* the filenames are now hyperlinks. However, at least on my system, I find the following problem that I think is caused by ls, rather than Emacs. e.g. $ ls --hyperlink /etc/anacrontab generates the following filename (after removing the markup) file://light/etc/anacrontab where 'light' is the name of my laptop (running arch linux). browse-url-xdg-open is my browser-function, and $ xdg-open file://light/etc/anacrontab generates the error: xdg-open: file 'file://light/etc/anacrontab' does not exist I have made a temporary workaround by adapting the following function to remove the hostname if it matches (system-name) which seems to solve the problem for me in initial testing, so that e.g. the URL becomes file:///etc/anacrontab (defun comint-osc-hyperlink-handler (_ text) "Create a hyperlink from an OSC 8 escape sequence. This function is intended to be included as an entry of `comint-osc-handlers'." (when comint-osc-hyperlink--state (let ((start (car comint-osc-hyperlink--state)) (url (cdr comint-osc-hyperlink--state))) (make-text-button start (point) 'type 'comint-osc-hyperlink 'browse-url-data url))) (setq comint-osc-hyperlink--state (and (string-match ";\\(.+\\)" text) (cons (point-marker) (match-string-no-properties 1 text)))) (let* ( (url (url-generic-parse-url (cdr comint-osc-hyperlink--state))) (host (url-host url))) (when (equal (system-name) host) (setq comint-osc-hyperlink--state (cons (car comint-osc-hyperlink--state) (concat "file://" (url-filename url))))))) However, is this the correct approach? (I note that a similar issue was filed for kitty terminal, which also resulted in kitty being patched in a similar fashion: https://github.com/kovidgoyal/kitty/issues/2970 so at least it is not just my system. The 'foot' terminal also does not parse urls with hostname that is not FQDN.) Stephen