emacs 2026-08-28

Made a tiny helper for sniffing out em-dashes, after finding myself squinting and calling describe-char one too many times :P

(defun +theming/widen-em-dash (limit)
  "Render extended em-dashes in a monospaced font via box drawing glyphs.
Preserves alignment, only encroaching into surrounding whitespace if present.
Font-lock-keyword, searches up to LIMIT."
  (when (re-search-forward " ?\\(—\\) ?" limit t)
    (let ((b0 (match-beginning 0)) (e0 (match-end 0))
          (b (match-beginning 1)) (e (match-end 1)))
      ;; Renders as "╶─╴" (if fully padded), alt: "╺━╸" (BOX DRAWINGS HEAVY)
      (compose-region b e ?─) ; the dash (U+2500)
      (when (< b0 b) (compose-region b0 b ?╶)) ; left extension (U+2576)
      (when (< e e0) (compose-region e e0 ?╴))) ; right extension (U+2574)
    t))

(defface +theming/confusable
  '((t :inherit error :weight ultrabold))
  "Face for highlighting confusable characters.")

(add-hook 'prog-mode-hook
          (defun +theming/highlight-em-dashes ()
            (font-lock-add-keywords nil '((+theming/widen-em-dash 0 '+theming/confusable prepend)))))

There's a way to do it with raw buffer-display-tables as well, no regex involved - but I wanted them to display as actual wide dashes, this seemed to be the simplest way of doing so

yep, minimal impl is:

(let ((table (make-display-table)))
  (aset table ?— (vector (make-glyph-code ?— 'highlight)))
  (setq-local buffer-display-table table))
or if you want it globally
(aset standard-display-table ?— (vector (make-glyph-code ?— 'highlight)))

👍 2