cmp-vimtex icon indicating copy to clipboard operation
cmp-vimtex copied to clipboard

New feature: documentation window highlighting

Open micangl opened this issue 1 year ago • 11 comments

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.

micangl avatar Feb 23 '24 16:02 micangl

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 avatar Feb 28 '24 21:02 lervag

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.

lervag avatar Feb 28 '24 21:02 lervag

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).

micangl avatar Mar 01 '24 19:03 micangl

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

lervag avatar Mar 01 '24 22:03 lervag

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.

micangl avatar Mar 02 '24 19:03 micangl

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.

lervag avatar Mar 03 '24 10:03 lervag

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!

micangl avatar Mar 03 '24 12:03 micangl

Glad to help :)

lervag avatar Mar 03 '24 15:03 lervag

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.

micangl avatar Mar 03 '24 15:03 micangl

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/

lervag avatar Mar 03 '24 16:03 lervag

Thanks!

micangl avatar Mar 03 '24 17:03 micangl