HDFql + Emacs + Org => Winning Combo

Add this to your init.el:

;; We assume that HDFqlCLI is in the path and that libHDFql.so is in
;; the LD_LIBRARY_PATH.

(defun org-babel-execute:hdfql (body params)
  "Execute a block of HDFql code with org-babel."
  (message "executing HDFql source code block")
  (org-babel-eval
   (format "HDFqlCLI --no-status --execute=\"%s\"" body) ""))

(push '("hdfql" . sql) org-src-lang-modes)

(add-to-list 'org-structure-template-alist '("hq" . "src hdfql"))

and enjoy this:

Wishlist:

  1. Support for sessions (:session header argument)
  2. Fancier syntax highlighting
  3. VSCode extension
  4. Jupyter kernel

Dear Santa; it’s a long story…

G.

1 Like

Great to see this integration between HDFql and Emacs happening - thanks @gheber! :slight_smile:

@contact Do you have an (E)BNF grammar of HDFql somewhere? The language description in section 6 of your reference manual is pretty thorough, but is there a standalone grammar somewhere?

G.

Sure - we just compiled an HDFql grammar based on section 6 from HDFql reference manual which can be found here (12.9 KB).

Hope it helps!

1 Like

First experiment w/ font locking (Emacs-speak for syntax highlighting):

(defvar hdf5-keywords-re
  (concat
   "\\b"
   (regexp-opt
    (list
     "attribute"
     "chunked" "compact"
     "dataset" "dense" "directory" "dimension"
     ...
     "unlimited" "userblock size"
     ))
   "\\b"))

...

(defun hdfql-font-lock-add-keywords ()
  "Augment the sql mode font-lock keywords for HDFql"
  (if (fboundp 'font-lock-add-keywords)
      (progn
	    (font-lock-add-keywords
	     'sql-mode `((,hdf5-keywords-re . font-lock-function-name-face)))
	    (font-lock-add-keywords
	     'sql-mode `((,hdf5-type-keywords-re . font-lock-type-face)))
	    (font-lock-add-keywords
	     'sql-mode `((,hdfql-keywords-re . font-lock-keyword-face)))
	)))

(add-hook 'sql-mode-hook
          '(lambda ()
 	         (hdfql-font-lock-add-keywords)
             (setq font-lock-keywords-case-fold-search t)
 	         (font-lock-mode t)))

(setq major-mode 'hdfql-mode)
(setq mode-name "HDFql")

(defun hdfql-mode ()
  (interactive)
  (sql-mode))

(provide 'hdfql)

Seems to do the trick:

G.

1 Like

Another slight simplification. Just add this to .emacs or .emacs.d/init.el

;; HDFql support
(autoload 'hdfql-mode "hdfql" "Interact with HDF5 files via HDFql" t)

and put the attached hdfql.el into your load path.

Enjoy, G.

hdfql.el (2.2 KB)

1 Like

Thanks for sharing this @gheber! Would it make sense to create a Git repository where the file could be stored/versioned? This would enable other people to contribute to its maintenance, including ourselves.

Yes! Check this out: https://github.com/HDFGroup/emacs

G.

1 Like

That’s great - thanks for sharing this! We will contribute to its maintenance whenever we add/change/remove keywords in HDFql.