From: Eli Zaretskii Date: Sun, 4 Sep 2022 06:03:30 +0000 (+0300) Subject: New command to facilitate text-mode display of unsupported chars X-Git-Tag: emacs-29.0.90~1856^2~744 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b35a93a0619400e93fd76d7de3d837f990802274;p=emacs.git 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. --- 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