[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs support for --hyperlink in ls?
From: |
Eli Zaretskii |
Subject: |
Re: Emacs support for --hyperlink in ls? |
Date: |
Wed, 04 May 2022 08:48:06 +0300 |
> From: Stephen Eglen <sje30@cam.ac.uk>
> Cc: Stephen Eglen <sje30@cam.ac.uk>, emacs-devel@gnu.org
> Date: Tue, 03 May 2022 21:38:47 +0100
>
> 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.)
I think TRT is to report this to the Coreutils developers as a bug in
GNU 'ls'.