summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2022-09-04 09:03:30 +0300
committerEli Zaretskii <eliz@gnu.org>2022-09-04 09:03:30 +0300
commitb35a93a0619400e93fd76d7de3d837f990802274 (patch)
tree976d48083e716a68d4fe9824e0cc66924b470841
parent1d9e4900a336b6fa2047404ff25ec31cf8ec613f (diff)
downloademacs-b35a93a0619400e93fd76d7de3d837f990802274.tar.gz
New command to facilitate text-mode display of unsupported chars
* lisp/disp-table.el (standard-display-by-replacement-char): New command. * etc/NEWS: Announce it.
-rw-r--r--etc/NEWS9
-rw-r--r--lisp/disp-table.el59
2 files changed, 68 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index cc4714e71ce..edd4b01eab5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -749,6 +749,15 @@ saved to the X primary selection, following the
'select-active-regions' variable. This support is enabled when
'tty-select-active-regions' is non-nil.
+---
+*** New command to set up display of unsupported characters.
+The new command 'standard-display-by-replacement-char' produces Lisp
+code that sets up the 'standard-display-table' to use a replacement
+character for display of characters that the text-mode terminal
+doesn't support. It is most useful with the Linux console and similar
+terminals, where Emacs has a reliable way of determining which
+characters have glyphs in the font loaded into the terminal's memory.
+
** ERT
+++
diff --git a/lisp/disp-table.el b/lisp/disp-table.el
index 422728c61c5..1b14808d788 100644
--- a/lisp/disp-table.el
+++ b/lisp/disp-table.el
@@ -296,6 +296,65 @@ in `.emacs'."
(if (coding-system-p c) c 'latin-1))))
(standard-display-european-internal)))
+
+;;;###autoload
+(defun standard-display-by-replacement-char (&optional repl from to)
+ "Produce code to display characters between FROM and TO using REPL.
+This function produces a buffer with code to set up `standard-display-table'
+such that characters that cannot be displayed by the terminal, and
+don't already have their display set up in `standard-display-table', will
+be represented by a replacement character. You can evaluate the produced
+code to use the setup for the current Emacs session, or copy the code
+into your init file, to make Emacs use it for subsequent sessions.
+
+FROM and TO define the range of characters for which to produce the
+setup code for `standard-display-table'. If they are omitted, they
+default to #x100 and #x10FFFF respectively, covering the entire
+non-ASCII range of Unicode characters.
+REPL is the replacement character to use. If it's omitted, it defaults
+to #xFFFD, the Unicode replacement character, usually displayed as a
+black diamond with a question mark inside.
+The produced code sets up `standard-display-table' to show REPL with
+the `homoglyph' face, making the replacements stand out on display.
+
+This command is most useful with text-mode terminals, such as the
+Linux console, for which Emacs has a reliable way of determining
+which characters can be displayed and which cannot."
+ (interactive)
+ (or repl
+ (setq repl #xfffd))
+ (or (and from to (<= from to))
+ (setq from #x100
+ to (max-char 'unicode)))
+ (let ((buf (get-buffer-create "*Display replacements*"))
+ (ch from)
+ (tbl standard-display-table)
+ first)
+ (with-current-buffer buf
+ (erase-buffer)
+ (insert "(let ((tbl standard-display-table))\n")
+ (while (<= ch to)
+ (cond
+ ((or (char-displayable-p ch)
+ (aref tbl ch))
+ (setq ch (1+ ch)))
+ (t
+ (setq first ch)
+ (while (and (<= ch to)
+ (not (or (char-displayable-p ch)
+ (aref tbl ch))))
+ (setq ch (1+ ch)))
+ (insert
+ " (set-char-table-range tbl '("
+ (format "#x%x" first)
+ " . "
+ (format "#x%x" (1- ch))
+ ")\n\ (vconcat (list (make-glyph-code "
+ (format "#x%x" repl) " 'homoglyph))))\n"))))
+ (insert ")\n"))
+ (pop-to-buffer buf)))
+
+
(provide 'disp-table)
;;; disp-table.el ends here