Omitting overlayed glyphs in nxml-mode

Volume 3, Issue 8; 12 Mar 2019

A small tweak to XML editing in Emacs.

I really like nxml-modeI 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 &#10;. 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)))
    (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
                     (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.

Please provide your name and email address. Your email address will not be displayed and I won’t spam you, I promise. Your name and a link to your web address, if you provide one, will be displayed.

Your name:

Your email:


Do you comprehend the words on this page? (Please demonstrate that you aren't a mindless, screen-scraping robot.)

What is eight times three?  (e.g. six plus two is 8)

Enter your comment in the box below. You may style your comment with the CommonMark flavor of Markdown.

All comments are moderated. I don’t promise to preserve all of your formatting and I reserve the right to remove comments for any reason.