Skip to content

Skip paths starting with // in file link detection - #759

Merged
dakra merged 1 commit into
mainfrom
fix/skip-double-slash-paths
Oct 24, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/skip-double-slash-paths

Conversation

@dakra

@dakra dakra commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Alternative to #757 with a smaller footprint. Closes #755.

A path candidate starting with // is almost never a file. In terminal output it is a // code comment (which linked to the root directory, since // is an existing absolute path) or the host half of a URL whose scheme the URL pass does not cover, such as npm's //registry.example.com/ warnings or ws://localhost:8080. On Windows and Cygwin it names a UNC share, and file-exists-p resolves it through GetFileAttributes, which looks the host up over the network and blocks for seconds when the host does not answer. The per-scan seen cache meant every redraw covering such a line paid again.

The fix is one extra disjunct in the file-pass guard, checked on the raw match before expand-file-name and the stat. No system-type branch: the junk candidates cost a stat on every platform, and skipping them is cheaper everywhere.

Ghostty's own path detection already behaves this way: the absolute-path branch of its URL regex (src/config/url.zig) requires a / that is not followed by another /, so // paths are never candidates there either.

Compared with #757, which compares the candidate's host against the host default-directory is on, this drops the same-host exception. Relative paths in a shell whose cwd is a share still expand onto the share after the check and link as before. Only absolute //server/share/... text in output stops linking.

Behaviour

link = linkified when the file exists. stat = no link, one cheap local stat. skip = no link, no stat. HANG = Windows blocks on a network lookup for seconds, every scan.

Linux and macOS, any cwd

Output text Before After
/etc/hosts, src/main.rs:42:4, ./a.el:3, ~/.zshrc link link
// comment here links // to / skip
//bin/sh (kernel reads it as /bin/sh) link skip
//registry.example.com/api/ stat skip
ws://localhost:8080/socket stat on //localhost skip

Windows, cwd on a local drive such as c:/src/

Output text Before After
c:/src/a.el, ./a.el:3, src/main.rs:42 link link
//registry.example.com/api/, host unreachable HANG skip
//server/share/proj/b.el, server reachable link, network stat per scan skip
//server/share/proj/b.el, server unreachable HANG skip

Windows, cwd on a share, //server/share/proj/

Output text Before After
./a.el:3, b.el, ../x/y.el link link
//server/share/proj/b.el link skip
//otherserver/share/x.el, unreachable HANG skip
//registry.example.com/api/ HANG skip

Cost

Measured in emacs -Q --batch: the guard is one string-prefix-p per candidate. On a 1.3 MB sample of mixed output it removed 20% of the candidates, each of which previously cost a stat, so scans get slightly faster.

Tests

One new test, running on every platform: an npm-style //registry.example.com/api/, a bare // from a comment, and a real fixture file on one line. It asserts no // path reaches file-exists-p and only the fixture file links. The test fails with the guard removed.

A path candidate beginning with // is almost never a file.  In terminal
output it is a // code comment, which linked to the root directory
because // is an existing absolute path, or the host half of a URL whose
scheme the URL pass does not cover, such as npm's
`//registry.example.com/` warnings or ws://localhost:8080.

On Windows and Cygwin a //HOST/... name is a UNC network share.
Emacs's file-exists-p resolves it through GetFileAttributes, which looks
the host up over the network and blocks for seconds when the host does
not answer.  The seen-cache is per scan, so every redraw covering such a
line paid that cost again, freezing Emacs each time the buffer was shown.

The guard runs on the raw match before expand-file-name, so relative
paths in a shell whose cwd is a share still expand onto that share and
link.  Only absolute //server/share/... text stops linking, as does a
doubled slash like //bin/sh on POSIX.

Closes #755.
@dakra
dakra force-pushed the fix/skip-double-slash-paths branch from a1a2db1 to e71226b Compare October 24, 2026 11:05
@dakra
dakra merged commit e71226b into main Oct 24, 2026
33 checks passed
@dakra
dakra deleted the fix/skip-double-slash-paths branch October 24, 2026 12:34

This branch was previously deployed

1 inactive deployment
github-pages — e71226b8 Deployed Oct 24, 2026 by dakra via deploy #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ghostel buffer hangs when being switched to - UNC paths

1 participant