]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve 'C-u C-x =' for ligatures of ASCII characters
authorEli Zaretskii <eliz@gnu.org>
Sat, 22 Mar 2025 10:39:46 +0000 (12:39 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 23 Mar 2025 19:24:28 +0000 (20:24 +0100)
* lisp/composite.el (composition-find-pos-glyph): New function.
* lisp/descr-text.el (describe-char): Use it to get the font glyph
code of "trivial" compositions.
(describe-char-display): Accept an additional optional argument
and use it as the font glyph code for the character.

(cherry picked from commit 098fe4b73b62033b8930760e7fff0a23c271a1bb)

lisp/composite.el
lisp/descr-text.el

index d0e5495e71ec64b3d08f6107b01413e0cb70ade6..4f3a958cc48bea423769860c5106940cc7edf152 100644 (file)
@@ -493,6 +493,24 @@ by `find-composition'."
         (setq idx (1+ idx)))))
     (or found endpos)))
 
+(defun composition-find-pos-glyph (composition pos)
+  "Find in COMPOSITION a glyph that corresponds to character at position POS.
+COMPOSITION is as returned by `find-composition'."
+  (let* ((from-pos (car composition))
+         (to-pos (nth 1 composition))
+         (gstring (nth 2 composition))
+         (nglyphs (lgstring-glyph-len gstring))
+        (idx 0)
+        glyph found)
+    (if (and (>= pos from-pos) (< pos to-pos))
+        (while (and (not found) (< idx nglyphs))
+          (setq glyph (lgstring-glyph gstring idx))
+          (if (and (>= pos (+ from-pos (lglyph-from glyph)))
+                   (<= pos (+ from-pos (lglyph-to glyph))))
+              (setq found (lglyph-code glyph)))
+          (setq idx (1+ idx))))
+    found))
+
 (defun compose-glyph-string (gstring from to)
   (let ((glyph (lgstring-glyph gstring from))
        from-pos to-pos)
index ad55feb4ea86e109eed87f097ad0db0bd03a5370..38fb044e28eed578a49271f32c90708a925842d1 100644 (file)
@@ -318,13 +318,13 @@ This function is semi-obsolete.  Use `get-char-code-property'."
 ;;   GLYPH-CODE is a hexadigit string representing the glyph-ID.
 ;; Otherwise, return a string describing the terminal codes for the
 ;; character.
-(defun describe-char-display (pos char)
+(defun describe-char-display (pos char &optional glyph-code)
   (if (display-graphic-p (selected-frame))
       (let ((char-font-info (internal-char-font pos char)))
        (if char-font-info
            (let ((type (font-get (car char-font-info) :type))
                  (name (font-xlfd-name (car char-font-info)))
-                 (code (cdr char-font-info)))
+                 (code (or glyph-code (cdr char-font-info))))
               (if (integerp code)
                   (format "%s:%s (#x%02X)" type name code)
                 (format "%s:%s (#x%04X%04X)"
@@ -420,7 +420,7 @@ The character information includes:
                     (describe-text-properties pos tmp-buf)
                     (with-current-buffer tmp-buf (buffer-string)))
                 (kill-buffer tmp-buf))))
-           item-list max-width code)
+           item-list max-width code glyph-code trivial-p)
 
       (if multibyte-p
           (or (setq code (encode-char char charset))
@@ -489,7 +489,8 @@ The character information includes:
                       (if (and (= to (1+ from))
                                (= i (1- j))
                                (setq glyph (lgstring-glyph components i))
-                               (= char (lglyph-char glyph)))
+                               (= char (lglyph-char glyph))
+                               (setq trivial-p t))
                           ;; The composition is trivial.
                           (throw 'tag nil))
                       (nconc composition (list i (1- j))))
@@ -527,7 +528,13 @@ The character information includes:
                         (format "composed to form \"%s\" (see below)"
                                 (setq composition-string
                                       (buffer-substring from to))))))
-            (setq composition nil)))
+            ;; For "trivial" compositions, such as ligatures of ASCII
+            ;; characters, at least show the correct font glyph number.
+            (setq glyph-code (if (and composition
+                                      trivial-p
+                                      (display-graphic-p (selected-frame)))
+                                 (composition-find-pos-glyph composition pos))
+                  composition nil)))
 
       (setq item-list
             `(("position"
@@ -664,7 +671,7 @@ The character information includes:
                  (composition
                   (cadr composition))
                  (t
-                  (let ((display (describe-char-display pos char)))
+                  (let ((display (describe-char-display pos char glyph-code)))
                     (if (display-graphic-p (selected-frame))
                         (if display
                             (concat "by this font (glyph code):\n    " display)