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

eqref behaviour (referencing completion) on custom command #3055

Open
Felipe-9 opened this issue Dec 12, 2024 · 1 comment
Open

eqref behaviour (referencing completion) on custom command #3055

Felipe-9 opened this issue Dec 12, 2024 · 1 comment
Labels

Comments

@Felipe-9
Copy link

Felipe-9 commented Dec 12, 2024

Description

recently i created a custom command for referencing \usingref{} and i would like for it to behave just like eqref, what changes i can make to autocomplete references just like the original command?

i searched on the original code and found out this file under /vimtex/autoload/vimtex/complete.vim

function! s:completer_ref.complete(regex) dict abort " {{{2
  let l:candidates = self.get_matches(a:regex)

  if self.context =~# '\\eqref'
        \ && !empty(filter(copy(l:candidates), 'v:val.word =~# ''^eq:'''))
    call filter(l:candidates, 'v:val.word =~# ''^eq:''')
  endif

  return l:candidates
endfunction

also in /vimtex/autoload/vimtex/syntax.vim

  syntax match texCmdRefEq nextgroup=texRefEqConcealedArg
        \ conceal skipwhite skipnl "\\eqref\>"
  call vimtex#syntax#core#new_arg('texRefEqConcealedArg', {
        \ 'contains': 'texComment,@NoSpell,texRefEqConcealedDelim',
        \ 'opts': 'keepend contained',
        \ 'matchgroup': '',
        \})
  syntax match texRefEqConcealedDelim contained "{" conceal cchar=(
  syntax match texRefEqConcealedDelim contained "}" conceal cchar=)

Should i copy those substituting \eqref by \usingref? where do i paste it?

i dont want to conceal the command.

@Felipe-9 Felipe-9 added the bug label Dec 12, 2024
@Felipe-9 Felipe-9 changed the title referencing completion on custom command eqref behaviour (referencing completion) on custom command Dec 12, 2024
@lervag
Copy link
Owner

lervag commented Dec 27, 2024

Sorry for the slow response!

It's hard to properly understand what you are asking about. The first sentence sort of makes sense, then I get confused, especially when you mention the syntax rules in syntax.vim.

I believe what you are asking for is how to configure VimTeX to allow label completion for custom commands such as your \usingref{}?

A friendly advice is to be more explicit and clear about what you are actually doing here. What is the definition of your custom command?

Now, I'm sorry to say there is currently no way to configure this. That is, the supported completion commands are hard coded; you can see them here:

\ 'patterns' : [
\ '\v\\v?%(auto|eq|[cC]?%(page)?|labelc)?ref%(\s*\{[^}]*|range\s*\{[^,{}]*%(\}\{)?)$',
\ '\\hyperref\s*\[[^]]*$',
\ '\\subref\*\?{[^}]*$',
\ '\\nameref{[^}]*$',
\ ],

I'm not very fond of adding more options, so could I ask why you want to make your own custom reference command? There are several packages that may provide something like what you want already, e.g. cleveref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants