Repository navigation
Link files inside URLs and keep balanced parentheses in URL links - #760
Merged
Merged
Conversation
The file pass used to skip any candidate overlapping a URL match, and a second check kept it off an earlier scan's URL link when URL detection was switched off. Since candidates starting with // are skipped, the only text inside a URL the file pass can still match follows a `:' or a parenthesis, such as https://host/upload(/tmp/a.log). Linking that path as a file is useful, so the ownership check and ghostel--url-link-p go. Every character of the URL keeps the full URL as its target, so a click on the host still opens the URL and a click on the path opens the file. The URL regex now treats a balanced (...) group as part of the URL, so https://en.wikipedia.org/wiki/Rust_(programming_language) links in full instead of losing its closing paren. A `(' or `)' that is not part of a balanced pair ends the URL, which still leaves out the trailing paren of "(see https://example.com)". The regex is built from runs of URL characters interleaved with balanced groups rather than a per-character alternation, so a long URL cannot overflow the regexp matcher; matching time is unchanged within noise on a 1.3 MB sample. Also shortens the docstrings and comments throughout ghostel-links.el to describe current behaviour only, drops a few redundant forms (ghostel--range-overlaps-p returning the range, ghostel--goto-hyperlink calling ghostel--find-link-1 directly, the fileref concat), and replaces the URL-ownership test with one pinning the split link.
dakra
force-pushed
the
fix/file-links-inside-urls
branch
from
October 24, 2026 12:49
04a577c to
6a8b838
Compare
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #759.
File paths inside URLs link as files
The file pass used to skip any candidate overlapping a URL match (
url-ranges), plus a second check (ghostel--url-link-p) that protected an earlier scan's URL link when URL detection had been switched off. With//candidates skipped since #759, the only text inside a URL the file pass can still reach follows a:or a parenthesis, e.g.https://host/upload(/tmp/a.log). Linking that path as a file is useful rather than harmful, so both checks are removed.Every character of a URL link carries the full URL as its target, so after the file pass overlays the path, a click on the scheme, host or closing paren still opens the complete URL, and a click on the path opens the file. Only an existing file links; a non-existent path leaves the URL link whole.
Known side effect, accepted: such a URL becomes three navigation stops for
ghostel-next-hyperlink(URL prefix, file, closing paren).URL links keep balanced parentheses
ghostel--url-regexis built from runs of URL characters interleaved with balanced(...)groups, ending in a non-punctuation character or a balanced group.https://w.org/Rust_(language)https://w.org/Rust_(languagehttps://w.org/Rust_(language)(see https://x.org/a)https://x.org/ahttps://x.org/a[t](https://x.org/a_(b))https://x.org/a_(bhttps://x.org/a_(b)https://x.org/a)bhttps://x.org/a)bhttps://x.org/aA lone
(or)ends the URL, as in ghostty's URL regex. Unlike ghostty, any URL character is allowed inside the parens, so(v=vs.110).aspxworks too. The group-based form backtracks per paren group, not per character, so a 20 KB URL or 2000 paren groups match without touching the regexp stack limit. Timing on a 1.3 MB URL-dense sample: 28.7 ms before, 29.7 ms after.Conciseness pass over
ghostel-links.elDocstrings and comments now describe current behaviour only; a few forms lost redundant machinery (
ghostel--range-overlaps-preturns the found range,ghostel--goto-hyperlinkcallsghostel--find-link-1directly, thefileref:target is a singleconcat). No behaviour change intended beyond the two sections above; the uncommitted diff was reviewed for equivalence, including a 20k-case fuzz of the paren-free URL regex against the old one.Tests
ghostel-test-detect-links-path-inside-url-as-filereplacesghostel-test-detect-url-owns-the-path-inside-itand pins both the overlay and the full-URL targets around it.