minad/osm

OSM fails when Emacs not built with json support

Closed this issue · 5 comments

As my system did not have the libjansson library, Emacs had been built without json support. In this case, searching does not work and returns with an error message indicating that json-parse-string is not known.
I solved my problem by installing the library and rebuilding Emacs. However, on the emacs.help newsgroup, it has been suggested that osm should fall back on json-read-from-string when json-parse-string is not available.

Edit: forgot to add that I'm really liking this package!

minad commented

Thanks! I just checked Emacs 27 of Debian and it comes with json-parse-string support, so it seems commonly available. The same issue exists with libxml support which provides its own entry point which is incompatible from xml.el. There is also no fallback there. Overall osm.el requires a full-featured Emacs (libxml, librsvg, libpng, libjpg), so it is not a big deal to also require libjansson. I think it is therefore okay to not fall back to json-read-from-string from json.el. Basically the decision to not fallback has been made by the API designers of Emacs. I wonder why they made this decision and did not redirect json-parse-string to json-read-from-string - performance reasons and/or correctness issues? Maybe the idea is to phase out json.el.

I think you have the correct approach: require json support natively in Emacs. At least on Debian, it's easy enough to install the jansson library and build Emacs. I have no idea, however, what other systems may be like in this regard.
Thank you.

minad commented

At least on Debian, it's easy enough to install the jansson library and build Emacs.

Emacs 27 comes ootb with jansson. There is no need to compile Emacs yourself. See https://packages.debian.org/buster-backports/emacs-gtk. Personally I switched to Emacs 28, in this case you have to compile it yourself since there doesn't exist an official Emacs 28 package just yet. However I can expect that people who use Emacs 28 will also compile it with at least the same reasonable dependencies as the prebuild 27 binaries.

Yeah, I'm using Emacs v29.x (tracking git repository for fun ;-)).

minad commented

The compat library always provides json-parse-string if it is missing from Emacs, see https://git.sr.ht/~pkal/compat.