lervag / wiki-ft.vim

Simple Vim filetype plugin for wiki-files
MIT License
14 stars 5 forks source link

highlighting of markdown-style citations with `@` breaks at `.` #13

Closed alexandreroberts closed 1 year ago

alexandreroberts commented 1 year ago

In wiki files, wiki-ft.vim highlights markdown-style citations (e.g., @me2023title.of.article) in bold, but it treats the cite-key as ending when it encounters a full stop (.):

@@me2023title.of.article

But the whole thing should be in bold.

lervag commented 1 year ago

This highlight is based on the "shortcite" link type defined in wiki.vim, here. It uses this regular expression:

'\%(\s\|^\|\[\)\zs@[-_a-zA-Z0-9]\+\>'

As you see, it does not accept any .s. The simple solution is to include the dot here. But before I do, let's just be sure we understand the consequence.

The link type is explained in wiki.vims docs: :help wiki-link-zotero. It was added as a simple way to create links from a wiki page to a zotero reference. It seems, from your question, that you are using them for something else?

alexandreroberts commented 1 year ago

Yes, I am using it for something slightly different: the cite-keys are biblatex cite-keys; my bibliography is stored in biblatex format (which allows .s), and my bibliographical manager is BibDesk (on a Mac). I would love it if I could open a bib-entry in BibDesk straight from one of these @-style citekeys in a wiki file (or md or tex -- for the latter, the citekeys of course live in \cite{} commands and the like), but the functionality I'm actually requesting now is simply to have the highlighting rules permit . when I include such cite-keys in a wiki file.

alexandreroberts commented 1 year ago

It occurs to me that the problem in markdown/wiki is a situation like See @citekey., where it may not be clear to the parser whether the . is punctuating the sentence or is simply part of the citekey. Since I never put . at the end of my citekeys (I only use it for "dot-casing"), and I would guess hardly anyone else does either, maybe the . could be treated as part of a citekey as long as it is not the last citekey-OK character in a string and not otherwise. Thus @citekey. Blah... and @citekey., 32 would omit the . from the citekey, but @cite.key would include the .key as part of the citekey. (I guess one could also think it would be good in the case of @citekey., 32 to include the . as the final character of the citekey, but I'm sticking with the principle that . shouldn't be the last character of a citekey.)

lervag commented 1 year ago

Yes, I am using it for something slightly different: …

It was close to what I suspected.

I would love it if I could open a bib-entry in BibDesk straight from one of these @-style citekeys in a wiki file

That's a new feature request. But bear in mind: I don't know what BibDesk is, I don't use MacOS, so if I were to add some kind of support here, you would need to help me quite a lot. Also, there is some need for deeper thinking here, as this clearly collides with the current Zotero implementation. I'm thinking it could be solved by abstracting things and adding one or more options.

(or md or tex -- for the latter, the citekeys of course live in \cite{} commands and the like)

I maintain VimTeX as well, so feel free to open requests for LaTeX there. But the same as above applies.

but the functionality I'm actually requesting now is simply to have the highlighting rules permit . when I include such cite-keys in a wiki file.

I think that should be doable.

It occurs to me that the problem in markdown/wiki is a situation like See @citekey., where it may not be clear to the parser whether the . is punctuating the sentence or is simply part of the citekey. …

Yes, I was also thinking about that. It means we need a complicated regex. But it's not impossible. I'll go with the one where we don't allow . at the end.

alexandreroberts commented 1 year ago

Many thanks for implementing this one as well! It works perfectly.

About linking from citekeys to BibDesk, I will consider opening feature requests (for wiki and vimtex). My hesitation is that I do not understand BibDesk's inner workings myself. I also should give some thought to what exactly would be most useful; for some use cases a link to the relevant line in the .bib file (opened in vim) might be enough. In any case, that is for a separate thread...

lervag commented 1 year ago

Many thanks for implementing this one as well! It works perfectly.

Glad to hear it :)

