Skip to content

Commit b371b9e

Browse files
feat(links)!: allow granular highlighting of links (#965)
Previously, both link with and without description were highlighted only with `@org.hyperlink` hl group, which was linked to `@markup.link.url` by default. Since Neovim also has `@markup.link` and `@markup.link.label` in addition to `@markup.link.url`, use those hl groups accordingly. 1. `@org.hyperlink` for the non-important parts of link (square brackets), and this hl group is now linked to `@markup.link` 2. `@org.hyperlink.url` for the actual url in the link. Hl group linked to `@markup.link.url` by default 3. `@org.hyperlink.desc` for the link description. Hl group linked to `@markup.link.label` by default To return to the previous behavior, override `@org.hyperlink.url` and `@org.hyperlink.desc` as suggested in the docs: ``` vim.api.nvim_create_autocmd('ColorScheme', { pattern = '*', callback = function() -- Define own colors vim.api.nvim_set_hl(0, '@org.hyperlink.url', { link = '@org.hyperlink' }) vim.api.nvim_set_hl(0, '@org.hyperlink.desc', { link = '@org.hyperlink' }) end }) ```
1 parent e66a641 commit b371b9e

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

docs/configuration.org

+3-1
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,9 @@ The following highlight groups are used:
28452845
- [email protected]=: code text delimiter =~= - linked to [email protected]=,
28462846
- [email protected]=: =verbatim= text - linked to [email protected]=,
28472847
- [email protected]=: verbatim text delimiter === - linked to [email protected]=,
2848-
- [email protected]=: =[[file:link]]= text - linked to [email protected]=,
2848+
- [email protected]=: link without description (example: =[[file:/this/is/link]]=) - linked to [email protected]=,
2849+
- [email protected]=: Url part of the link with description (example: =[[file:/this/is/url][description]]=) - linked to [email protected]=,
2850+
- [email protected]=: Description part of the link with description (example: =[[file:/path/to/file][description]]=) - linked to [email protected]=,
28492851
- [email protected]=: Inline latex - linked to [email protected]=,
28502852
- [email protected]= - =|= and =-= delimiters in tables - linked to [email protected]=,
28512853
- [email protected]= - Table headings - linked to [email protected]=,

lua/orgmode/colors/highlights.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ function M.link_highlights()
6161
['@org.code.delimiter'] = '@markup.raw',
6262
['@org.verbatim'] = '@markup.raw',
6363
['@org.verbatim.delimiter'] = '@markup.raw',
64-
['@org.hyperlink'] = '@markup.link.url',
64+
['@org.hyperlink'] = '@markup.link',
65+
['@org.hyperlink.url'] = '@markup.link.url',
66+
['@org.hyperlink.desc'] = '@markup.link.label',
6567
['@org.latex'] = '@markup.math',
6668
['@org.latex_env'] = '@markup.environment',
6769
['@org.footnote'] = '@markup.link.url',

queries/org/highlights.scm

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
(table . (row (cell (contents) @org.table.heading)))
4444
(table (hr) @org.table.delimiter)
4545
(fndef label: (expr) @org.footnote (#offset! @org.footnote 0 -4 0 1))
46-
(link) @org.hyperlink
47-
(link_desc) @org.hyperlink
46+
(link url: (expr) @org.hyperlink.url) @org.hyperlink
47+
(link_desc url: (expr) @org.hyperlink.url desc: (expr) @org.hyperlink.desc) @org.hyperlink
4848
(link "[[" @_link_open "]]" @_link_close (#set! conceal ""))
4949
(link_desc "[[" @_link_open "][" @_link_separator "]]" @_link_close (#set! conceal ""))
5050
((link_desc url: (expr)+ @_link_url (#set! @_link_url conceal "")) @_link (#set! @_link url @_link_url))

0 commit comments

Comments
 (0)