emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b35a93a061: New command to facilitate text-mode display of unsupp


From: Eli Zaretskii
Subject: master b35a93a061: New command to facilitate text-mode display of unsupported chars
Date: Sun, 4 Sep 2022 02:04:48 -0400 (EDT)

branch: master
commit b35a93a0619400e93fd76d7de3d837f990802274
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    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.
---
 etc/NEWS           |  9 +++++++++
 lisp/disp-table.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index cc4714e71c..edd4b01eab 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 422728c61c..1b14808d78 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]