emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs support for --hyperlink in ls?


From: Stephen Eglen
Subject: Re: Emacs support for --hyperlink in ls?
Date: Tue, 03 May 2022 21:38:47 +0100
User-agent: mu4e 1.6.10; emacs 28.1

> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]