micangl / cmp-vimtex

Vimtex source for nvim-cmp.
MIT License
78 stars 5 forks source link

New feature: documentation window highlighting #18

Closed micangl closed 1 month ago

micangl commented 6 months ago

In the new branch test_highlighting is available a feature I had wanted to implement for some time. Basically, it highlights the bibliographic keys in the documentation windows: 2024-02-23T17:40:20,979233542+01:00

I haven't written the documentation yet. This is the relevant part of the configuration:

local defaults = {
  additional_information = {
    bib_highlighting = true,
    highlight_colors = {
      default_group = "Normal", -- Highlight group for most of the keys (in my config it's the yellow part)
      important_group = "IncSearch", -- Highlight group to distinguish the most important keys
      default = { -- Eventually, color codes can be specified
        fg = "",
        bg = "",
      },
      important = {
        fg = "",
        bg = "",
      },
    },
    highlight_links = { -- This sets, for each key, if "Default" or "Important" is used.
      -- Normal highlight groups can be used too.
      -- Bibtex
      Address = "Default",
      Annote = "Default",
      Author = "Important",
      Booktitle = "Default",
      Email = "Default",
      Chapter = "Default",
      Crossref = "Default",
      Doi = "Default",
      Edition = "Default",
      Editor = "Default",
      Howpublished = "Default",
      Institution = "Default",
      Journal = "Default",
      Key = "Default",
      Month = "Default",
      Note = "Default",
      Number = "Default",
      Organization = "Default",
      Pages = "Default",
      Publisher = "Default",
      School = "Default",
      Series = "Default",
      Title = "Important",
      Type = "Default",
      Volume = "Default",
      Year = "Default",
      -- Biblatex
      Isbn = "Default",
      -- cmp-vimtex-specific keys
      File = "Default",
      Lnum = "Default",
      Cite = "Default",
    },
  },
}

This may interest @lervag and @benbrastmckie.

lervag commented 6 months ago

Good idea; although I don't really like the default groups here. I would choose groups that don't set the background colors by default. In particular, I would choose one of the groups from :help group-names, perhaps PreProc or Define for the default group and Special for the important group.

lervag commented 6 months ago

Also, I would actually rather prefer to keep the keys more neutral and perhaps instead highlight the values differently. That is, have something like this:

local defaults = {
  additional_information = {
    highlight_colors = {
      key_group = "PreProc",
      value_group = "String",
      important_value_group = "Identifier",
    },

The syntax matching will be somewhat more complex, but I don't think it will be very hard.

micangl commented 6 months ago

Do you think that the ability to set guifg and guibg with the actual color codes should be removed? I almost feel that it may be excessive for this plugin (i.e., that the user should simply be able to specify a group).

lervag commented 6 months ago

Good question. My intuition is the same as you, that the user should instead learn to specify their own highlight groups directly.

micangl commented 6 months ago

I've been trying to write functioning syntax rules to highlight a row of the following kind:

TITLE: some_text

I've tried, without success:

syntax keyword CmpVimtexTitle           TITLE
syntax match CmpVimtexTitleBody "TITLE: .*$"ms=s+7

But it doesn't work: it matches only TITLE, even though I've put the match offset in the second command.

lervag commented 6 months ago

I would try something like this:

syntax match CmpVimtexTitle     "^TITLE:\s*"
      \ nextgroup=CmpVimtexTitleBody
      \ contains=CmpVimtexColon
syntax match CmpVimtexTitleBody ".*" contained
syntax match CmpVimtexColon ":" contained

I've added a match for the colon, as I think it makes sense to highlight it differently. This idea should work for everything that is a single line. If you need for the body to match multiple lines you need to do something more advanced here.

micangl commented 6 months ago

Ok, I've updated it. I'll write the documentation when I can, and then merge with master if everything's fine.

Thanks for the help, as usual!

lervag commented 6 months ago

Glad to help :)

micangl commented 6 months ago

On a sidenote, would you mind if I asked you to post about the plugin in the main subreddits? I'd like to get as many users on board as possible to start troubleshooting eventual bugs, and receive suggestions for new features. I've seen that the (Neo)vim and Latex communities are pretty big, but I don't really use it.

lervag commented 6 months ago

I can make a post on r/neovim; I don't think it makes sense to post on r/vim as nvim-cmp does not work there.

Edit: Here it is: https://www.reddit.com/r/neovim/comments/1b5l5cm/cmpvimtex_a_vimtex_source_for_nvimcmp/

micangl commented 6 months ago

Thanks!