* Emacs support for --hyperlink in ls?
@ 2022-05-03 11:08 Stephen Eglen
2022-05-03 11:35 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Eglen @ 2022-05-03 11:08 UTC (permalink / raw)
To: emacs-devel
Various programs, including ls (GNU coreutils 9.0), now contain
--hyperlink flag and similar to markup file names with the full
file-path. The full file name is embedded using 'OSC 8 escape sequence'
so that it can be hidden in terminal emualators and recognised as a hyperlink.
For a video example using the kitty terminal, see
https://download.calibre-ebook.com/videos/kitty.mp4
the relevant part starts about 3min in; several other terminals also
support this feature. Further documentation of this feature is on the
following page
https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
Should Emacs support these OSC 8 hyperlinks in things like *shell*?
If I run M-x shell, of course, these hyperlinks appear verbatim.
$ ls -1 --hyperlink /etc | head -5
%1b]8;;file://light/etc/acpi\aacpi%1b]8;;\a
%1b]8;;file://light/etc/adjtime\aadjtime%1b]8;;\a
%1b]8;;file://light/etc/alsa\aalsa%1b]8;;\a
%1b]8;;file://light/etc/anacrontab\aanacrontab%1b]8;;\a
%1b]8;;file://light/etc/ant.conf\aant.conf%1b]8;;\a
If people think it worth trying, I might start hacking something to work
e.g. on comint-output-filter-functions but presumably this might be
something that eshell, ansi-term and vterm might also benefit from?
Stephen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Emacs support for --hyperlink in ls?
2022-05-03 11:08 Emacs support for --hyperlink in ls? Stephen Eglen
@ 2022-05-03 11:35 ` Eli Zaretskii
2022-05-03 20:38 ` Stephen Eglen
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2022-05-03 11:35 UTC (permalink / raw)
To: Stephen Eglen; +Cc: emacs-devel
> From: Stephen Eglen <sje30@cam.ac.uk>
> Date: Tue, 03 May 2022 12:08:30 +0100
>
> Various programs, including ls (GNU coreutils 9.0), now contain
> --hyperlink flag and similar to markup file names with the full
> file-path. The full file name is embedded using 'OSC 8 escape sequence'
> so that it can be hidden in terminal emualators and recognised as a hyperlink.
>
> For a video example using the kitty terminal, see
>
> https://download.calibre-ebook.com/videos/kitty.mp4
>
> the relevant part starts about 3min in; several other terminals also
> support this feature. Further documentation of this feature is on the
> following page
>
> https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
>
> Should Emacs support these OSC 8 hyperlinks in things like *shell*?
>
> If I run M-x shell, of course, these hyperlinks appear verbatim.
>
> $ ls -1 --hyperlink /etc | head -5
>
> %1b]8;;file://light/etc/acpi\aacpi%1b]8;;\a
> %1b]8;;file://light/etc/adjtime\aadjtime%1b]8;;\a
> %1b]8;;file://light/etc/alsa\aalsa%1b]8;;\a
> %1b]8;;file://light/etc/anacrontab\aanacrontab%1b]8;;\a
> %1b]8;;file://light/etc/ant.conf\aant.conf%1b]8;;\a
>
> If people think it worth trying, I might start hacking something to work
> e.g. on comint-output-filter-functions but presumably this might be
> something that eshell, ansi-term and vterm might also benefit from?
comint.el already supports OSC 8, since Emacs 28.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Emacs support for --hyperlink in ls?
2022-05-03 11:35 ` Eli Zaretskii
@ 2022-05-03 20:38 ` Stephen Eglen
2022-05-04 5:48 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Eglen @ 2022-05-03 20:38 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Stephen Eglen, emacs-devel
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Emacs support for --hyperlink in ls?
2022-05-03 20:38 ` Stephen Eglen
@ 2022-05-04 5:48 ` Eli Zaretskii
2022-05-06 12:17 ` Augusto Stoffel
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2022-05-04 5:48 UTC (permalink / raw)
To: Stephen Eglen; +Cc: emacs-devel
> 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'.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Emacs support for --hyperlink in ls?
2022-05-04 5:48 ` Eli Zaretskii
@ 2022-05-06 12:17 ` Augusto Stoffel
0 siblings, 0 replies; 5+ messages in thread
From: Augusto Stoffel @ 2022-05-06 12:17 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Stephen Eglen, emacs-devel
On Wed, 4 May 2022 at 08:48, Eli Zaretskii <eliz@gnu.org> wrote:
>> 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 think TRT is to report this to the Coreutils developers as a bug in
> GNU 'ls'.
I think ls is doing TRT. One may call 'ls --hyperlink' on a remote
machine, so a complete file URL is needed.
On my computer (running Fedora), xdg-open opens the file as expected.
So I suppose this is an issue in the OP's operating system.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-05-06 12:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-03 11:08 Emacs support for --hyperlink in ls? Stephen Eglen
2022-05-03 11:35 ` Eli Zaretskii
2022-05-03 20:38 ` Stephen Eglen
2022-05-04 5:48 ` Eli Zaretskii
2022-05-06 12:17 ` Augusto Stoffel
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.