What is it?

A major mode for emacs that provides syntax highlighting for SPARQL. It also provides a way to execute queries against a SPARQL HTTP endpoint, such as is provided by Fuseki. It is also possible to query other endpoints like DBPedia. You can find sparql-mode here.

Getting Started

(add-to-list 'load-path "/path/to/sparql-mode-dir")
(autoload 'sparql-mode "sparql-mode.el"
    "Major mode for editing SPARQL files" t)
(add-to-list 'auto-mode-alist '("\\.sparql$" . sparql-mode))

Now sparql-mode will load whenever you visit a file whose name ends with .sparql. Alternatively, run in an existing buffer containing SPARQL commands.

It is also possible to add

-*- mode: sparql -*-

to the top of the file. This is a comment read by emacs to discover what mode to use.

Auto-complete mode

SPARQL-mode now also supports auto-complete-mode. Just add

(add-to-list 'ac-dictionary-files "/path/to/sparql-mode-dir/sparql-mode")
(add-hook 'sparql-mode-hook 'auto-complete-mode)

Executing SPARQL Queries from within Emacs

From a buffer that is in sparql-mode, execute . You will be prompted for a SPARQL HTTP endpoint in the minibuffer, which defaults to . Once set, it will be used for all subsequent queries in that buffer. Results will be displayed in another buffer in CSV format.

Org-babel support

It is also possible to use with org-mode and executing queries with org-babel. You can do that by adding the following snippet or adding to languages org-babel can load:

 '((sparql . t)))

You can then execute the query by pressing on the source-block header.


#+BEGIN_SRC sparql :url :format text/csv
    [] a ?Concept
  } LIMIT 5

: "Concept"
: ""
: ""
: ""
: ""
: ""

Notice that the server request is done synchronously and will therefore lock the editor if the request takes a long time.

Bugs and Enhancements

If you have a problem or would like to see it get better in a specific way, feel free to drop an issue in the issue tracker. Enjoy!