emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CSL-JSON support for =parsebib=


From: Titus von der Malsburg
Subject: Re: CSL-JSON support for =parsebib=
Date: Fri, 07 May 2021 13:33:09 +0000

On 2021-05-07 Fri 14:34, Joost Kremers wrote:
> Hi Titus,
>
> On Fri, May 07 2021, Titus von der Malsburg wrote:
>> I’m the maintainer of bibtex-completion, helm-bibtex, and ivy-bibtex. My 
>> name is
>> actually Titus, not Theo ;)
>
> :$ (I do apologise!)
>
>> Regarding the symbols vs. string issue: I don’t have a strong opinion, but
>> personally tend to favor a conservative solution that avoids braking changes.
>> First, it’s difficult to predict how switching to symbols is going to affect
>> other software including custom code written by users. Second, JSON key names
>> can contain spaces and other weird stuff.
>
> Apparently, =json-parse-{buffer|string}= then gives you a symbol with a space 
> in it...

I now see that symbol names “can contain any characters whatever” [1].  But 
many characters need to be escaped (like spaces) which isn’t pretty.

>> So strings are perhaps a more natural
>> choice anyway. (It appears that you can actually configure the JSON parser to
>> use strings instead of symbols. See variable `json-key-type`.)
>
> This works for the Elisp library =json.el=, but Emacs 27 can be compiled with
> native JSON support, which, however, doesn't provide this option, 
> unfortunately.

I see.  In this case it might make sense to propose string keys as a feature 
for json.c.  The key is a string anyway at some point during parsing, so 
avoiding the conversion to symbol may actually be the best way to speed things 
up.

>> Finally,
>> it’s not necessarily clear that avoiding the conversion to strings saves
>> sufficiently many CPU cycles to justify the effort.
>
> I can simply try it out. Shouldn't be difficult to code up.
>
>> Regarding support for CSL-JSON: bibtex-completion is currently very
>> BibTeX-oriented and uses fairly low-level parsing functions from parsebib. We
>> could add similar support for CSL-JSON
>
> I'm afraid that won't be possible, because the CLS-JSON support in parsebib
> isn't low-level. ;-) There's basically just a single function that gives you 
> all
> the entries in the buffer and that's it.
>
>> Some rough ideas for such an API (just for illustration):
>> - A function that returns all entries in a .bib or CSL-JSON file.
>
> Those already exist... ;-) For JSON, that's basically the only option, because
> the actual parsing isn't handled by parsebib. For BibTeX, such a function has
> existed for some time now.

Wasn’t aware.  Fantastic!

>> - A function that returns an entry with a specific key (or multiple entries).
>
> That would be easy to support, but IMHO is better handled in 
> bibtex-completion:
> just parse the buffer and then call =gethash= on the resulting hash table. Or
> what use-case do you have in mind?

One use case: bibtex-completion drops fields that aren’t needed early on to 
save memory and CPU cycles.  (Some people work with truly enormous 
bibliographies, like crypto.bib with ~60K entries.)  But this means that we 
sometimes have to read an individual entry again if we need more fields that 
were dropped earlier.  In this case I’d like to be able to read just one entry 
without having to reparse the complete bibliography. 

>> - Functions for resolving strings and cross-references.
>
> This, too, is something that parsebib already does.

OMG, bibtex-completion is doing this as well, but I’d be happy to get rid of 
this code.

> parsebib has a lower-level API and a higher-level API, and the latter does
> essentially what you suggest here. I thought bibtex-completion was already 
> using it...

Nope. I think the high-level API didn’t exist when I wrote my code in 2014.

Seems like there’s quite a bit of potential for streamlining bibtex-completion. 
 Now I just need a week to work on it.  :)

  Titus


[1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Type.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]