[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 098fe4b73b6: Improve 'C-u C-x =' for ligatures of ASCII character
From: |
Eli Zaretskii |
Subject: |
master 098fe4b73b6: Improve 'C-u C-x =' for ligatures of ASCII characters |
Date: |
Sat, 22 Mar 2025 06:42:50 -0400 (EDT) |
branch: master
commit 098fe4b73b62033b8930760e7fff0a23c271a1bb
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
Improve 'C-u C-x =' for ligatures of ASCII characters
* 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.
---
lisp/composite.el | 18 ++++++++++++++++++
lisp/descr-text.el | 19 +++++++++++++------
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/lisp/composite.el b/lisp/composite.el
index 89136ba5f39..2301dede2bd 100644
--- a/lisp/composite.el
+++ b/lisp/composite.el
@@ -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)
diff --git a/lisp/descr-text.el b/lisp/descr-text.el
index 3fb21309f7b..2cdb47acf40 100644
--- a/lisp/descr-text.el
+++ b/lisp/descr-text.el
@@ -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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 098fe4b73b6: Improve 'C-u C-x =' for ligatures of ASCII characters,
Eli Zaretskii <=