]> git.eshelyaron.com Git - emacs.git/commitdiff
New command to facilitate text-mode display of unsupported chars
authorEli Zaretskii <eliz@gnu.org>
Sun, 4 Sep 2022 06:03:30 +0000 (09:03 +0300)
committerEli Zaretskii <eliz@gnu.org>
Sun, 4 Sep 2022 06:03:30 +0000 (09:03 +0300)
* lisp/disp-table.el (standard-display-by-replacement-char): New
command.

* etc/NEWS: Announce it.

etc/NEWS
lisp/disp-table.el

index cc4714e71ce63b9a096c3577ae9ebef42827e014..edd4b01eab507aa5aa9b4499ec0a2857c292a880 100644 (file)
--- 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
 
 +++
index 422728c61c5cff0d92468b4f79148c8e8105c992..1b14808d788fe5a02018d2eb59b1170022d7d565 100644 (file)
@@ -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