Omitting overlayed glyphs in nxml-mode
A small tweak to XML editing in Emacs.
I really like nxml-mode
I understand that some folks still prefer psgml-mode for it’s much
larger set of key bindings to manipulate elements. I have occasionally
investigated porting those, but I’ve never manged to get very far.
If someone with Emacs experience wants to do the XML community a solid,
that’d be nice. for editing XML (in Emacs, of course), and I have done
for a while.
I’m happy using RELAX NG grammars for my XML vocabularies and, for
those still using DTDs, I’ll observe that it’s straightforward and
mechanical to convert DTDs to RELAX NG. (As an aid to editing, I mean, even if
you prefer to maintain the schemas as DTDs.)
One nice feature of nxml-mode
is that it puts in overlays for
numeric character references. If you stumble across a ☺
in a
document, nxml-mode
will helpfully put a “☺” after it as an overlay.
One really annoying feature of nxml-mode
is that it does this for
. They aren’t exactly common, but they do turn up in
<xsl:text>
elements with enough regularity that I find the
overlayed, literal newline characters significantly distracting.
Herewith, a fix:
(defcustom nxml-char-ref-display-glyph-omit '(10)
"A list of Unicode code points. The overlay character displayed
after numeric character references will be omitted for these values."
:group 'nxml
:type '(repeat integer))
(defun nxml-char-ref-display-extra (start end n)
(when nxml-char-ref-extra-display
(let ((name (or (get-char-code-property n 'name)
(get-char-code-property n 'old-name)))
(glyph-string (and nxml-char-ref-display-glyph-flag
(not (member n nxml-char-ref-display-glyph-omit))
(char-displayable-p n)
(string n)))
ov)
(when (or name glyph-string)
(setq ov (make-overlay start end nil t))
(overlay-put ov 'category 'nxml-char-ref)
(when name
(overlay-put ov 'help-echo name))
(when glyph-string
(overlay-put ov
'after-string
(propertize glyph-string 'face 'nxml-glyph)))))))
I haven’t (yet) investigated getting this change pushed upstream, I’m just sharing a little itch scratching at the moment.