Add new bidi-string-strip-control-characters function
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 20 Jan 2022 06:44:49 +0000 (07:44 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 20 Jan 2022 06:44:49 +0000 (07:44 +0100)
* lisp/international/characters.el
(bidi-string-strip-control-characters): New function.

etc/NEWS
lisp/international/characters.el

index 47dbfba9c05d2039fbea747323e65bca23d4937c..ac3b1dccf9c6642383eaf0d7f33d60d82c5d7193 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -960,6 +960,10 @@ The input must be encoded text.
 \f
 * Lisp Changes in Emacs 29.1
 
+** New function 'bidi-string-strip-control-characters'.
+This utility function is meant for displaying strings when it's
+essential that there's no bidirectional context.
+
 ---
 ** The Gnus range functions have been moved to a new library, range.el.
 All the old names have been made obsolete.
index ce23e995c116903dd6456337b764e361fb2c3900..63ac455ea6a32e35af54a6810ef26b021f81f807 100644 (file)
@@ -1541,6 +1541,12 @@ Setup `char-width-table' appropriate for non-CJK language environment."
     #x2069)                          ; ?\N{pop directional isolate}
   "List of bidirectional control characters.")
 
+(defun bidi-string-strip-control-characters (string)
+  "Strip bidi control characters from STRING and return the result."
+  (apply #'string (seq-filter (lambda (char)
+                                (not (memq char bidi-control-characters)))
+                              string)))
+
 (defun update-glyphless-char-display (&optional variable value)
   "Make the setting of `glyphless-char-display-control' take effect.
 This function updates the char-table `glyphless-char-display',