💾 Archived View for warp.geminispace.club › ~freezr › gemlog › 2023-03-17-emacs-for-speedata.gmi captured on 2024-08-24 at 23:44:07. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-06-14)

-=-=-=-=-=-=-

Setting up GNU Emacs for Speedata Publisher

Updated at 2023-06-06

Introduction

If you follow my "Pebcak's diary" you already knew that I am trying to learn these high-level TeX implementations, such as ConTeXt and Speedata Publisher.

The latter is especially challenging since works exclusively with "XML Schema" and I found very few native opensource editors able to work with this XML variation.

Related links:

My Pebcak's diary

Speedata Publisher Website

W3C — XML Schema

Living in freedom

Speedata is pretty Linux and opensource friendly but, unfortunately, it provides exclusively documentation for my least favorite editors; however it recommends Emacs as a potential alternative.

Speedata manual — How to write the layout: XML Editor

I surely prefer using GNU Emacs rather than the applications suggested, however Emacs has its learning curve and some caveats that must be addressed if you want use it in combination with XML Schema.

Tech Savvy Friends Matter

My dear friend OP — yes, always him — author of GMID (my capsule's server) and Telescope (my favorite TUI client) is also a BIG fan of Emacs.

OP English Capsule

He encouraged myself to use Emacs, and to facilitate this adoption he prepared for me a special setup to make my life easier!

Setting up GNU Emacs for Humans

The set up is straightforward and doesn't require any special expertise, a simple plain text file — called "init.el" — must be create inside your ~/.emacs.d/ directory (if it doesn't exist just make it) with the following content:

IMPORTANT: Emacs will create auto-comments in your custom edit, do not worry if eventually it will look a little bit more verbose than my code block.

;; Actives the following standard control-c/v/x/z
(cua-mode +1)

;; Automatic closes brackets and quotation marks
(electric-pair-mode +1)

;; Automatic close XML tags
(setq nxml-slash-auto-complete-flag t)

;; Makes the font size bigger
(let ((font "Monospace 14"))
    (set-frame-font font nil t)
    (add-to-list 'default-frame-alist `(font . ,font)))

;; Enables control-s to save
(define-key global-map (kbd "C-s") #'save-buffer)

;; Enables control-f to search
(define-key global-map (kbd "C-f") #'isearch-forward)
(define-key isearch-mode-map (kbd "C-f") #'isearch-repeat-forward)

;; Enables control-q to close
(define-key global-map (kbd "C-q") #'save-buffers-kill-terminal)

;; XML Schema
(unless (package-installed-p 'rnc-mode) 
    (package-install 'rnc-mode))

;; CORFU autocompletion

(unless (package-installed-p 'corfu)
    (package-install 'corfu))
(global-corfu-mode +1)
(setq tab-always-indent 'complete
    corfu-auto t
    corfu-quit-no-match 'separator)

Brief explanation

For the ones that didn't understand anything — like myself — these settings do the following:

Relax NG caveat

GNU Emacs supports "XML Schema" through a different dialect called "Relax NG".

https://relaxng.org/

The Schema provided by Speedata has the extension RNG while the "Relax NG" supported by Emacs supports instead Schema that uses the RNC extension. This tiny difference had driven me crazy until OP found the pebcak and thus the solution.

The solution was using a (java) package called "Trang" — available on Debian/Devuan repository, the can convert .RNG files into .RNC files. The utilization is pretty intuitive:

trang layoutschema-en.rng layoutschema-en.rnc

Based on your personal preferences you can convert it by yourself or download the one I converted by myself.

Download layoutschema-en.rnc

⚠️ Other limitations

I don't know the reason but I couldn't find a method to let Emacs remembering to use the associated schema, this means that everytime you open the `layout.xml` file you must do this procedure again and again. It is strongly recommended to have the `layoutschema-en.rnc` inside your working folder.

Using Relax NG on Emacs

On Emacs, "XML Schema/Relax NG" is called "nXML mode":

Emacs Manual: nXML mode TOC

Emacs Manual: 6 Locating a schema

Emacs Manual: 6.1 Commands for locating a schema

💡 Gnu Emacs goes in nXML mode automatically
⚠️ I re-edit this sequence of commands since the one I made before was unreliable
⚠️ This method is still unreliable, the procedure must be done everytime you reopen any Speedata XML file.

Basic commands:

To check a schema assigned use this commands:

C-c C-s C-w

To assign the Schema to an XML file the procedure is the following one:

C-c C-s C-f

To verify if a XML file is using the right Schema you can reuse this combination:

C-c C-s C-w

To make this association persistent as for the manual:

The command C-c C-s C-l adds a rule to a schema locating file that persistently associates the document with the schema that is currently being used.
C-c C-s C-l

To recall a schema directly from the file [ ⚠️ NOT RELIABLE, DON'T USE IT ⚠️ ]

C-c C-s C-a

FAQ: Your instructions do not work?

IMPORTANT: I tested this method on Debian/Devuan only.
lsb_release -a
No LSB modules are available.
Distributor ID:	Devuan
Description:	Devuan GNU/Linux 5 (daedalus/ceres)
Release:	5
Codename:	daedalus ceres

emacs --version 
GNU Emacs 28.2

You may try installing this package:

elpa-use-package

Wrapping this up

Unfortunately the first iteration of this guide didn't really work out. Schema was frequently forgotten, Emacs showed the xml was correct while was actually incorrect when matched with the right schema. Without the right schema it is almost impossible write correct XML. I was almost to the point to give up with Emacs (which I don't really like) to go with the Empire of Evil. As a matter of fact, looks like the first time I missed to make the association persintent. I'll test this method for a while, if you can read this gemlog it means it eventually has worked! 🤞

⚠️ Sadly the association must be made every time you open or reopen the layout.xml file, otherwise it will forget the association. ⚠️
🕒 [OLD VERSION] Thanks to OP, automagically tags are suggested and closed, key combinations work as expected! This spares to me a lot of headache and the shame to use nefarious editors, with the additional value that my workflow can be still the same on any OS that support Emacs.
I am very happy! 😬

For comments or suggestion write me at:

freezr AT disroot DOT org

↩ go back