About linking from citekeys to BibDesk, I will consider opening feature requests (for wiki and vimtex). My hesitation is that I do not understand BibDesk's inner workings myself. I also should give some thought to what exactly would be most useful; for some use cases a link to the relevant line in the .bib file (opened in vim) might be enough. In any case, that is for a separate thread...

For VimTeX, I believe things should already work quite well as long as BibDesk provides a bib file that is used by the LaTeX project. Then VimTeX should have good features for working with that bib file. You may be interested in checking out the context menu (see :help vimtex-context-menu), for instance.

For wiki.vim, there is no such integration, but it could be possible. However, I would need to understand which type of commands we need and how and where to run them. For instance, if you can "talk to" BibDesk from a terminal via some cli, then it should not be too hard to make an integration.

alexandreroberts commented 1 year ago

I have looked into "talking to" BibDesk via a CLI. I asked the BibDesk developers about it, and Christiaan Hofman replied with exactly what we need, I think: on a Mac, you can write open x-bdsk://citekey, and this opens the bib-entry corresponding to citekey in BibDesk. It seems that for both VimTeX and wiki.vim, this could be an optional behavior that a user could switch on.

As for vimtex-context-menu, I tried it out, and it is generally pretty nice, although for some reason it is very slow for me. I suspect this might be because my .bib files are huge, since I keep all of the references I ever use for any project in 2-3 huge files at any given time, with a total of over 5000 entries. So there too if a BibDesk option could be implemented, it would be very convenient.

If you think that is possible, should I open a new feature request?

lervag commented 1 year ago

you can write open x-bdsk://citekey, and this opens the bib-entry corresponding to citekey in BibDesk.

Yes, that seems perfect.

It seems that for both VimTeX and wiki.vim, this could be an optional behavior that a user could switch on.

Agreed. If you want this for VimTeX, please open a new feature request there. It will need some thinking, though, and I'll not make any guarantees.

For wiki.vim, I think a good idea would be to "generalize" the current Zotero stuff and allow other bibliography managers. I think this will also require some thinking, so I would appreciate a feature request here as well. I think this is the one I'll address first, as it seems easier.

As for vimtex-context-menu, I tried it out, and it is generally pretty nice, although for some reason it is very slow for me. I suspect this might be because my .bib files are huge, since I keep all of the references I ever use for any project in 2-3 huge files at any given time, with a total of over 5000 entries.

Yes, I would not be surprised if a huge bib file causes delays here. I would strongly advice to not use huge, common bib files. I believe it is better to instead use bib files with only the relevant entries for each project. There are great tools available to simplify these kinds of things. I've personally found bibtool to be very good.

So there too if a BibDesk option could be implemented, it would be very convenient.

For the feature request to VimTeX it would be useful if you specifically suggest this as one of the interfaces.

alexandreroberts commented 6 months ago

I've finally gotten around to opening a feature request related to this thread on the vimtex page -- a year later!

alexandreroberts commented 6 months ago

Now I have also opened a similar feature request for wiki.vim.

lervag commented 6 months ago

Thanks! I'll look into them when I get the time!

lervag commented 6 months ago

As I mentioned a year ago, I will probably look at the one in wiki.vim first, and only after resolving that I will look at the vimtex one. It may take some time - depends on how much time I have to spare.

alexandreroberts commented 6 months ago

Thank you!

On Apr 2, 2024, at 10:54 AM, Karl Yngve Lervåg @.***> wrote:

As I mentioned a year ago, I will probably look at the one in wiki.vim first, and only after resolving that I will look at the vimtex one. It may take some time - depends on how much time I have to spare.

— Reply to this email directly, view it on GitHub https://github.com/lervag/wiki-ft.vim/issues/13#issuecomment-2031437982, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABURL6XXPQ2YF3PSK25DGJ3Y3JW37AVCNFSM6AAAAAAWHYHR3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZRGQZTOOJYGI. You are receiving this because you authored the thread.