Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow TS users to highlight marker delimiters #623

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions lua/orgmode/colors/markup_highlighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,58 @@ local valid_post_marker_chars =
local markers = {
['*'] = {
hl_name = 'org_bold',
hl_cmd = 'hi def org_bold term=bold cterm=bold gui=bold',
hl_cmd = 'hi def %s term=bold cterm=bold gui=bold',
nestable = true,
type = 'text',
},
['/'] = {
hl_name = 'org_italic',
hl_cmd = 'hi def org_italic term=italic cterm=italic gui=italic',
hl_cmd = 'hi def %s term=italic cterm=italic gui=italic',
nestable = true,
type = 'text',
},
['_'] = {
hl_name = 'org_underline',
hl_cmd = 'hi def org_underline term=underline cterm=underline gui=underline',
hl_cmd = 'hi def %s term=underline cterm=underline gui=underline',
nestable = true,
type = 'text',
},
['+'] = {
hl_name = 'org_strikethrough',
hl_cmd = 'hi def org_strikethrough term=strikethrough cterm=strikethrough gui=strikethrough',
hl_cmd = 'hi def %s term=strikethrough cterm=strikethrough gui=strikethrough',
nestable = true,
type = 'text',
},
['~'] = {
hl_name = 'org_code',
hl_cmd = 'hi def link org_code String',
hl_cmd = 'hi def link %s String',
nestable = false,
spell = false,
type = 'text',
},
['='] = {
hl_name = 'org_verbatim',
hl_cmd = 'hi def link org_verbatim String',
hl_cmd = 'hi def link %s String',
nestable = false,
spell = false,
type = 'text',
},
['\\('] = {
hl_name = 'org_latex',
hl_cmd = 'hi def link org_latex OrgTSLatex',
hl_cmd = 'hi def link %s OrgTSLatex',
nestable = false,
spell = false,
type = 'latex',
},
['\\{'] = {
hl_name = 'org_latex',
hl_cmd = 'hi def link org_latex OrgTSLatex',
hl_cmd = 'hi def link %s OrgTSLatex',
nestable = false,
type = 'latex',
},
['\\s'] = {
hl_name = 'org_latex',
hl_cmd = 'hi def link org_latex OrgTSLatex',
hl_cmd = 'hi def link %s OrgTSLatex',
nestable = false,
type = 'latex',
},
Expand Down Expand Up @@ -357,10 +357,29 @@ local function apply(namespace, bufnr, line_index)
local hide_markers = config.org_hide_emphasis_markers

for _, range in ipairs(result.ranges) do
-- Main body highlight
vim.api.nvim_buf_set_extmark(bufnr, namespace, range.from.start.line, range.from.start.character + 1, {
ephemeral = true,
end_col = range.to['end'].character - 1,
hl_group = markers[range.type].hl_name,
spell = markers[range.type].spell,
priority = 110 + range.from.start.character,
})

-- Leading delimiter
vim.api.nvim_buf_set_extmark(bufnr, namespace, range.from.start.line, range.from.start.character, {
ephemeral = true,
end_col = range.from.start.character + 1,
hl_group = markers[range.type].hl_name .. '_delimiter',
spell = markers[range.type].spell,
priority = 110 + range.from.start.character,
})

-- Closing delimiter
vim.api.nvim_buf_set_extmark(bufnr, namespace, range.from.start.line, range.to['end'].character - 1, {
ephemeral = true,
end_col = range.to['end'].character,
hl_group = markers[range.type].hl_name,
hl_group = markers[range.type].hl_name .. '_delimiter',
spell = markers[range.type].spell,
priority = 110 + range.from.start.character,
})
Expand Down Expand Up @@ -423,8 +442,10 @@ local function apply(namespace, bufnr, line_index)
end

local function setup()
for _, marker in pairs(markers) do
vim.cmd(marker.hl_cmd)
for delimiter, marker in pairs(markers) do
vim.cmd(string.format(marker.hl_cmd, marker.hl_name))
vim.cmd(string.format('syn keyword %s_delimiter %s', marker.hl_name, delimiter))
PriceHiller marked this conversation as resolved.
Show resolved Hide resolved
vim.cmd(string.format(marker.hl_cmd, marker.hl_name .. '_delimiter'))
PriceHiller marked this conversation as resolved.
Show resolved Hide resolved
end
vim.cmd('hi def link org_hyperlink Underlined')
load_deps()
Expand Down