-
Notifications
You must be signed in to change notification settings - Fork 390
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
citekey: link to BibDesk #2908
Comments
To be clear: for my purposes, it would also be fine for the bib file used to be simply the one that is open in BibDesk at the time, which I think might be the default behavior of |
I'm finally thinking about this one. So, my first thought or question is how this feature relates to the current context menu, i.e.
Something like this: I've mapped the context menu to |
I've pushed initial support for it in the manner suggested above. Please test. Also, I'm curious, I would want to only show "Open in BibDesk" if BibDesk is available. For Zotero, I did this with |
I think you brought up the context menu as one solution a year ago when brainstorming about this. When I tested it last year, I found it was very slow because my bib files are huge (I know, that's not the typical approach, but I am a historian and end up with a very different citation practice than a lot of the technical papers for which tex was originally produced...).
Even if the context menu approach were not slow, it would still involve an extra, unnecessary step for my purposes (step 2). For me, I think the ideal thing would actually be to implement something almost identical to what you did for wiki.vim: simply pass the citekey to BibDesk, without bothering to check which bib files this particular project references.
… On Apr 28, 2024, at 5:47 PM, Karl Yngve Lervåg ***@***.***> wrote:
I'm finally thinking about this one. So, my first thought or question is how this feature relates to the current context menu, i.e. :VimtexContextMenu - mapped to \la by default. I could see this feature implemented as part of the citation context. It would imply this workflow:
Keep cursor above a cite command.
Press \la to open context menu.
Select "Open in BibDesk" to open it in BibDesk.
Something like this:
image.png (view on web) <https://github.com/lervag/vimtex/assets/998898/0adc4f84-f3c6-4dbe-9fce-8010dd10d12b>
I've mapped the context menu to <cr> personally, so for me this would be two key strokes: first <cr>, then a number, e.g. 6.
—
Reply to this email directly, view it on GitHub <#2908 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABURL6VYOCVGRCVIG4QY7JTY7UKZPAVCNFSM6AAAAABFSEAA6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGUZDMMBYGI>.
You are receiving this because you authored the thread.
|
PS - Sorry, I added my last comment via email without realizing that you had followed it up by implementing what you proposed. I will test that and get back to you. |
Ah, and I see from the image that I misunderstood how you were proposing to use the context menu -- sorry about that too. |
No problem. I think this is, at least, a useful first step. Let's first make it work as expected, because I think it makes a nice addition regardless. Then after, we can consider making a shortcut - either included in VimTeX or as a personal advanced config. While testing this, you could make a small temporary project with a smaller bib file. But I would be interested in hearing if the problem with slow bibfiles may have improved since the last time you tried that. Are you using Neovim or Vim? |
P.S. I am using NeoVim. |
Good to hear. Then I think we'll keep this regardless of future work. But it would be nice if you could answer my other question from earlier. Repeated for convenience:
Yes, the context menu tries to only show relevant options. It depends on the available data from your bibentry. I use Zotero and I often add both URL's and pdf files to my library, and Zotero is able to make that readily available in my synchronized bib entries.
Before considering if I can somehow make this part of VimTeX, here is something you can use in your own personal config: function! OpenInBibDesk() abort
let l:cmd_re = '\v%(%(\a*cite|Cite)\a*|bibentry|%(text|block|%(for|hy)\w+)cquote)'
let l:cmd = vimtex#cmd#get_current()
if empty(l:cmd)
\ || l:cmd.name[1:] !~# l:cmd_re
\ || len(l:cmd.args) < 1
\ || len(l:cmd.args) > 2
return
endif
let l:text = l:cmd.args[0].text
if len(l:cmd.args) == 2
let l:text .= ',' .. l:cmd.args[1].text
endif
let l:cites = split(l:text, ',\s*')
let l:word = expand('<cword>')
if index(l:cites, l:word) >= 0
let l:selected = l:word
else
let l:selected = l:cites[0]
endif
if !empty(l:selected)
call vimtex#util#www('x-bdsk://' .. l:selected)
endif
endfunction
nnoremap <localleader>aa :call OpenInBibDesk()<cr> This is Vimscript, so you need to put it e.g. in your personal
Yes, that is right. Although "inflexible", I would argue it is sort of the expected for the current idea of the context menu.
Notice, even if your chapters are commented out from your main file, you can still have them recognize your main file and thus make both the citations and syntax stuff work seamlessly. There are several ways to do this, see %! TeX root: ../main.tex
The best approach is to have your files generally find the real main file even if they are not included in the compiled version. But you can also force a syntax package to be loaded: let g:vimtex_syntax_packages = {
\ 'biblatex_chicago': {'load': 2},
\} See |
I'm not sure what the executable is called. I have played around and searched on the internet but have been unable to figure out how to open BibDesk from the terminal. There must be one. Is there a simple way to search for it on my own computer? As for everything else: thank you, thank you! The TeX root solution solves all these little issues at once, and the vimscript you provided lets me jump straight to a BibDesk entry from my document. What a great improvement! |
Glad to help, and glad to hear that things work for you now!
The thing is, I don't know how these things work on MacOS. It doesn't work quite like it does on Linux. Perhaps @clason would be able and willing to help out here? |
It occurs to me that this "bug" might be related to the similar issue that arose when you were implementing the same functionality in wiki.vim. I think the solution there was to escape the colons in the URL. |
I don't know any other way than the vimtex/autoload/vimtex/view/skim.vim Lines 27 to 37 in 42f573b
The possible commands are not listed on a webpage but can be found through the Script Editor as explained here: https://bibdesk.sourceforge.io/manual/BibDeskHelp_80.html#SEC144 |
Well, it sure looks like the context menu picks up the correct key. On my end, the script I provided you also seems to work - but I can't really check since I don't have bibdesk. But I do see that the final url becomes
Ah, yes, that seems like it could solve this. Since you already have wiki.vim, it should be relatively easy to test. In the earlier proposed script, change: -call vimtex#util#www('x-bdsk://' .. l:selected)
+call vimtex#util#www('x-bdsk://' .. wiki#url#utils#encode(l:selected)) If that works, then I might include this encode function into VimTeX. |
Thanks! That's annoying and hard to work with. @alexandreroberts, could you try to run something like this: osascript -l JavaScript -e 'Application("BibDesk").id()'
osascript -l JavaScript -e 'Application("bibdesk").id()' and report the output? |
I think somehow the file path and name are being inserted into the link. I don't know why. This is because the file I have open in which I tested this is at |
Yes, sorry, my mistake.
Huh. That' strange. The url encoding should now be exactly the same as in the wiki.vim case, but the error message seems to report something else. Can you change the |
What happens if you do |
I've run those two commands, and this is the output: edu.ucsd.cs.mmccrack.bibdesk
edu.ucsd.cs.mmccrack.bibdesk |
When I do |
Strange. It really shouldn't do anything strange. It is here: vimtex/autoload/vimtex/util.vim Lines 487 to 495 in 42f573b
Perhaps you could try to add an |
Thanks! I've tried to add the guard now. Please update, then check if you still |
Ok. Next, what happens if you run that command manually? |
When I run that command manually, it works. |
And it does not work if you run it from the function? |
Now, that is strange and does not really make any sense to me. |
In case I somehow garbled your script when I pasted it into my vim config, here is what it says (pasted into here directly from my vim config): function! OpenInBibDesk() abort
let l:cmd_re = '\v%(%(\a*cite|Cite)\a*|bibentry|%(text|block|%(for|hy)\w+)cquote)'
let l:cmd = vimtex#cmd#get_current()
if empty(l:cmd)
\ || l:cmd.name[1:] !~# l:cmd_re
\ || len(l:cmd.args) < 1
\ || len(l:cmd.args) > 2
return
endif
let l:text = l:cmd.args[0].text
if len(l:cmd.args) == 2
let l:text .= ',' .. l:cmd.args[1].text
endif
let l:cites = split(l:text, ',\s*')
let l:word = expand('<cword>')
if index(l:cites, l:word) >= 0
let l:selected = l:word
else
let l:selected = l:cites[0]
endif
if !empty(l:selected)
call vimtex#util#www('x-bdsk://' .. wiki#url#utils#url_encode(l:selected))
endif
endfunction
nnoremap <leader>df :call OpenInBibDesk()<cr> |
Could it be that |
No, because then you should see that in #2908 (comment). |
Very strange, especially since this problem didn't come up at all in the wiki.vim case. |
Could you try to do this: vimtex#jobs#start('open x-bdsk://' .. wiki#url#utils#url_encode(l:selected)) I'm not sure if it will help, but it could. |
Oh. Now I get it! |
The thing is, doing |
Ah, that makes sense!
… On Apr 29, 2024, at 3:17 PM, Karl Yngve Lervåg ***@***.***> wrote:
The thing is, doing :!... is special. See :help :!. Things like % will be replaced, which is exactly what we are seeing. So, the url encoding is generally not very compatible with :!. I'll push an update where I use system() or vimtex#jobs#start instead, as I think those should be more robust in this case, anyway.
—
Reply to this email directly, view it on GitHub <#2908 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABURL6QKSBYFKJPPN6HIQCDY7ZB5FAVCNFSM6AAAAABFSEAA6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBSG4YTSNZVG4>.
You are receiving this because you were mentioned.
|
After updating, I still get BibDesk in the context menu, so it seems to have worked. |
Great, thanks for checking. I've pushed an update. I think most things should work now. Please test. |
I've also added url_encode to vimtex and made the bibdesk thing use it. With that, I think we can be ready to close this issue? Final version of the script: function! OpenInBibDesk() abort
let l:cmd_re = '\v%(%(\a*cite|Cite)\a*|bibentry|%(text|block|%(for|hy)\w+)cquote)'
let l:cmd = vimtex#cmd#get_current()
if empty(l:cmd)
\ || l:cmd.name[1:] !~# l:cmd_re
\ || len(l:cmd.args) < 1
\ || len(l:cmd.args) > 2
return
endif
let l:text = l:cmd.args[0].text
if len(l:cmd.args) == 2
let l:text .= ',' .. l:cmd.args[1].text
endif
let l:cites = split(l:text, ',\s*')
let l:word = expand('<cword>')
if index(l:cites, l:word) >= 0
let l:selected = l:word
else
let l:selected = l:cites[0]
endif
if !empty(l:selected)
call vimtex#util#www('x-bdsk://' .. vimtex#util#url_encode(l:selected))
endif
endfunction |
It works! Now when I use the shortcut command on that colon-laden citekey, it jumps right to the correct entry in BibDesk. Thank you! I think it would be great for this vimscript to be incorporated into Vimtex, perhaps with an additional option that defaults to off so that it doesn't bog down configurations of people who are not using BibDesk. |
Ah, great, I will change the script in my config -- or have you added the |
Just checked: I see that Thanks again, and yes, I think you can close this now. |
Nah, I don't quite see how fit it in properly. However, I did something else that I think makes more sense. If you update again, then you can change your custom script to this: function! OpenInBibDesk() abort
let l:key = vimtex#cite#get_key()
if empty(l:key) | return | endif
call vimtex#util#www('x-bdsk://' .. vimtex#util#url_encode(l:key))
endfunction I'll also add a short doc for the
Great, I'm closing it now. |
Thanks so much! This concise version of the function works beautifully. This is such a wonderful new feature of Vimtex, thank you for taking the time to implement it. |
Thanks for the kind words! And thanks for providing the ideas that help make VimTeX better! |
Describe the solution you'd like
As described in a different feature request a year ago that I'm finally following up on, I'd like to be able to type a single command to have vimtex open the bibentry for the citekey under the cursor in BibDesk (on MacOS). This would of course only work when the latex project open at the time refers to a
.bib
file.Additional context
I briefly summarized the protocol for interacting with BibDesk here.
Sorry that is has taken me so long to open the feature request! I hope this is feasible without too much trouble.
The text was updated successfully, but these errors were encountered: