-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refer: #2908
- Loading branch information
Showing
5 changed files
with
70 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
" VimTeX - LaTeX plugin for Vim | ||
" | ||
" Maintainer: Karl Yngve Lervåg | ||
" Email: [email protected] | ||
" | ||
|
||
function! vimtex#cite#get_key(...) abort " {{{1 | ||
let l:cmd = a:0 > 0 ? a:1 : vimtex#cmd#get_current() | ||
if empty(l:cmd) | ||
\ || l:cmd.name[1:] !~# g:vimtex#re#cite_cmd | ||
\ || len(l:cmd.args) < 1 | ||
\ || len(l:cmd.args) > 2 | ||
return '' | ||
endif | ||
|
||
let l:current_word = a:0 > 1 ? a:2 : expand('<cword>') | ||
let l:cites = l:cmd.args->map({_, x -> x.text})->join(',')->split(',\s*') | ||
|
||
return index(l:cites, l:current_word) >= 0 | ||
\ ? l:current_word | ||
\ : l:cites[0] | ||
endfunction | ||
|
||
" }}}1 | ||
function! vimtex#cite#get_key_at(line, col) abort " {{{1 | ||
let l:pos_saved = vimtex#pos#get_cursor() | ||
|
||
call vimtex#pos#set_cursor(a:line, a:col) | ||
let l:key = vimtex#cite#get_key() | ||
call vimtex#pos#set_cursor(l:pos_saved) | ||
|
||
return l:key | ||
endfunction | ||
|
||
" }}}1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
MYVIM ?= nvim --clean --headless | ||
|
||
INMAKE := 1 | ||
export INMAKE | ||
|
||
TESTS := $(wildcard test*.vim) | ||
TESTS := $(TESTS:.vim=) | ||
|
||
.PHONY: test $(TESTS) | ||
|
||
test: $(TESTS) | ||
|
||
$(TESTS): | ||
@$(MYVIM) -u $@.vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
set nocompatible | ||
let &rtp = '../..,' . &rtp | ||
filetype plugin indent on | ||
syntax enable | ||
|
||
set nomore | ||
|
||
nnoremap q :qall!<cr> | ||
silent edit ../test-context-cite/test-cites.tex | ||
|
||
if empty($INMAKE) | finish | endif | ||
|
||
call assert_equal("Hemingway1940", vimtex#cite#get_key_at(11, 35)) | ||
call assert_equal("wilcox.e:2021", vimtex#cite#get_key_at(14, 56)) | ||
|
||
call vimtex#test#finished() |