emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/eat 6a94082eff 3/8: Use hash table to convert from charset


From: ELPA Syncer
Subject: [nongnu] elpa/eat 6a94082eff 3/8: Use hash table to convert from charset
Date: Mon, 28 Nov 2022 11:58:51 -0500 (EST)

branch: elpa/eat
commit 6a94082effd5d501bf6e3608f04552abc7a9e844
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>

    Use hash table to convert from charset
    
    * eat.el (eat--t-dec-line-drawing-chars): New constant
    containing the hash table.
    * eat.el (eat--t-write): Use hash-table instead alist while
    converting from DEC Line Drawing charset.
---
 eat.el | 86 ++++++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 49 insertions(+), 37 deletions(-)

diff --git a/eat.el b/eat.el
index 476a33acbb..e07081b1b9 100644
--- a/eat.el
+++ b/eat.el
@@ -2362,6 +2362,53 @@ character or its the internal invisible spaces."
         (insert (propertize " " 'face face))
         (backward-char)))))
 
+(defconst eat--t-dec-line-drawing-chars
+  (eval-and-compile
+    (let ((alist '((?+ . ?→)
+                   (?, . ?←)
+                   (?- . ?↑)
+                   (?. . ?↓)
+                   (?0 . ?█)
+                   (?\` . ?�)
+                   (?a . ?▒)
+                   (?b . ?␉)
+                   (?c . ?␌)
+                   (?d . ?␍)
+                   (?e . ?␊)
+                   (?f . ?°)
+                   (?g . ?±)
+                   (?h . ?░)
+                   (?i . ?#)
+                   (?j . ?┘)
+                   (?k . ?┐)
+                   (?l . ?┌)
+                   (?m . ?└)
+                   (?n . ?┼)
+                   (?o . ?⎺)
+                   (?p . ?⎻)
+                   (?q . ?─)
+                   (?r . ?⎼)
+                   (?s . ?⎽)
+                   (?t . ?├)
+                   (?u . ?┤)
+                   (?v . ?┴)
+                   (?w . ?┬)
+                   (?x . ?│)
+                   (?y . ?≤)
+                   (?z . ?≥)
+                   (?{ . ?π)
+                   (?| . ?≠)
+                   (?} . ?£)
+                   (?~ . ?•)))
+          (table (make-hash-table :purecopy t)))
+      (dolist (pair alist)
+        (puthash (car pair) (cdr pair) table))
+      table))
+  "Hash table for DEC Line Drawing charset.
+
+The key is the output character from client, and value of the
+character to actually show.")
+
 (defun eat--t-write (str)
   "Write STR on display."
   (let ((face (eat--t-face-face (eat--t-term-face eat--t-term)))
@@ -2387,43 +2434,8 @@ character or its the internal invisible spaces."
       ;; `us-ascii'.
       ('dec-line-drawing
        (dotimes (i (length str))
-         (let ((replacement (alist-get (aref str i)
-                                       '((?+ . ?→)
-                                         (?, . ?←)
-                                         (?- . ?↑)
-                                         (?. . ?↓)
-                                         (?0 . ?█)
-                                         (?\` . ?�)
-                                         (?a . ?▒)
-                                         (?b . ?␉)
-                                         (?c . ?␌)
-                                         (?d . ?␍)
-                                         (?e . ?␊)
-                                         (?f . ?°)
-                                         (?g . ?±)
-                                         (?h . ?░)
-                                         (?i . ?#)
-                                         (?j . ?┘)
-                                         (?k . ?┐)
-                                         (?l . ?┌)
-                                         (?m . ?└)
-                                         (?n . ?┼)
-                                         (?o . ?⎺)
-                                         (?p . ?⎻)
-                                         (?q . ?─)
-                                         (?r . ?⎼)
-                                         (?s . ?⎽)
-                                         (?t . ?├)
-                                         (?u . ?┤)
-                                         (?v . ?┴)
-                                         (?w . ?┬)
-                                         (?x . ?│)
-                                         (?y . ?≤)
-                                         (?z . ?≥)
-                                         (?{ . ?π)
-                                         (?| . ?≠)
-                                         (?} . ?£)
-                                         (?~ . ?•)))))
+         (let ((replacement
+                (gethash (aref str i) eat--t-dec-line-drawing-chars)))
            (when replacement
              (aset str i replacement))))))
     ;; Find all the multi-column wide characters in STR, using a



reply via email to

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